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

import (
	"context"
	"testing"
	"time"

	"github.com/Gleipnir-Technology/bob"
	enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
	models "github.com/Gleipnir-Technology/nidus-sync/db/models"
	"github.com/aarondl/opt/null"
	"github.com/aarondl/opt/omit"
	"github.com/aarondl/opt/omitnull"
	"github.com/jaswdr/faker/v2"
)

type UserMod interface {
	Apply(context.Context, *UserTemplate)
}

type UserModFunc func(context.Context, *UserTemplate)

func (f UserModFunc) Apply(ctx context.Context, n *UserTemplate) {
	f(ctx, n)
}

type UserModSlice []UserMod

func (mods UserModSlice) Apply(ctx context.Context, n *UserTemplate) {
	for _, f := range mods {
		f.Apply(ctx, n)
	}
}

// UserTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type UserTemplate struct {
	ID                        func() int32
	ArcgisAccessToken         func() null.Val[string]
	ArcgisLicense             func() null.Val[enums.Arcgislicensetype]
	ArcgisRefreshToken        func() null.Val[string]
	ArcgisRefreshTokenExpires func() null.Val[time.Time]
	ArcgisRole                func() null.Val[string]
	DisplayName               func() string
	Email                     func() null.Val[string]
	OrganizationID            func() int32
	Username                  func() string
	PasswordHashType          func() enums.Hashtype
	PasswordHash              func() string
	Role                      func() enums.Userrole

	r userR
	f *Factory

	alreadyPersisted bool
}

type userR struct {
	UserOauthTokens                 []*userRUserOauthTokensR
	PublicUserUser                  []*userRPublicUserUserR
	CreatorComplianceReportRequests []*userRCreatorComplianceReportRequestsR
	CreatorFiles                    []*userRCreatorFilesR
	FileuploadPool                  []*userRFileuploadPoolR
	CreatorNoteAudios               []*userRCreatorNoteAudiosR
	DeletorNoteAudios               []*userRDeletorNoteAudiosR
	CreatorNoteImages               []*userRCreatorNoteImagesR
	DeletorNoteImages               []*userRDeletorNoteImagesR
	UserNotifications               []*userRUserNotificationsR
	CreatorPools                    []*userRCreatorPoolsR
	CreatorResidents                []*userRCreatorResidentsR
	CreatorSites                    []*userRCreatorSitesR
	Organization                    *userROrganizationR
}

type userRUserOauthTokensR struct {
	number int
	o      *ArcgisOauthTokenTemplate
}
type userRPublicUserUserR struct {
	number int
	o      *ArcgisUserTemplate
}
type userRCreatorComplianceReportRequestsR struct {
	number int
	o      *ComplianceReportRequestTemplate
}
type userRCreatorFilesR struct {
	number int
	o      *FileuploadFileTemplate
}
type userRFileuploadPoolR struct {
	number int
	o      *FileuploadPoolTemplate
}
type userRCreatorNoteAudiosR struct {
	number int
	o      *NoteAudioTemplate
}
type userRDeletorNoteAudiosR struct {
	number int
	o      *NoteAudioTemplate
}
type userRCreatorNoteImagesR struct {
	number int
	o      *NoteImageTemplate
}
type userRDeletorNoteImagesR struct {
	number int
	o      *NoteImageTemplate
}
type userRUserNotificationsR struct {
	number int
	o      *NotificationTemplate
}
type userRCreatorPoolsR struct {
	number int
	o      *PoolTemplate
}
type userRCreatorResidentsR struct {
	number int
	o      *ResidentTemplate
}
type userRCreatorSitesR struct {
	number int
	o      *SiteTemplate
}
type userROrganizationR struct {
	o *OrganizationTemplate
}

// Apply mods to the UserTemplate
func (o *UserTemplate) Apply(ctx context.Context, mods ...UserMod) {
	for _, mod := range mods {
		mod.Apply(ctx, o)
	}
}

