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

package models

import (
	"context"
	"fmt"
	"io"
	"time"

	"github.com/aarondl/opt/null"
	"github.com/aarondl/opt/omit"
	"github.com/aarondl/opt/omitnull"
	"github.com/stephenafamo/bob"
	"github.com/stephenafamo/bob/dialect/mysql"
	"github.com/stephenafamo/bob/dialect/mysql/dialect"
	"github.com/stephenafamo/bob/dialect/mysql/dm"
	"github.com/stephenafamo/bob/dialect/mysql/sm"
	"github.com/stephenafamo/bob/dialect/mysql/um"
	"github.com/stephenafamo/bob/expr"
	"github.com/stephenafamo/bob/mods"
	"github.com/stephenafamo/bob/orm"
)

// LocationsFixitylog is an object representing the database table.
type LocationsFixitylog struct {
	ID               int32            `db:"id,pk,autoincr" `
	Success          null.Val[bool]   `db:"success" `
	ErrorDetails     null.Val[string] `db:"error_details" `
	DatetimeReported time.Time        `db:"datetime_reported" `
	PackageID        string           `db:"package_id" `

	R locationsFixitylogR `db:"-" `
}

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

// LocationsFixitylogs contains methods to work with the locations_fixitylog table
var LocationsFixitylogs = mysql.NewTablex[*LocationsFixitylog, LocationsFixitylogSlice, *LocationsFixitylogSetter]("locations_fixitylog", buildLocationsFixitylogColumns("locations_fixitylog"), []string{"id"})

// LocationsFixitylogsQuery is a query on the locations_fixitylog table
type LocationsFixitylogsQuery = *mysql.ViewQuery[*LocationsFixitylog, LocationsFixitylogSlice]

// locationsFixitylogR is where relationships are stored.
type locationsFixitylogR struct {
	PackageLocationsPackage *LocationsPackage // locations_fixitylog_package_id_0201e98f_fk_locations
}

func buildLocationsFixitylogColumns(alias string) locationsFixitylogColumns {
	return locationsFixitylogColumns{
		ColumnsExpr: expr.NewColumnsExpr(
			"id", "success", "error_details", "datetime_reported", "package_id",
		).WithParent("locations_fixitylog"),
		tableAlias:       alias,
		ID:               mysql.Quote(alias, "id"),
		Success:          mysql.Quote(alias, "success"),
		ErrorDetails:     mysql.Quote(alias, "error_details"),
		DatetimeReported: mysql.Quote(alias, "datetime_reported"),
		PackageID:        mysql.Quote(alias, "package_id"),
	}
}

type locationsFixitylogColumns struct {
	expr.ColumnsExpr
	tableAlias       string
	ID               mysql.Expression
	Success          mysql.Expression
	ErrorDetails     mysql.Expression
	DatetimeReported mysql.Expression
	PackageID        mysql.Expression
}

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

func (locationsFixitylogColumns) AliasedAs(alias string) locationsFixitylogColumns {
	return buildLocationsFixitylogColumns(alias)
}

// LocationsFixitylogSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type LocationsFixitylogSetter struct {
	ID               omit.Val[int32]      `db:"id,pk,autoincr" `
	Success          omitnull.Val[bool]   `db:"success" `
	ErrorDetails     omitnull.Val[string] `db:"error_details" `
	DatetimeReported omit.Val[time.Time]  `db:"datetime_reported" `
	PackageID        omit.Val[string]     `db:"package_id" `
}

func (s LocationsFixitylogSetter) SetColumns() []string {
	vals := make([]string, 0, 5)
	if s.ID.IsValue() {
		vals = append(vals, "id")
	}
	if !s.Success.IsUnset() {
		vals = append(vals, "success")
	}
	if !s.ErrorDetails.IsUnset() {
		vals = append(vals, "error_details")
	}
	if s.DatetimeReported.IsValue() {
		vals = append(vals, "datetime_reported")
	}
	if s.PackageID.IsValue() {
		vals = append(vals, "package_id")
	}
	return vals
}

func (s LocationsFixitylogSetter) Overwrite(t *LocationsFixitylog) {
	if s.ID.IsValue() {
		t.ID = s.ID.MustGet()
	}
	if !s.Success.IsUnset() {
		t.Success = s.Success.MustGetNull()
	}
	if !s.ErrorDetails.IsUnset() {
		t.ErrorDetails = s.ErrorDetails.MustGetNull()
	}
	if s.DatetimeReported.IsValue() {
		t.DatetimeReported = s.DatetimeReported.MustGet()
	}
	if s.PackageID.IsValue() {
		t.PackageID = s.PackageID.MustGet()
	}
}

