// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: batch.go

package db

import (
	"context"
	"errors"

	"github.com/jackc/pgx/v5"
)

var (
	ErrBatchAlreadyClosed = errors.New("batch already closed")
)

const createTransactionAssets = `-- name: CreateTransactionAssets :batchexec
INSERT INTO transaction_asset (transaction_id, asset_id, quantity) VALUES ($1, $2, $3)
`

type CreateTransactionAssetsBatchResults struct {
	br     pgx.BatchResults
	tot    int
	closed bool
}

type CreateTransactionAssetsParams struct {
	TransactionID int64 `json:"transaction_id"`
	AssetID       int64 `json:"asset_id"`
	Quantity      int64 `json:"quantity"`
}

func (q *Queries) CreateTransactionAssets(ctx context.Context, arg []CreateTransactionAssetsParams) *CreateTransactionAssetsBatchResults {
	batch := &pgx.Batch{}
	for _, a := range arg {
		vals := []interface{}{
			a.TransactionID,
			a.AssetID,
			a.Quantity,
		}
		batch.Queue(createTransactionAssets, vals...)
	}
	br := q.db.SendBatch(ctx, batch)
	return &CreateTransactionAssetsBatchResults{br, len(arg), false}
}

func (b *CreateTransactionAssetsBatchResults) Exec(f func(int, error)) {
	defer b.br.Close()
	for t := 0; t < b.tot; t++ {
		if b.closed {
			if f != nil {
				f(t, ErrBatchAlreadyClosed)
			}
			continue
		}
		_, err := b.br.Exec()
		if f != nil {
			f(t, err)
		}
	}
}

func (b *CreateTransactionAssetsBatchResults) Close() error {
	b.closed = true
	return b.br.Close()
}

const createTransferAssets = `-- name: CreateTransferAssets :batchexec
INSERT INTO transfer_asset (transfer_id, asset_id, quantity) VALUES ($1, $2, $3)
`

type CreateTransferAssetsBatchResults struct {
	br     pgx.BatchResults
	tot    int
	closed bool
}

type CreateTransferAssetsParams struct {
	TransferID int64 `json:"transfer_id"`
	AssetID    int64 `json:"asset_id"`
	Quantity   int64 `json:"quantity"`
}

func (q *Queries) CreateTransferAssets(ctx context.Context, arg []CreateTransferAssetsParams) *CreateTransferAssetsBatchResults {
	batch := &pgx.Batch{}
	for _, a := range arg {
		vals := []interface{}{
			a.TransferID,
			a.AssetID,
			a.Quantity,
		}
		batch.Queue(createTransferAssets, vals...)
	}
	br := q.db.SendBatch(ctx, batch)
	return &CreateTransferAssetsBatchResults{br, len(arg), false}
}

func (b *CreateTransferAssetsBatchResults) Exec(f func(int, error)) {
	defer b.br.Close()
	for t := 0; t < b.tot; t++ {
		if b.closed {
			if f != nil {
				f(t, ErrBatchAlreadyClosed)
			}
			continue
		}
		_, err := b.br.Exec()
		if f != nil {
			f(t, err)
		}
	}
}

func (b *CreateTransferAssetsBatchResults) Close() error {
	b.closed = true
	return b.br.Close()
}