// setModelRels creates and sets the relationships on *models.User
// according to the relationships in the template. Nothing is inserted into the db
func (t UserTemplate) setModelRels(o *models.User) {
	if t.r.UserOauthTokens != nil {
		rel := models.ArcgisOauthTokenSlice{}
		for _, r := range t.r.UserOauthTokens {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.UserID = o.ID // h2
				rel.R.UserUser = o
			}
			rel = append(rel, related...)
		}
		o.R.UserOauthTokens = rel
	}

	if t.r.PublicUserUser != nil {
		rel := models.ArcgisUserSlice{}
		for _, r := range t.r.PublicUserUser {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PublicUserID = o.ID // h2
				rel.R.PublicUserUser = o
			}
			rel = append(rel, related...)
		}
		o.R.PublicUserUser = rel
	}

	if t.r.CreatorComplianceReportRequests != nil {
		rel := models.ComplianceReportRequestSlice{}
		for _, r := range t.r.CreatorComplianceReportRequests {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.Creator = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorComplianceReportRequests = rel
	}

	if t.r.CreatorFiles != nil {
		rel := models.FileuploadFileSlice{}
		for _, r := range t.r.CreatorFiles {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorFiles = rel
	}

	if t.r.FileuploadPool != nil {
		rel := models.FileuploadPoolSlice{}
		for _, r := range t.r.FileuploadPool {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.FileuploadPool = rel
	}

	if t.r.CreatorNoteAudios != nil {
		rel := models.NoteAudioSlice{}
		for _, r := range t.r.CreatorNoteAudios {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorNoteAudios = rel
	}

	if t.r.DeletorNoteAudios != nil {
		rel := models.NoteAudioSlice{}
		for _, r := range t.r.DeletorNoteAudios {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.DeletorID = null.From(o.ID) // h2
				rel.R.DeletorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.DeletorNoteAudios = rel
	}

	if t.r.CreatorNoteImages != nil {
		rel := models.NoteImageSlice{}
		for _, r := range t.r.CreatorNoteImages {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorNoteImages = rel
	}

	if t.r.DeletorNoteImages != nil {
		rel := models.NoteImageSlice{}
		for _, r := range t.r.DeletorNoteImages {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.DeletorID = null.From(o.ID) // h2
				rel.R.DeletorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.DeletorNoteImages = rel
	}

	if t.r.UserNotifications != nil {
		rel := models.NotificationSlice{}
		for _, r := range t.r.UserNotifications {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.UserID = o.ID // h2
				rel.R.UserUser = o
			}
			rel = append(rel, related...)
		}
		o.R.UserNotifications = rel
	}

	if t.r.CreatorPools != nil {
		rel := models.PoolSlice{}
		for _, r := range t.r.CreatorPools {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorPools = rel
	}

	if t.r.CreatorResidents != nil {
		rel := models.ResidentSlice{}
		for _, r := range t.r.CreatorResidents {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.Creator = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorResidents = rel
	}

	if t.r.CreatorSites != nil {
		rel := models.SiteSlice{}
		for _, r := range t.r.CreatorSites {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.CreatorID = o.ID // h2
				rel.R.CreatorUser = o
			}
			rel = append(rel, related...)
		}
		o.R.CreatorSites = rel
	}

	if t.r.Organization != nil {
		rel := t.r.Organization.o.Build()
		rel.R.User = append(rel.R.User, o)
		o.OrganizationID = rel.ID // h2
		o.R.Organization = rel
	}
}

// BuildSetter returns an *models.UserSetter
// this does nothing with the relationship templates
func (o UserTemplate) BuildSetter() *models.UserSetter {
	m := &models.UserSetter{}

	if o.ID != nil {
		val := o.ID()
		m.ID = omit.From(val)
	}
	if o.ArcgisAccessToken != nil {
		val := o.ArcgisAccessToken()
		m.ArcgisAccessToken = omitnull.FromNull(val)
	}
	if o.ArcgisLicense != nil {
		val := o.ArcgisLicense()
		m.ArcgisLicense = omitnull.FromNull(val)
	}
	if o.ArcgisRefreshToken != nil {
		val := o.ArcgisRefreshToken()
		m.ArcgisRefreshToken = omitnull.FromNull(val)
	}
	if o.ArcgisRefreshTokenExpires != nil {
		val := o.ArcgisRefreshTokenExpires()
		m.ArcgisRefreshTokenExpires = omitnull.FromNull(val)
	}
	if o.ArcgisRole != nil {
		val := o.ArcgisRole()
		m.ArcgisRole = omitnull.FromNull(val)
	}
	if o.DisplayName != nil {
		val := o.DisplayName()
		m.DisplayName = omit.From(val)
	}
	if o.Email != nil {
		val := o.Email()
		m.Email = omitnull.FromNull(val)
	}
	if o.OrganizationID != nil {
		val := o.OrganizationID()
		m.OrganizationID = omit.From(val)
	}
	if o.Username != nil {
		val := o.Username()
		m.Username = omit.From(val)
	}
	if o.PasswordHashType != nil {
		val := o.PasswordHashType()
		m.PasswordHashType = omit.From(val)
	}
	if o.PasswordHash != nil {
		val := o.PasswordHash()
		m.PasswordHash = omit.From(val)
	}
	if o.Role != nil {
		val := o.Role()
		m.Role = omit.From(val)
	}

	return m
}

// BuildManySetter returns an []*models.UserSetter
// this does nothing with the relationship templates
func (o UserTemplate) BuildManySetter(number int) []*models.UserSetter {
	m := make([]*models.UserSetter, number)

	for i := range m {
		m[i] = o.BuildSetter()
	}

	return m
}

// Build returns an *models.User
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use UserTemplate.Create
func (o UserTemplate) Build() *models.User {
	m := &models.User{}

	if o.ID != nil {
		m.ID = o.ID()
	}
	if o.ArcgisAccessToken != nil {
		m.ArcgisAccessToken = o.ArcgisAccessToken()
	}
	if o.ArcgisLicense != nil {
		m.ArcgisLicense = o.ArcgisLicense()
	}
	if o.ArcgisRefreshToken != nil {
		m.ArcgisRefreshToken = o.ArcgisRefreshToken()
	}
	if o.ArcgisRefreshTokenExpires != nil {
		m.ArcgisRefreshTokenExpires = o.ArcgisRefreshTokenExpires()
	}
	if o.ArcgisRole != nil {
		m.ArcgisRole = o.ArcgisRole()
	}
	if o.DisplayName != nil {
		m.DisplayName = o.DisplayName()
	}
	if o.Email != nil {
		m.Email = o.Email()
	}
	if o.OrganizationID != nil {
		m.OrganizationID = o.OrganizationID()
	}
	if o.Username != nil {
		m.Username = o.Username()
	}
	if o.PasswordHashType != nil {
		m.PasswordHashType = o.PasswordHashType()
	}
	if o.PasswordHash != nil {
		m.PasswordHash = o.PasswordHash()
	}
	if o.Role != nil {
		m.Role = o.Role()
	}

	o.setModelRels(m)

	return m
}

// BuildMany returns an models.UserSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use UserTemplate.CreateMany
func (o UserTemplate) BuildMany(number int) models.UserSlice {
	m := make(models.UserSlice, number)

	for i := range m {
		m[i] = o.Build()
	}

	return m
}

func ensureCreatableUser(m *models.UserSetter) {
	if !(m.DisplayName.IsValue()) {
		val := random_string(nil, "200")
		m.DisplayName = omit.From(val)
	}
	if !(m.OrganizationID.IsValue()) {
		val := random_int32(nil)
		m.OrganizationID = omit.From(val)
	}
	if !(m.Username.IsValue()) {
		val := random_string(nil)
		m.Username = omit.From(val)
	}
	if !(m.PasswordHashType.IsValue()) {
		val := random_enums_Hashtype(nil)
		m.PasswordHashType = omit.From(val)
	}
	if !(m.PasswordHash.IsValue()) {
		val := random_string(nil)
		m.PasswordHash = omit.From(val)
	}
	if !(m.Role.IsValue()) {
		val := random_enums_Userrole(nil)
		m.Role = omit.From(val)
	}
}

// insertOptRels creates and inserts any optional the relationships on *models.User
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.User) error {
	var err error

	isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx)
	if !isUserOauthTokensDone && o.r.UserOauthTokens != nil {
		ctx = userRelUserOauthTokensCtx.WithValue(ctx, true)
		for _, r := range o.r.UserOauthTokens {
			if r.o.alreadyPersisted {
				m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build())
			} else {
				rel0, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachUserOauthTokens(ctx, exec, rel0...)
				if err != nil {
					return err
				}
			}
		}
	}

	isPublicUserUserDone, _ := userRelPublicUserUserCtx.Value(ctx)
	if !isPublicUserUserDone && o.r.PublicUserUser != nil {
		ctx = userRelPublicUserUserCtx.WithValue(ctx, true)
		for _, r := range o.r.PublicUserUser {
			if r.o.alreadyPersisted {
				m.R.PublicUserUser = append(m.R.PublicUserUser, r.o.Build())
			} else {
				rel1, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachPublicUserUser(ctx, exec, rel1...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorComplianceReportRequestsDone, _ := userRelCreatorComplianceReportRequestsCtx.Value(ctx)
	if !isCreatorComplianceReportRequestsDone && o.r.CreatorComplianceReportRequests != nil {
		ctx = userRelCreatorComplianceReportRequestsCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorComplianceReportRequests {
			if r.o.alreadyPersisted {
				m.R.CreatorComplianceReportRequests = append(m.R.CreatorComplianceReportRequests, r.o.Build())
			} else {
				rel2, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorComplianceReportRequests(ctx, exec, rel2...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorFilesDone, _ := userRelCreatorFilesCtx.Value(ctx)
	if !isCreatorFilesDone && o.r.CreatorFiles != nil {
		ctx = userRelCreatorFilesCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorFiles {
			if r.o.alreadyPersisted {
				m.R.CreatorFiles = append(m.R.CreatorFiles, r.o.Build())
			} else {
				rel3, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorFiles(ctx, exec, rel3...)
				if err != nil {
					return err
				}
			}
		}
	}

	isFileuploadPoolDone, _ := userRelFileuploadPoolCtx.Value(ctx)
	if !isFileuploadPoolDone && o.r.FileuploadPool != nil {
		ctx = userRelFileuploadPoolCtx.WithValue(ctx, true)
		for _, r := range o.r.FileuploadPool {
			if r.o.alreadyPersisted {
				m.R.FileuploadPool = append(m.R.FileuploadPool, r.o.Build())
			} else {
				rel4, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachFileuploadPool(ctx, exec, rel4...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorNoteAudiosDone, _ := userRelCreatorNoteAudiosCtx.Value(ctx)
	if !isCreatorNoteAudiosDone && o.r.CreatorNoteAudios != nil {
		ctx = userRelCreatorNoteAudiosCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorNoteAudios {
			if r.o.alreadyPersisted {
				m.R.CreatorNoteAudios = append(m.R.CreatorNoteAudios, r.o.Build())
			} else {
				rel5, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorNoteAudios(ctx, exec, rel5...)
				if err != nil {
					return err
				}
			}
		}
	}

	isDeletorNoteAudiosDone, _ := userRelDeletorNoteAudiosCtx.Value(ctx)
	if !isDeletorNoteAudiosDone && o.r.DeletorNoteAudios != nil {
		ctx = userRelDeletorNoteAudiosCtx.WithValue(ctx, true)
		for _, r := range o.r.DeletorNoteAudios {
			if r.o.alreadyPersisted {
				m.R.DeletorNoteAudios = append(m.R.DeletorNoteAudios, r.o.Build())
			} else {
				rel6, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachDeletorNoteAudios(ctx, exec, rel6...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorNoteImagesDone, _ := userRelCreatorNoteImagesCtx.Value(ctx)
	if !isCreatorNoteImagesDone && o.r.CreatorNoteImages != nil {
		ctx = userRelCreatorNoteImagesCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorNoteImages {
			if r.o.alreadyPersisted {
				m.R.CreatorNoteImages = append(m.R.CreatorNoteImages, r.o.Build())
			} else {
				rel7, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorNoteImages(ctx, exec, rel7...)
				if err != nil {
					return err
				}
			}
		}
	}

	isDeletorNoteImagesDone, _ := userRelDeletorNoteImagesCtx.Value(ctx)
	if !isDeletorNoteImagesDone && o.r.DeletorNoteImages != nil {
		ctx = userRelDeletorNoteImagesCtx.WithValue(ctx, true)
		for _, r := range o.r.DeletorNoteImages {
			if r.o.alreadyPersisted {
				m.R.DeletorNoteImages = append(m.R.DeletorNoteImages, r.o.Build())
			} else {
				rel8, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachDeletorNoteImages(ctx, exec, rel8...)
				if err != nil {
					return err
				}
			}
		}
	}

	isUserNotificationsDone, _ := userRelUserNotificationsCtx.Value(ctx)
	if !isUserNotificationsDone && o.r.UserNotifications != nil {
		ctx = userRelUserNotificationsCtx.WithValue(ctx, true)
		for _, r := range o.r.UserNotifications {
			if r.o.alreadyPersisted {
				m.R.UserNotifications = append(m.R.UserNotifications, r.o.Build())
			} else {
				rel9, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachUserNotifications(ctx, exec, rel9...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorPoolsDone, _ := userRelCreatorPoolsCtx.Value(ctx)
	if !isCreatorPoolsDone && o.r.CreatorPools != nil {
		ctx = userRelCreatorPoolsCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorPools {
			if r.o.alreadyPersisted {
				m.R.CreatorPools = append(m.R.CreatorPools, r.o.Build())
			} else {
				rel10, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorPools(ctx, exec, rel10...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorResidentsDone, _ := userRelCreatorResidentsCtx.Value(ctx)
	if !isCreatorResidentsDone && o.r.CreatorResidents != nil {
		ctx = userRelCreatorResidentsCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorResidents {
			if r.o.alreadyPersisted {
				m.R.CreatorResidents = append(m.R.CreatorResidents, r.o.Build())
			} else {
				rel11, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorResidents(ctx, exec, rel11...)
				if err != nil {
					return err
				}
			}
		}
	}

	isCreatorSitesDone, _ := userRelCreatorSitesCtx.Value(ctx)
	if !isCreatorSitesDone && o.r.CreatorSites != nil {
		ctx = userRelCreatorSitesCtx.WithValue(ctx, true)
		for _, r := range o.r.CreatorSites {
			if r.o.alreadyPersisted {
				m.R.CreatorSites = append(m.R.CreatorSites, r.o.Build())
			} else {
				rel12, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachCreatorSites(ctx, exec, rel12...)
				if err != nil {
					return err
				}
			}
		}
	}

	return err
}

// Create builds a user and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *UserTemplate) Create(ctx context.Context, exec bob.Executor) (*models.User, error) {
	var err error
	opt := o.BuildSetter()
	ensureCreatableUser(opt)

	if o.r.Organization == nil {
		UserMods.WithNewOrganization().Apply(ctx, o)
	}

	var rel13 *models.Organization

	if o.r.Organization.o.alreadyPersisted {
		rel13 = o.r.Organization.o.Build()
	} else {
		rel13, err = o.r.Organization.o.Create(ctx, exec)
		if err != nil {
			return nil, err
		}
	}

	opt.OrganizationID = omit.From(rel13.ID)

	m, err := models.Users.Insert(opt).One(ctx, exec)
	if err != nil {
		return nil, err
	}

	m.R.Organization = rel13

	if err := o.insertOptRels(ctx, exec, m); err != nil {
		return nil, err
	}
	return m, err
}

// MustCreate builds a user and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *UserTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.User {
	m, err := o.Create(ctx, exec)
	if err != nil {
		panic(err)
	}
	return m
}

// CreateOrFail builds a user and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *UserTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.User {
	tb.Helper()
	m, err := o.Create(ctx, exec)
	if err != nil {
		tb.Fatal(err)
		return nil
	}
	return m
}

// CreateMany builds multiple users and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o UserTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.UserSlice, error) {
	var err error
	m := make(models.UserSlice, number)

	for i := range m {
		m[i], err = o.Create(ctx, exec)
		if err != nil {
			return nil, err
		}
	}

	return m, nil
}

// MustCreateMany builds multiple users and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o UserTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.UserSlice {
	m, err := o.CreateMany(ctx, exec, number)
	if err != nil {
		panic(err)
	}
	return m
}

// CreateManyOrFail builds multiple users and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o UserTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.UserSlice {
	tb.Helper()
	m, err := o.CreateMany(ctx, exec, number)
	if err != nil {
		tb.Fatal(err)
		return nil
	}
	return m
}

// User has methods that act as mods for the UserTemplate
var UserMods userMods

type userMods struct{}

func (m userMods) RandomizeAllColumns(f *faker.Faker) UserMod {
	return UserModSlice{
		UserMods.RandomID(f),
		UserMods.RandomArcgisAccessToken(f),
		UserMods.RandomArcgisLicense(f),
		UserMods.RandomArcgisRefreshToken(f),
		UserMods.RandomArcgisRefreshTokenExpires(f),
		UserMods.RandomArcgisRole(f),
		UserMods.RandomDisplayName(f),
		UserMods.RandomEmail(f),
		UserMods.RandomOrganizationID(f),
		UserMods.RandomUsername(f),
		UserMods.RandomPasswordHashType(f),
		UserMods.RandomPasswordHash(f),
		UserMods.RandomRole(f),
	}
}

// Set the model columns to this value
func (m userMods) ID(val int32) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m userMods) IDFunc(f func() int32) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ID = f
	})
}

// Clear any values for the column
func (m userMods) UnsetID() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomID(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m userMods) ArcgisAccessToken(val null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisAccessToken = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m userMods) ArcgisAccessTokenFunc(f func() null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisAccessToken = f
	})
}

// Clear any values for the column
func (m userMods) UnsetArcgisAccessToken() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisAccessToken = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomArcgisAccessToken(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisAccessToken = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomArcgisAccessTokenNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisAccessToken = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) ArcgisLicense(val null.Val[enums.Arcgislicensetype]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] { return val }
	})
}

// Set the Column from the function
func (m userMods) ArcgisLicenseFunc(f func() null.Val[enums.Arcgislicensetype]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisLicense = f
	})
}

// Clear any values for the column
func (m userMods) UnsetArcgisLicense() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisLicense = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomArcgisLicense(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_enums_Arcgislicensetype(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomArcgisLicenseNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_enums_Arcgislicensetype(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) ArcgisRefreshToken(val null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshToken = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m userMods) ArcgisRefreshTokenFunc(f func() null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshToken = f
	})
}

// Clear any values for the column
func (m userMods) UnsetArcgisRefreshToken() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshToken = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomArcgisRefreshToken(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshToken = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomArcgisRefreshTokenNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshToken = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) ArcgisRefreshTokenExpires(val null.Val[time.Time]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] { return val }
	})
}

// Set the Column from the function
func (m userMods) ArcgisRefreshTokenExpiresFunc(f func() null.Val[time.Time]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshTokenExpires = f
	})
}

// Clear any values for the column
func (m userMods) UnsetArcgisRefreshTokenExpires() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshTokenExpires = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomArcgisRefreshTokenExpires(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_time_Time(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomArcgisRefreshTokenExpiresNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_time_Time(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) ArcgisRole(val null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRole = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m userMods) ArcgisRoleFunc(f func() null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRole = f
	})
}

// Clear any values for the column
func (m userMods) UnsetArcgisRole() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRole = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomArcgisRole(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRole = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomArcgisRoleNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.ArcgisRole = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) DisplayName(val string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.DisplayName = func() string { return val }
	})
}

// Set the Column from the function
func (m userMods) DisplayNameFunc(f func() string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.DisplayName = f
	})
}

// Clear any values for the column
func (m userMods) UnsetDisplayName() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.DisplayName = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomDisplayName(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.DisplayName = func() string {
			return random_string(f, "200")
		}
	})
}

