// 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/orm"
	"github.com/aarondl/opt/null"
	"github.com/google/uuid"
	"github.com/stephenafamo/scan"
)

//go:embed publicreport_image_with_json_by_nuisance_id.bob.sql
var formattedQueries_publicreport_image_with_json_by_nuisance_id string

var publicreportImageWithJSONByNuisanceIDSQL = formattedQueries_publicreport_image_with_json_by_nuisance_id[175:999]

type PublicreportImageWithJSONByNuisanceIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]

func PublicreportImageWithJSONByNuisanceID(NuisanceID int32) *PublicreportImageWithJSONByNuisanceIDQuery {
	var expressionTypArgs publicreportImageWithJSONByNuisanceID

	expressionTypArgs.NuisanceID = psql.Arg(NuisanceID)

	return &PublicreportImageWithJSONByNuisanceIDQuery{
		Query: orm.Query[publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]{
			ExecQuery: orm.ExecQuery[publicreportImageWithJSONByNuisanceID]{
				BaseQuery: bob.BaseQuery[publicreportImageWithJSONByNuisanceID]{
					Expression: expressionTypArgs,
					Dialect:    dialect.Dialect,
					QueryType:  bob.QueryTypeSelect,
				},
			},
			Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportImageWithJSONByNuisanceIDRow, error)) {
				return func(row *scan.Row) (any, error) {
						var t PublicreportImageWithJSONByNuisanceIDRow
						row.ScheduleScanByIndex(0, &t.ID)
						row.ScheduleScanByIndex(1, &t.ContentType)
						row.ScheduleScanByIndex(2, &t.Created)
						row.ScheduleScanByIndex(3, &t.Location)
						row.ScheduleScanByIndex(4, &t.LocationJSON)
						row.ScheduleScanByIndex(5, &t.ResolutionX)
						row.ScheduleScanByIndex(6, &t.ResolutionY)
						row.ScheduleScanByIndex(7, &t.StorageUUID)
						row.ScheduleScanByIndex(8, &t.StorageSize)
						row.ScheduleScanByIndex(9, &t.UploadedFilename)
						return &t, nil
					}, func(v any) (PublicreportImageWithJSONByNuisanceIDRow, error) {
						return *(v.(*PublicreportImageWithJSONByNuisanceIDRow)), nil
					}
			},
		},
		Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
			q.AppendSelect(expressionTypArgs.subExpr(9, 565))
			q.SetTable(expressionTypArgs.subExpr(571, 767))
			q.AppendWhere(expressionTypArgs.subExpr(775, 823))
		}),
	}
}

type PublicreportImageWithJSONByNuisanceIDRow = struct {
	ID               int32            `db:"id"`
	ContentType      string           `db:"content_type"`
	Created          time.Time        `db:"created"`
	Location         null.Val[string] `db:"location"`
	LocationJSON     string           `db:"location_json"`
	ResolutionX      int32            `db:"resolution_x"`
	ResolutionY      int32            `db:"resolution_y"`
	StorageUUID      uuid.UUID        `db:"storage_uuid"`
	StorageSize      int64            `db:"storage_size"`
	UploadedFilename string           `db:"uploaded_filename"`
}

type publicreportImageWithJSONByNuisanceIDTransformer = bob.SliceTransformer[PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow]

type publicreportImageWithJSONByNuisanceID struct {
	NuisanceID bob.Expression
}

func (o publicreportImageWithJSONByNuisanceID) args() iter.Seq[orm.ArgWithPosition] {
	return func(yield func(arg orm.ArgWithPosition) bool) {
		if !yield(orm.ArgWithPosition{
			Name:       "nuisanceID",
			Start:      821,
			Stop:       823,
			Expression: o.NuisanceID,
		}) {
			return
		}
	}
}

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

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

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