// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package sql

import (
	"context"
	_ "embed"
	"io"
	"iter"
	"time"

	"github.com/Gleipnir-Technology/bob"
	"github.com/Gleipnir-Technology/bob/dialect/psql"
	"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
	"github.com/Gleipnir-Technology/bob/expr"
	"github.com/Gleipnir-Technology/bob/orm"
	"github.com/google/uuid"
	"github.com/stephenafamo/scan"
)

//go:embed trapdata_by_location_id_recent.bob.sql
var formattedQueries_trapdata_by_location_id_recent string

var trapDataByLocationIDRecentSQL = formattedQueries_trapdata_by_location_id_recent[164:463]

type TrapDataByLocationIDRecentQuery = orm.ModQuery[*dialect.SelectQuery, trapDataByLocationIDRecent, TrapDataByLocationIDRecentRow, []TrapDataByLocationIDRecentRow, trapDataByLocationIDRecentTransformer]

func TrapDataByLocationIDRecent(OrganizationID int32, LocID []uuid.UUID) *TrapDataByLocationIDRecentQuery {
	var expressionTypArgs trapDataByLocationIDRecent

	expressionTypArgs.OrganizationID = psql.Arg(OrganizationID)
	expressionTypArgs.LocID = expr.ToArgs(LocID...)

	return &TrapDataByLocationIDRecentQuery{
		Query: orm.Query[trapDataByLocationIDRecent, TrapDataByLocationIDRecentRow, []TrapDataByLocationIDRecentRow, trapDataByLocationIDRecentTransformer]{
			ExecQuery: orm.ExecQuery[trapDataByLocationIDRecent]{
				BaseQuery: bob.BaseQuery[trapDataByLocationIDRecent]{
					Expression: expressionTypArgs,
					Dialect:    dialect.Dialect,
					QueryType:  bob.QueryTypeSelect,
				},
			},
			Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (TrapDataByLocationIDRecentRow, error)) {
				return func(row *scan.Row) (any, error) {
						var t TrapDataByLocationIDRecentRow
						row.ScheduleScanByIndex(0, &t.Enddatetime)
						row.ScheduleScanByIndex(1, &t.Globalid)
						row.ScheduleScanByIndex(2, &t.LocID)
						return &t, nil
					}, func(v any) (TrapDataByLocationIDRecentRow, error) {
						return *(v.(*TrapDataByLocationIDRecentRow)), nil
					}
			},
		},
		Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
			q.AppendSelect(expressionTypArgs.subExpr(7, 36))
			q.SetTable(expressionTypArgs.subExpr(42, 253))
			q.AppendWhere(expressionTypArgs.subExpr(260, 273))
			q.CombinedOrder.AppendOrder(expressionTypArgs.subExpr(283, 299))
		}),
	}
}

type TrapDataByLocationIDRecentRow = struct {
	Enddatetime time.Time `db:"enddatetime"`
	Globalid    uuid.UUID `db:"globalid"`
	LocID       uuid.UUID `db:"loc_id"`
}

type trapDataByLocationIDRecentTransformer = bob.SliceTransformer[TrapDataByLocationIDRecentRow, []TrapDataByLocationIDRecentRow]

type trapDataByLocationIDRecent struct {
	OrganizationID bob.Expression
	LocID          bob.Expression
}

func (o trapDataByLocationIDRecent) args() iter.Seq[orm.ArgWithPosition] {
	return func(yield func(arg orm.ArgWithPosition) bool) {
		if !yield(orm.ArgWithPosition{
			Name:       "organizationID",
			Start:      216,
			Stop:       218,
			Expression: o.OrganizationID,
		}) {
			return
		}

		if !yield(orm.ArgWithPosition{
			Name:       "locID",
			Start:      236,
			Stop:       238,
			Expression: o.LocID,
		}) {
			return
		}
	}
}

func (o trapDataByLocationIDRecent) raw(from, to int) string {
	return trapDataByLocationIDRecentSQL[from:to]
}

func (o trapDataByLocationIDRecent) subExpr(from, to int) bob.Expression {
	return orm.ArgsToExpression(trapDataByLocationIDRecentSQL, from, to, o.args())
}

func (o trapDataByLocationIDRecent) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
	return o.subExpr(0, len(trapDataByLocationIDRecentSQL)).WriteSQL(ctx, w, d, start)
}