// Set the model columns to this value
func (m userMods) Email(val null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Email = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m userMods) EmailFunc(f func() null.Val[string]) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Email = f
	})
}

// Clear any values for the column
func (m userMods) UnsetEmail() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Email = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m userMods) RandomEmail(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Email = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m userMods) RandomEmailNotNull(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Email = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Set the model columns to this value
func (m userMods) OrganizationID(val int32) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.OrganizationID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m userMods) OrganizationIDFunc(f func() int32) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.OrganizationID = f
	})
}

// Clear any values for the column
func (m userMods) UnsetOrganizationID() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.OrganizationID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomOrganizationID(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.OrganizationID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m userMods) Username(val string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Username = func() string { return val }
	})
}

// Set the Column from the function
func (m userMods) UsernameFunc(f func() string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Username = f
	})
}

// Clear any values for the column
func (m userMods) UnsetUsername() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Username = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomUsername(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Username = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m userMods) PasswordHashType(val enums.Hashtype) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHashType = func() enums.Hashtype { return val }
	})
}

// Set the Column from the function
func (m userMods) PasswordHashTypeFunc(f func() enums.Hashtype) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHashType = f
	})
}

// Clear any values for the column
func (m userMods) UnsetPasswordHashType() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHashType = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomPasswordHashType(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHashType = func() enums.Hashtype {
			return random_enums_Hashtype(f)
		}
	})
}

