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

package sqlcv1

import (
	"context"
	"errors"

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

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

const registerBatch = `-- name: RegisterBatch :batchexec
SELECT id, inserted_at, tenant_id, queue, action_id, step_id, step_readable_id, workflow_id, workflow_version_id, workflow_run_id, schedule_timeout, step_timeout, priority, sticky, desired_worker_id, external_id, display_name, input, retry_count, internal_retry_count, app_retry_count, step_index, additional_metadata, dag_id, dag_inserted_at, parent_task_external_id, parent_task_id, parent_task_inserted_at, child_index, child_key, initial_state, initial_state_reason, concurrency_parent_strategy_ids, concurrency_strategy_ids, concurrency_keys, retry_backoff_factor, retry_max_backoff, is_durable, desired_worker_label, triggering_event_external_id, triggering_event_key FROM v1_task WHERE id = $1
`

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

// DO NOT USE: dummy query to satisfy sqlc and register Batch calls on DBTX
func (q *Queries) RegisterBatch(ctx context.Context, db DBTX, id []int64) *RegisterBatchBatchResults {
	batch := &pgx.Batch{}
	for _, a := range id {
		vals := []interface{}{
			a,
		}
		batch.Queue(registerBatch, vals...)
	}
	br := db.SendBatch(ctx, batch)
	return &RegisterBatchBatchResults{br, len(id), false}
}

func (b *RegisterBatchBatchResults) 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 *RegisterBatchBatchResults) Close() error {
	b.closed = true
	return b.br.Close()
}
