// 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 (
	"hash/maphash"

	"github.com/stephenafamo/bob"
	"github.com/stephenafamo/bob/clause"
	"github.com/stephenafamo/bob/dialect/mysql/dialect"
)

var (
	SelectJoins = getJoins[*dialect.SelectQuery]()
	UpdateJoins = getJoins[*dialect.UpdateQuery]()
	DeleteJoins = getJoins[*dialect.DeleteQuery]()
)

type joinSet[Q interface{ aliasedAs(string) Q }] struct {
	InnerJoin Q
	LeftJoin  Q
	RightJoin Q
}

func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] {
	return joinSet[Q]{
		InnerJoin: j.InnerJoin.aliasedAs(alias),
		LeftJoin:  j.LeftJoin.aliasedAs(alias),
		RightJoin: j.RightJoin.aliasedAs(alias),
	}
}

type joins[Q dialect.Joinable] struct {
	AuthGroups                        joinSet[authGroupJoins[Q]]
	AuthGroupPermissions              joinSet[authGroupPermissionJoins[Q]]
	AuthPermissions                   joinSet[authPermissionJoins[Q]]
	AuthUsers                         joinSet[authUserJoins[Q]]
	AuthUserGroups                    joinSet[authUserGroupJoins[Q]]
	AuthUserUserPermissions           joinSet[authUserUserPermissionJoins[Q]]
	DjangoAdminLogs                   joinSet[djangoAdminLogJoins[Q]]
	DjangoContentTypes                joinSet[djangoContentTypeJoins[Q]]
	LocationsArchipelagos             joinSet[locationsArchipelagoJoins[Q]]
	LocationsArkivums                 joinSet[locationsArkivumJoins[Q]]
	LocationsDataverses               joinSet[locationsDataverseJoins[Q]]
	LocationsDspaces                  joinSet[locationsDspaceJoins[Q]]
	LocationsDspacerests              joinSet[locationsDspacerestJoins[Q]]
	LocationsDuraclouds               joinSet[locationsDuracloudJoins[Q]]
	LocationsEvents                   joinSet[locationsEventJoins[Q]]
	LocationsFedoras                  joinSet[locationsFedoraJoins[Q]]
	LocationsFiles                    joinSet[locationsFileJoins[Q]]
	LocationsFixitylogs               joinSet[locationsFixitylogJoins[Q]]
	LocationsGPGS                     joinSet[locationsGPGJoins[Q]]
	LocationsLocalfilesystems         joinSet[locationsLocalfilesystemJoins[Q]]
	LocationsLocations                joinSet[locationsLocationJoins[Q]]
	LocationsLocationReplicators      joinSet[locationsLocationReplicatorJoins[Q]]
	LocationsLocationpipelines        joinSet[locationsLocationpipelineJoins[Q]]
	LocationsLockssomatics            joinSet[locationsLockssomaticJoins[Q]]
	LocationsNFS                      joinSet[locationsNFJoins[Q]]
	LocationsOfflinereplicastagings   joinSet[locationsOfflinereplicastagingJoins[Q]]
	LocationsPackages                 joinSet[locationsPackageJoins[Q]]
	LocationsPackageRelatedPackages   joinSet[locationsPackageRelatedPackageJoins[Q]]
	LocationsPackagedownloadtasks     joinSet[locationsPackagedownloadtaskJoins[Q]]
	LocationsPackagedownloadtaskfiles joinSet[locationsPackagedownloadtaskfileJoins[Q]]
	LocationsPipelines                joinSet[locationsPipelineJoins[Q]]
	LocationsPipelinelocalfs          joinSet[locationsPipelinelocalfJoins[Q]]
	LocationsRclones                  joinSet[locationsRcloneJoins[Q]]
	LocationsS3S                      joinSet[locationsS3Joins[Q]]
	LocationsSpaces                   joinSet[locationsSpaceJoins[Q]]
	LocationsSwifts                   joinSet[locationsSwiftJoins[Q]]
	TastypieApikeys                   joinSet[tastypieApikeyJoins[Q]]
}

func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q](c C, f F) joinSet[Q] {
	return joinSet[Q]{
		InnerJoin: f(c, clause.InnerJoin),
		LeftJoin:  f(c, clause.LeftJoin),
		RightJoin: f(c, clause.RightJoin),
	}
}