// Set the model columns to this value
func (m userMods) PasswordHash(val string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHash = func() string { return val }
	})
}

// Set the Column from the function
func (m userMods) PasswordHashFunc(f func() string) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHash = f
	})
}

// Clear any values for the column
func (m userMods) UnsetPasswordHash() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHash = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomPasswordHash(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.PasswordHash = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m userMods) Role(val enums.Userrole) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Role = func() enums.Userrole { return val }
	})
}

// Set the Column from the function
func (m userMods) RoleFunc(f func() enums.Userrole) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Role = f
	})
}

// Clear any values for the column
func (m userMods) UnsetRole() UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Role = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m userMods) RandomRole(f *faker.Faker) UserMod {
	return UserModFunc(func(_ context.Context, o *UserTemplate) {
		o.Role = func() enums.Userrole {
			return random_enums_Userrole(f)
		}
	})
}

func (m userMods) WithParentsCascading() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		if isDone, _ := userWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = userWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading())
			m.WithOrganization(related).Apply(ctx, o)
		}
	})
}

func (m userMods) WithOrganization(rel *OrganizationTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.Organization = &userROrganizationR{
			o: rel,
		}
	})
}

func (m userMods) WithNewOrganization(mods ...OrganizationMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)

		m.WithOrganization(related).Apply(ctx, o)
	})
}

