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

import (
	"context"
	"time"

	"github.com/Gleipnir-Technology/bob"
	"github.com/Gleipnir-Technology/bob/dialect/psql"
	"github.com/Gleipnir-Technology/bob/expr"
	enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
	"github.com/aarondl/opt/null"
)

// PublicreportReportLocation is an object representing the database table.
type PublicreportReportLocation struct {
	ID        null.Val[int64]                              `db:"id" `
	TableName null.Val[string]                             `db:"table_name" `
	Address   null.Val[string]                             `db:"address" `
	Created   null.Val[time.Time]                          `db:"created" `
	Location  null.Val[string]                             `db:"location" `
	PublicID  null.Val[string]                             `db:"public_id" `
	Status    null.Val[enums.PublicreportReportstatustype] `db:"status" `
}

// PublicreportReportLocationSlice is an alias for a slice of pointers to PublicreportReportLocation.
// This should almost always be used instead of []*PublicreportReportLocation.
type PublicreportReportLocationSlice []*PublicreportReportLocation

// PublicreportReportLocations contains methods to work with the report_location view
var PublicreportReportLocations = psql.NewViewx[*PublicreportReportLocation, PublicreportReportLocationSlice]("publicreport", "report_location", buildPublicreportReportLocationColumns("publicreport.report_location"))

// PublicreportReportLocationsQuery is a query on the report_location view
type PublicreportReportLocationsQuery = *psql.ViewQuery[*PublicreportReportLocation, PublicreportReportLocationSlice]

func buildPublicreportReportLocationColumns(alias string) publicreportReportLocationColumns {
	return publicreportReportLocationColumns{
		ColumnsExpr: expr.NewColumnsExpr(
			"id", "table_name", "address", "created", "location", "public_id", "status",
		).WithParent("publicreport.report_location"),
		tableAlias: alias,
		ID:         psql.Quote(alias, "id"),
		TableName:  psql.Quote(alias, "table_name"),
		Address:    psql.Quote(alias, "address"),
		Created:    psql.Quote(alias, "created"),
		Location:   psql.Quote(alias, "location"),
		PublicID:   psql.Quote(alias, "public_id"),
		Status:     psql.Quote(alias, "status"),
	}
}

type publicreportReportLocationColumns struct {
	expr.ColumnsExpr
	tableAlias string
	ID         psql.Expression
	TableName  psql.Expression
	Address    psql.Expression
	Created    psql.Expression
	Location   psql.Expression
	PublicID   psql.Expression
	Status     psql.Expression
}

func (c publicreportReportLocationColumns) Alias() string {
	return c.tableAlias
}

func (publicreportReportLocationColumns) AliasedAs(alias string) publicreportReportLocationColumns {
	return buildPublicreportReportLocationColumns(alias)
}

// AfterQueryHook is called after PublicreportReportLocation is retrieved from the database
func (o *PublicreportReportLocation) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
	var err error

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = PublicreportReportLocations.AfterSelectHooks.RunHooks(ctx, exec, PublicreportReportLocationSlice{o})
	}

	return err
}

// AfterQueryHook is called after PublicreportReportLocationSlice is retrieved from the database
func (o PublicreportReportLocationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
	var err error

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = PublicreportReportLocations.AfterSelectHooks.RunHooks(ctx, exec, o)
	}

	return err
}

type publicreportReportLocationWhere[Q psql.Filterable] struct {
	ID        psql.WhereNullMod[Q, int64]
	TableName psql.WhereNullMod[Q, string]
	Address   psql.WhereNullMod[Q, string]
	Created   psql.WhereNullMod[Q, time.Time]
	Location  psql.WhereNullMod[Q, string]
	PublicID  psql.WhereNullMod[Q, string]
	Status    psql.WhereNullMod[Q, enums.PublicreportReportstatustype]
}

func (publicreportReportLocationWhere[Q]) AliasedAs(alias string) publicreportReportLocationWhere[Q] {
	return buildPublicreportReportLocationWhere[Q](buildPublicreportReportLocationColumns(alias))
}

func buildPublicreportReportLocationWhere[Q psql.Filterable](cols publicreportReportLocationColumns) publicreportReportLocationWhere[Q] {
	return publicreportReportLocationWhere[Q]{
		ID:        psql.WhereNull[Q, int64](cols.ID),
		TableName: psql.WhereNull[Q, string](cols.TableName),
		Address:   psql.WhereNull[Q, string](cols.Address),
		Created:   psql.WhereNull[Q, time.Time](cols.Created),
		Location:  psql.WhereNull[Q, string](cols.Location),
		PublicID:  psql.WhereNull[Q, string](cols.PublicID),
		Status:    psql.WhereNull[Q, enums.PublicreportReportstatustype](cols.Status),
	}
}