func (s *LocationsFixitylogSetter) Apply(q *dialect.InsertQuery) {
	q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
		return LocationsFixitylogs.BeforeInsertHooks.RunHooks(ctx, exec, s)
	})

	q.AppendValues(
		bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
			if !(s.ID.IsValue()) {
				return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start)
			}
			return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start)
		}), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
			if !(!s.Success.IsUnset()) {
				return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start)
			}
			return mysql.Arg(s.Success.MustGetNull()).WriteSQL(ctx, w, d, start)
		}), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
			if !(!s.ErrorDetails.IsUnset()) {
				return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start)
			}
			return mysql.Arg(s.ErrorDetails.MustGetNull()).WriteSQL(ctx, w, d, start)
		}), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
			if !(s.DatetimeReported.IsValue()) {
				return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start)
			}
			return mysql.Arg(s.DatetimeReported.MustGet()).WriteSQL(ctx, w, d, start)
		}), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
			if !(s.PackageID.IsValue()) {
				return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start)
			}
			return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start)
		}))
}

func (s LocationsFixitylogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
	return um.Set(s.Expressions("locations_fixitylog")...)
}

func (s LocationsFixitylogSetter) Expressions(prefix ...string) []bob.Expression {
	exprs := make([]bob.Expression, 0, 5)

	if s.ID.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			mysql.Quote(append(prefix, "id")...),
			mysql.Arg(s.ID),
		}})
	}

	if !s.Success.IsUnset() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			mysql.Quote(append(prefix, "success")...),
			mysql.Arg(s.Success),
		}})
	}

	if !s.ErrorDetails.IsUnset() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			mysql.Quote(append(prefix, "error_details")...),
			mysql.Arg(s.ErrorDetails),
		}})
	}

	if s.DatetimeReported.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			mysql.Quote(append(prefix, "datetime_reported")...),
			mysql.Arg(s.DatetimeReported),
		}})
	}

	if s.PackageID.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			mysql.Quote(append(prefix, "package_id")...),
			mysql.Arg(s.PackageID),
		}})
	}

	return exprs
}

// FindLocationsFixitylog retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindLocationsFixitylog(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFixitylog, error) {
	if len(cols) == 0 {
		return LocationsFixitylogs.Query(
			sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))),
		).One(ctx, exec)
	}

	return LocationsFixitylogs.Query(
		sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))),
		sm.Columns(LocationsFixitylogs.Columns.Only(cols...)),
	).One(ctx, exec)
}

// LocationsFixitylogExists checks the presence of a single record by primary key
func LocationsFixitylogExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
	return LocationsFixitylogs.Query(
		sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))),
	).Exists(ctx, exec)
}

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

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o})
	case bob.QueryTypeInsert:
		ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o})
	case bob.QueryTypeUpdate:
		ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o})
	case bob.QueryTypeDelete:
		ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o})
	}

	return err
}

// primaryKeyVals returns the primary key values of the LocationsFixitylog
func (o *LocationsFixitylog) primaryKeyVals() bob.Expression {
	return mysql.Arg(o.ID)
}

func (o *LocationsFixitylog) pkEQ() dialect.Expression {
	return mysql.Quote("locations_fixitylog", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
		return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
	}))
}

// Update uses an executor to update the LocationsFixitylog
func (o *LocationsFixitylog) Update(ctx context.Context, exec bob.Executor, s *LocationsFixitylogSetter) error {
	_, err := LocationsFixitylogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec)
	if err != nil {
		return err
	}

	s.Overwrite(o)

	return nil
}

// Delete deletes a single LocationsFixitylog record with an executor
func (o *LocationsFixitylog) Delete(ctx context.Context, exec bob.Executor) error {
	_, err := LocationsFixitylogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
	return err
}

// Reload refreshes the LocationsFixitylog using the executor
func (o *LocationsFixitylog) Reload(ctx context.Context, exec bob.Executor) error {
	o2, err := LocationsFixitylogs.Query(
		sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(o.ID))),
	).One(ctx, exec)
	if err != nil {
		return err
	}
	o2.R = o.R
	*o = *o2

	return nil
}

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

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeInsert:
		ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeUpdate:
		ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeDelete:
		ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
	}

	return err
}