func getJoins[Q dialect.Joinable]() joins[Q] {
	return joins[Q]{
		AuthGroups:                        buildJoinSet[authGroupJoins[Q]](AuthGroups.Columns, buildAuthGroupJoins),
		AuthGroupPermissions:              buildJoinSet[authGroupPermissionJoins[Q]](AuthGroupPermissions.Columns, buildAuthGroupPermissionJoins),
		AuthPermissions:                   buildJoinSet[authPermissionJoins[Q]](AuthPermissions.Columns, buildAuthPermissionJoins),
		AuthUsers:                         buildJoinSet[authUserJoins[Q]](AuthUsers.Columns, buildAuthUserJoins),
		AuthUserGroups:                    buildJoinSet[authUserGroupJoins[Q]](AuthUserGroups.Columns, buildAuthUserGroupJoins),
		AuthUserUserPermissions:           buildJoinSet[authUserUserPermissionJoins[Q]](AuthUserUserPermissions.Columns, buildAuthUserUserPermissionJoins),
		DjangoAdminLogs:                   buildJoinSet[djangoAdminLogJoins[Q]](DjangoAdminLogs.Columns, buildDjangoAdminLogJoins),
		DjangoContentTypes:                buildJoinSet[djangoContentTypeJoins[Q]](DjangoContentTypes.Columns, buildDjangoContentTypeJoins),
		LocationsArchipelagos:             buildJoinSet[locationsArchipelagoJoins[Q]](LocationsArchipelagos.Columns, buildLocationsArchipelagoJoins),
		LocationsArkivums:                 buildJoinSet[locationsArkivumJoins[Q]](LocationsArkivums.Columns, buildLocationsArkivumJoins),
		LocationsDataverses:               buildJoinSet[locationsDataverseJoins[Q]](LocationsDataverses.Columns, buildLocationsDataverseJoins),
		LocationsDspaces:                  buildJoinSet[locationsDspaceJoins[Q]](LocationsDspaces.Columns, buildLocationsDspaceJoins),
		LocationsDspacerests:              buildJoinSet[locationsDspacerestJoins[Q]](LocationsDspacerests.Columns, buildLocationsDspacerestJoins),
		LocationsDuraclouds:               buildJoinSet[locationsDuracloudJoins[Q]](LocationsDuraclouds.Columns, buildLocationsDuracloudJoins),
		LocationsEvents:                   buildJoinSet[locationsEventJoins[Q]](LocationsEvents.Columns, buildLocationsEventJoins),
		LocationsFedoras:                  buildJoinSet[locationsFedoraJoins[Q]](LocationsFedoras.Columns, buildLocationsFedoraJoins),
		LocationsFiles:                    buildJoinSet[locationsFileJoins[Q]](LocationsFiles.Columns, buildLocationsFileJoins),
		LocationsFixitylogs:               buildJoinSet[locationsFixitylogJoins[Q]](LocationsFixitylogs.Columns, buildLocationsFixitylogJoins),
		LocationsGPGS:                     buildJoinSet[locationsGPGJoins[Q]](LocationsGPGS.Columns, buildLocationsGPGJoins),
		LocationsLocalfilesystems:         buildJoinSet[locationsLocalfilesystemJoins[Q]](LocationsLocalfilesystems.Columns, buildLocationsLocalfilesystemJoins),
		LocationsLocations:                buildJoinSet[locationsLocationJoins[Q]](LocationsLocations.Columns, buildLocationsLocationJoins),
		LocationsLocationReplicators:      buildJoinSet[locationsLocationReplicatorJoins[Q]](LocationsLocationReplicators.Columns, buildLocationsLocationReplicatorJoins),
		LocationsLocationpipelines:        buildJoinSet[locationsLocationpipelineJoins[Q]](LocationsLocationpipelines.Columns, buildLocationsLocationpipelineJoins),
		LocationsLockssomatics:            buildJoinSet[locationsLockssomaticJoins[Q]](LocationsLockssomatics.Columns, buildLocationsLockssomaticJoins),
		LocationsNFS:                      buildJoinSet[locationsNFJoins[Q]](LocationsNFS.Columns, buildLocationsNFJoins),
		LocationsOfflinereplicastagings:   buildJoinSet[locationsOfflinereplicastagingJoins[Q]](LocationsOfflinereplicastagings.Columns, buildLocationsOfflinereplicastagingJoins),
		LocationsPackages:                 buildJoinSet[locationsPackageJoins[Q]](LocationsPackages.Columns, buildLocationsPackageJoins),
		LocationsPackageRelatedPackages:   buildJoinSet[locationsPackageRelatedPackageJoins[Q]](LocationsPackageRelatedPackages.Columns, buildLocationsPackageRelatedPackageJoins),
		LocationsPackagedownloadtasks:     buildJoinSet[locationsPackagedownloadtaskJoins[Q]](LocationsPackagedownloadtasks.Columns, buildLocationsPackagedownloadtaskJoins),
		LocationsPackagedownloadtaskfiles: buildJoinSet[locationsPackagedownloadtaskfileJoins[Q]](LocationsPackagedownloadtaskfiles.Columns, buildLocationsPackagedownloadtaskfileJoins),
		LocationsPipelines:                buildJoinSet[locationsPipelineJoins[Q]](LocationsPipelines.Columns, buildLocationsPipelineJoins),
		LocationsPipelinelocalfs:          buildJoinSet[locationsPipelinelocalfJoins[Q]](LocationsPipelinelocalfs.Columns, buildLocationsPipelinelocalfJoins),
		LocationsRclones:                  buildJoinSet[locationsRcloneJoins[Q]](LocationsRclones.Columns, buildLocationsRcloneJoins),
		LocationsS3S:                      buildJoinSet[locationsS3Joins[Q]](LocationsS3S.Columns, buildLocationsS3Joins),
		LocationsSpaces:                   buildJoinSet[locationsSpaceJoins[Q]](LocationsSpaces.Columns, buildLocationsSpaceJoins),
		LocationsSwifts:                   buildJoinSet[locationsSwiftJoins[Q]](LocationsSwifts.Columns, buildLocationsSwiftJoins),
		TastypieApikeys:                   buildJoinSet[tastypieApikeyJoins[Q]](TastypieApikeys.Columns, buildTastypieApikeyJoins),
	}
}

type modAs[Q any, C interface{ AliasedAs(string) C }] struct {
	c C
	f func(C) bob.Mod[Q]
}

func (m modAs[Q, C]) Apply(q Q) {
	m.f(m.c).Apply(q)
}

func (m modAs[Q, C]) AliasedAs(alias string) bob.Mod[Q] {
	m.c = m.c.AliasedAs(alias)
	return m
}

func randInt() int64 {
	out := int64(new(maphash.Hash).Sum64())

	if out < 0 {
		return -out % 10000
	}

	return out % 10000
}
