// 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"

	"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/orm"
	"github.com/stephenafamo/scan"
)

//go:embed org_by_oauth_id.bob.sql
var formattedQueries_org_by_oauth_id string

var orgByOauthIdSQL = formattedQueries_org_by_oauth_id[150:495]

type OrgByOauthIdQuery = orm.ModQuery[*dialect.SelectQuery, orgByOauthId, OrgByOauthIdRow, []OrgByOauthIdRow, orgByOauthIdTransformer]

func OrgByOauthId(ID int32) *OrgByOauthIdQuery {
	var expressionTypArgs orgByOauthId

	expressionTypArgs.ID = psql.Arg(ID)

	return &OrgByOauthIdQuery{
		Query: orm.Query[orgByOauthId, OrgByOauthIdRow, []OrgByOauthIdRow, orgByOauthIdTransformer]{
			ExecQuery: orm.ExecQuery[orgByOauthId]{
				BaseQuery: bob.BaseQuery[orgByOauthId]{
					Expression: expressionTypArgs,
					Dialect:    dialect.Dialect,
					QueryType:  bob.QueryTypeSelect,
				},
			},
			Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (OrgByOauthIdRow, error)) {
				return func(row *scan.Row) (any, error) {
						var t OrgByOauthIdRow
						row.ScheduleScanByIndex(0, &t.OrganizationID)
						row.ScheduleScanByIndex(1, &t.ArcgisID)
						row.ScheduleScanByIndex(2, &t.FieldseekerURL)
						return &t, nil
					}, func(v any) (OrgByOauthIdRow, error) {
						return *(v.(*OrgByOauthIdRow)), nil
					}
			},
		},
		Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
			q.AppendSelect(expressionTypArgs.subExpr(7, 78))
			q.SetTable(expressionTypArgs.subExpr(84, 328))
			q.AppendWhere(expressionTypArgs.subExpr(335, 345))
		}),
	}
}

type OrgByOauthIdRow = struct {
	OrganizationID int32  `db:"organization_id"`
	ArcgisID       string `db:"arcgis_id"`
	FieldseekerURL string `db:"fieldseeker_url"`
}

type orgByOauthIdTransformer = bob.SliceTransformer[OrgByOauthIdRow, []OrgByOauthIdRow]

type orgByOauthId struct {
	ID bob.Expression
}

func (o orgByOauthId) args() iter.Seq[orm.ArgWithPosition] {
	return func(yield func(arg orm.ArgWithPosition) bool) {
		if !yield(orm.ArgWithPosition{
			Name:       "id",
			Start:      343,
			Stop:       345,
			Expression: o.ID,
		}) {
			return
		}
	}
}

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

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

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