func (o LocationsFixitylogSlice) pkIN() dialect.Expression {
	if len(o) == 0 {
		return mysql.Raw("NULL")
	}

	return mysql.Quote("locations_fixitylog", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
		pkPairs := make([]bob.Expression, len(o))
		for i, row := range o {
			pkPairs[i] = row.primaryKeyVals()
		}
		return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
	}))
}

// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o LocationsFixitylogSlice) copyMatchingRows(from ...*LocationsFixitylog) {
	for i, old := range o {
		for _, new := range from {
			if new.ID != old.ID {
				continue
			}
			new.R = old.R
			o[i] = new
			break
		}
	}
}

// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o LocationsFixitylogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
	return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
		q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
			return LocationsFixitylogs.BeforeUpdateHooks.RunHooks(ctx, exec, o)
		})

		q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
			var err error
			switch retrieved := retrieved.(type) {
			case *LocationsFixitylog:
				o.copyMatchingRows(retrieved)
			case []*LocationsFixitylog:
				o.copyMatchingRows(retrieved...)
			case LocationsFixitylogSlice:
				o.copyMatchingRows(retrieved...)
			default:
				// If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog
				// then run the AfterUpdateHooks on the slice
				_, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
			}

			return err
		}))

		q.AppendWhere(o.pkIN())
	})
}

// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o LocationsFixitylogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
	return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
		q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
			return LocationsFixitylogs.BeforeDeleteHooks.RunHooks(ctx, exec, o)
		})

		q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
			var err error
			switch retrieved := retrieved.(type) {
			case *LocationsFixitylog:
				o.copyMatchingRows(retrieved)
			case []*LocationsFixitylog:
				o.copyMatchingRows(retrieved...)
			case LocationsFixitylogSlice:
				o.copyMatchingRows(retrieved...)
			default:
				// If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog
				// then run the AfterDeleteHooks on the slice
				_, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
			}

			return err
		}))

		q.AppendWhere(o.pkIN())
	})
}

func (o LocationsFixitylogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFixitylogSetter) error {
	_, err := LocationsFixitylogs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec)

	for i := range o {
		vals.Overwrite(o[i])
	}

	return err
}

func (o LocationsFixitylogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
	if len(o) == 0 {
		return nil
	}

	_, err := LocationsFixitylogs.Delete(o.DeleteMod()).Exec(ctx, exec)
	return err
}

func (o LocationsFixitylogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
	if len(o) == 0 {
		return nil
	}

	o2, err := LocationsFixitylogs.Query(sm.Where(o.pkIN())).All(ctx, exec)
	if err != nil {
		return err
	}

	o.copyMatchingRows(o2...)

	return nil
}

// PackageLocationsPackage starts a query for related objects on locations_package
func (o *LocationsFixitylog) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery {
	return LocationsPackages.Query(append(mods,
		sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))),
	)...)
}

func (os LocationsFixitylogSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery {
	PKArgSlice := make([]bob.Expression, len(os))
	for i, o := range os {
		PKArgSlice[i] = mysql.ArgGroup(o.PackageID)
	}
	PKArgExpr := mysql.Group(PKArgSlice...)

	return LocationsPackages.Query(append(mods,
		sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)),
	)...)
}

func attachLocationsFixitylogPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsFixitylog0 *LocationsFixitylog, locationsPackage1 *LocationsPackage) (*LocationsFixitylog, error) {
	setter := &LocationsFixitylogSetter{
		PackageID: omit.From(locationsPackage1.UUID),
	}

	err := locationsFixitylog0.Update(ctx, exec, setter)
	if err != nil {
		return nil, fmt.Errorf("attachLocationsFixitylogPackageLocationsPackage0: %w", err)
	}

	return locationsFixitylog0, nil
}

func (locationsFixitylog0 *LocationsFixitylog) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error {
	var err error

	locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec)
	if err != nil {
		return fmt.Errorf("inserting related objects: %w", err)
	}

	_, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1)
	if err != nil {
		return err
	}

	locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1

	locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0)

	return nil
}

func (locationsFixitylog0 *LocationsFixitylog) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error {
	var err error

	_, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1)
	if err != nil {
		return err
	}

	locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1

	locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0)

	return nil
}

type locationsFixitylogWhere[Q mysql.Filterable] struct {
	ID               mysql.WhereMod[Q, int32]
	Success          mysql.WhereNullMod[Q, bool]
	ErrorDetails     mysql.WhereNullMod[Q, string]
	DatetimeReported mysql.WhereMod[Q, time.Time]
	PackageID        mysql.WhereMod[Q, string]
}