func (m userMods) WithExistingOrganization(em *models.Organization) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.Organization = &userROrganizationR{
			o: o.f.FromExistingOrganization(em),
		}
	})
}

func (m userMods) WithoutOrganization() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.Organization = nil
	})
}

func (m userMods) WithUserOauthTokens(number int, related *ArcgisOauthTokenTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserOauthTokens = []*userRUserOauthTokensR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewUserOauthTokens(number int, mods ...ArcgisOauthTokenMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
		m.WithUserOauthTokens(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddUserOauthTokens(number int, related *ArcgisOauthTokenTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewUserOauthTokens(number int, mods ...ArcgisOauthTokenMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
		m.AddUserOauthTokens(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingUserOauthTokens(existingModels ...*models.ArcgisOauthToken) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{
				o: o.f.FromExistingArcgisOauthToken(em),
			})
		}
	})
}

func (m userMods) WithoutUserOauthTokens() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserOauthTokens = nil
	})
}

func (m userMods) WithPublicUserUser(number int, related *ArcgisUserTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.PublicUserUser = []*userRPublicUserUserR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewPublicUserUser(number int, mods ...ArcgisUserMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewArcgisUserWithContext(ctx, mods...)
		m.WithPublicUserUser(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddPublicUserUser(number int, related *ArcgisUserTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.PublicUserUser = append(o.r.PublicUserUser, &userRPublicUserUserR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewPublicUserUser(number int, mods ...ArcgisUserMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewArcgisUserWithContext(ctx, mods...)
		m.AddPublicUserUser(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingPublicUserUser(existingModels ...*models.ArcgisUser) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.PublicUserUser = append(o.r.PublicUserUser, &userRPublicUserUserR{
				o: o.f.FromExistingArcgisUser(em),
			})
		}
	})
}

func (m userMods) WithoutPublicUserUser() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.PublicUserUser = nil
	})
}

func (m userMods) WithCreatorComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorComplianceReportRequests = []*userRCreatorComplianceReportRequestsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
		m.WithCreatorComplianceReportRequests(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorComplianceReportRequests = append(o.r.CreatorComplianceReportRequests, &userRCreatorComplianceReportRequestsR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
		m.AddCreatorComplianceReportRequests(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorComplianceReportRequests(existingModels ...*models.ComplianceReportRequest) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorComplianceReportRequests = append(o.r.CreatorComplianceReportRequests, &userRCreatorComplianceReportRequestsR{
				o: o.f.FromExistingComplianceReportRequest(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorComplianceReportRequests() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorComplianceReportRequests = nil
	})
}

func (m userMods) WithCreatorFiles(number int, related *FileuploadFileTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorFiles = []*userRCreatorFilesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorFiles(number int, mods ...FileuploadFileMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewFileuploadFileWithContext(ctx, mods...)
		m.WithCreatorFiles(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorFiles(number int, related *FileuploadFileTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorFiles = append(o.r.CreatorFiles, &userRCreatorFilesR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorFiles(number int, mods ...FileuploadFileMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewFileuploadFileWithContext(ctx, mods...)
		m.AddCreatorFiles(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorFiles(existingModels ...*models.FileuploadFile) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorFiles = append(o.r.CreatorFiles, &userRCreatorFilesR{
				o: o.f.FromExistingFileuploadFile(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorFiles() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorFiles = nil
	})
}

func (m userMods) WithFileuploadPool(number int, related *FileuploadPoolTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.FileuploadPool = []*userRFileuploadPoolR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewFileuploadPool(number int, mods ...FileuploadPoolMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.WithFileuploadPool(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddFileuploadPool(number int, related *FileuploadPoolTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.FileuploadPool = append(o.r.FileuploadPool, &userRFileuploadPoolR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewFileuploadPool(number int, mods ...FileuploadPoolMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.AddFileuploadPool(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingFileuploadPool(existingModels ...*models.FileuploadPool) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.FileuploadPool = append(o.r.FileuploadPool, &userRFileuploadPoolR{
				o: o.f.FromExistingFileuploadPool(em),
			})
		}
	})
}

func (m userMods) WithoutFileuploadPool() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.FileuploadPool = nil
	})
}

func (m userMods) WithCreatorNoteAudios(number int, related *NoteAudioTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteAudios = []*userRCreatorNoteAudiosR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorNoteAudios(number int, mods ...NoteAudioMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteAudioWithContext(ctx, mods...)
		m.WithCreatorNoteAudios(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorNoteAudios(number int, related *NoteAudioTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteAudios = append(o.r.CreatorNoteAudios, &userRCreatorNoteAudiosR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorNoteAudios(number int, mods ...NoteAudioMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteAudioWithContext(ctx, mods...)
		m.AddCreatorNoteAudios(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorNoteAudios(existingModels ...*models.NoteAudio) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorNoteAudios = append(o.r.CreatorNoteAudios, &userRCreatorNoteAudiosR{
				o: o.f.FromExistingNoteAudio(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorNoteAudios() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteAudios = nil
	})
}

func (m userMods) WithDeletorNoteAudios(number int, related *NoteAudioTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteAudios = []*userRDeletorNoteAudiosR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewDeletorNoteAudios(number int, mods ...NoteAudioMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteAudioWithContext(ctx, mods...)
		m.WithDeletorNoteAudios(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddDeletorNoteAudios(number int, related *NoteAudioTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteAudios = append(o.r.DeletorNoteAudios, &userRDeletorNoteAudiosR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewDeletorNoteAudios(number int, mods ...NoteAudioMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteAudioWithContext(ctx, mods...)
		m.AddDeletorNoteAudios(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingDeletorNoteAudios(existingModels ...*models.NoteAudio) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.DeletorNoteAudios = append(o.r.DeletorNoteAudios, &userRDeletorNoteAudiosR{
				o: o.f.FromExistingNoteAudio(em),
			})
		}
	})
}

func (m userMods) WithoutDeletorNoteAudios() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteAudios = nil
	})
}

func (m userMods) WithCreatorNoteImages(number int, related *NoteImageTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteImages = []*userRCreatorNoteImagesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorNoteImages(number int, mods ...NoteImageMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteImageWithContext(ctx, mods...)
		m.WithCreatorNoteImages(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorNoteImages(number int, related *NoteImageTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteImages = append(o.r.CreatorNoteImages, &userRCreatorNoteImagesR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorNoteImages(number int, mods ...NoteImageMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteImageWithContext(ctx, mods...)
		m.AddCreatorNoteImages(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorNoteImages(existingModels ...*models.NoteImage) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorNoteImages = append(o.r.CreatorNoteImages, &userRCreatorNoteImagesR{
				o: o.f.FromExistingNoteImage(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorNoteImages() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorNoteImages = nil
	})
}

func (m userMods) WithDeletorNoteImages(number int, related *NoteImageTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteImages = []*userRDeletorNoteImagesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewDeletorNoteImages(number int, mods ...NoteImageMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteImageWithContext(ctx, mods...)
		m.WithDeletorNoteImages(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddDeletorNoteImages(number int, related *NoteImageTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteImages = append(o.r.DeletorNoteImages, &userRDeletorNoteImagesR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewDeletorNoteImages(number int, mods ...NoteImageMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNoteImageWithContext(ctx, mods...)
		m.AddDeletorNoteImages(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingDeletorNoteImages(existingModels ...*models.NoteImage) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.DeletorNoteImages = append(o.r.DeletorNoteImages, &userRDeletorNoteImagesR{
				o: o.f.FromExistingNoteImage(em),
			})
		}
	})
}

func (m userMods) WithoutDeletorNoteImages() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.DeletorNoteImages = nil
	})
}

func (m userMods) WithUserNotifications(number int, related *NotificationTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserNotifications = []*userRUserNotificationsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewUserNotifications(number int, mods ...NotificationMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNotificationWithContext(ctx, mods...)
		m.WithUserNotifications(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddUserNotifications(number int, related *NotificationTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewUserNotifications(number int, mods ...NotificationMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewNotificationWithContext(ctx, mods...)
		m.AddUserNotifications(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingUserNotifications(existingModels ...*models.Notification) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{
				o: o.f.FromExistingNotification(em),
			})
		}
	})
}

func (m userMods) WithoutUserNotifications() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.UserNotifications = nil
	})
}

func (m userMods) WithCreatorPools(number int, related *PoolTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorPools = []*userRCreatorPoolsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorPools(number int, mods ...PoolMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewPoolWithContext(ctx, mods...)
		m.WithCreatorPools(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorPools(number int, related *PoolTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorPools(number int, mods ...PoolMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewPoolWithContext(ctx, mods...)
		m.AddCreatorPools(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorPools(existingModels ...*models.Pool) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{
				o: o.f.FromExistingPool(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorPools() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorPools = nil
	})
}

func (m userMods) WithCreatorResidents(number int, related *ResidentTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorResidents = []*userRCreatorResidentsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorResidents(number int, mods ...ResidentMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewResidentWithContext(ctx, mods...)
		m.WithCreatorResidents(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorResidents(number int, related *ResidentTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorResidents = append(o.r.CreatorResidents, &userRCreatorResidentsR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorResidents(number int, mods ...ResidentMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewResidentWithContext(ctx, mods...)
		m.AddCreatorResidents(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorResidents(existingModels ...*models.Resident) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorResidents = append(o.r.CreatorResidents, &userRCreatorResidentsR{
				o: o.f.FromExistingResident(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorResidents() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorResidents = nil
	})
}

func (m userMods) WithCreatorSites(number int, related *SiteTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorSites = []*userRCreatorSitesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m userMods) WithNewCreatorSites(number int, mods ...SiteMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewSiteWithContext(ctx, mods...)
		m.WithCreatorSites(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddCreatorSites(number int, related *SiteTemplate) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorSites = append(o.r.CreatorSites, &userRCreatorSitesR{
			number: number,
			o:      related,
		})
	})
}

func (m userMods) AddNewCreatorSites(number int, mods ...SiteMod) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		related := o.f.NewSiteWithContext(ctx, mods...)
		m.AddCreatorSites(number, related).Apply(ctx, o)
	})
}

func (m userMods) AddExistingCreatorSites(existingModels ...*models.Site) UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		for _, em := range existingModels {
			o.r.CreatorSites = append(o.r.CreatorSites, &userRCreatorSitesR{
				o: o.f.FromExistingSite(em),
			})
		}
	})
}

func (m userMods) WithoutCreatorSites() UserMod {
	return UserModFunc(func(ctx context.Context, o *UserTemplate) {
		o.r.CreatorSites = nil
	})
}