func (locationsFixitylogWhere[Q]) AliasedAs(alias string) locationsFixitylogWhere[Q] {
	return buildLocationsFixitylogWhere[Q](buildLocationsFixitylogColumns(alias))
}

func buildLocationsFixitylogWhere[Q mysql.Filterable](cols locationsFixitylogColumns) locationsFixitylogWhere[Q] {
	return locationsFixitylogWhere[Q]{
		ID:               mysql.Where[Q, int32](cols.ID),
		Success:          mysql.WhereNull[Q, bool](cols.Success),
		ErrorDetails:     mysql.WhereNull[Q, string](cols.ErrorDetails),
		DatetimeReported: mysql.Where[Q, time.Time](cols.DatetimeReported),
		PackageID:        mysql.Where[Q, string](cols.PackageID),
	}
}

func (o *LocationsFixitylog) Preload(name string, retrieved any) error {
	if o == nil {
		return nil
	}

	switch name {
	case "PackageLocationsPackage":
		rel, ok := retrieved.(*LocationsPackage)
		if !ok {
			return fmt.Errorf("locationsFixitylog cannot load %T as %q", retrieved, name)
		}

		o.R.PackageLocationsPackage = rel

		if rel != nil {
			rel.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o}
		}
		return nil
	default:
		return fmt.Errorf("locationsFixitylog has no relationship %q", name)
	}
}

type locationsFixitylogPreloader struct {
	PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader
}

func buildLocationsFixitylogPreloader() locationsFixitylogPreloader {
	return locationsFixitylogPreloader{
		PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader {
			return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{
				Name: "PackageLocationsPackage",
				Sides: []mysql.PreloadSide{
					{
						From:        LocationsFixitylogs,
						To:          LocationsPackages,
						FromColumns: []string{"package_id"},
						ToColumns:   []string{"uuid"},
					},
				},
			}, LocationsPackages.Columns.Names(), opts...)
		},
	}
}

type locationsFixitylogThenLoader[Q orm.Loadable] struct {
	PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}

func buildLocationsFixitylogThenLoader[Q orm.Loadable]() locationsFixitylogThenLoader[Q] {
	type PackageLocationsPackageLoadInterface interface {
		LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
	}

	return locationsFixitylogThenLoader[Q]{
		PackageLocationsPackage: thenLoadBuilder[Q](
			"PackageLocationsPackage",
			func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
				return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...)
			},
		),
	}
}

// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct
func (o *LocationsFixitylog) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
	if o == nil {
		return nil
	}

	// Reset the relationship
	o.R.PackageLocationsPackage = nil

	related, err := o.PackageLocationsPackage(mods...).One(ctx, exec)
	if err != nil {
		return err
	}

	related.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o}

	o.R.PackageLocationsPackage = related
	return nil
}

// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct
func (os LocationsFixitylogSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
	if len(os) == 0 {
		return nil
	}

	locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec)
	if err != nil {
		return err
	}

	for _, o := range os {
		if o == nil {
			continue
		}

		for _, rel := range locationsPackages {

			if !(o.PackageID == rel.UUID) {
				continue
			}

			rel.R.PackageLocationsFixitylogs = append(rel.R.PackageLocationsFixitylogs, o)

			o.R.PackageLocationsPackage = rel
			break
		}
	}

	return nil
}

type locationsFixitylogJoins[Q dialect.Joinable] struct {
	typ                     string
	PackageLocationsPackage modAs[Q, locationsPackageColumns]
}

func (j locationsFixitylogJoins[Q]) aliasedAs(alias string) locationsFixitylogJoins[Q] {
	return buildLocationsFixitylogJoins[Q](buildLocationsFixitylogColumns(alias), j.typ)
}

func buildLocationsFixitylogJoins[Q dialect.Joinable](cols locationsFixitylogColumns, typ string) locationsFixitylogJoins[Q] {
	return locationsFixitylogJoins[Q]{
		typ: typ,
		PackageLocationsPackage: modAs[Q, locationsPackageColumns]{
			c: LocationsPackages.Columns,
			f: func(to locationsPackageColumns) bob.Mod[Q] {
				mods := make(mods.QueryMods[Q], 0, 1)

				{
					mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On(
						to.UUID.EQ(cols.PackageID),
					))
				}

				return mods
			},
		},
	}
}
