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

	"github.com/Gleipnir-Technology/bob"
	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 ArcgisAccountMod interface {
	Apply(context.Context, *ArcgisAccountTemplate)
}

type ArcgisAccountModFunc func(context.Context, *ArcgisAccountTemplate)

func (f ArcgisAccountModFunc) Apply(ctx context.Context, n *ArcgisAccountTemplate) {
	f(ctx, n)
}

type ArcgisAccountModSlice []ArcgisAccountMod

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

// ArcgisAccountTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ArcgisAccountTemplate struct {
	ID             func() string
	Name           func() string
	OrganizationID func() int32
	URLFeatures    func() null.Val[string]
	URLInsights    func() null.Val[string]
	URLGeometry    func() null.Val[string]
	URLNotebooks   func() null.Val[string]
	URLTiles       func() null.Val[string]

	r arcgisAccountR
	f *Factory

	alreadyPersisted bool
}

type arcgisAccountR struct {
	Organization               *arcgisAccountROrganizationR
	ArcgisAccountOauthTokens   []*arcgisAccountRArcgisAccountOauthTokensR
	ServiceFeatures            []*arcgisAccountRServiceFeaturesR
	ServiceMaps                []*arcgisAccountRServiceMapsR
	ArcgisAccountOrganizations []*arcgisAccountRArcgisAccountOrganizationsR
}

type arcgisAccountROrganizationR struct {
	o *OrganizationTemplate
}
type arcgisAccountRArcgisAccountOauthTokensR struct {
	number int
	o      *ArcgisOauthTokenTemplate
}
type arcgisAccountRServiceFeaturesR struct {
	number int
	o      *ArcgisServiceFeatureTemplate
}
type arcgisAccountRServiceMapsR struct {
	number int
	o      *ArcgisServiceMapTemplate
}
type arcgisAccountRArcgisAccountOrganizationsR struct {
	number int
	o      *OrganizationTemplate
}

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

// setModelRels creates and sets the relationships on *models.ArcgisAccount
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisAccountTemplate) setModelRels(o *models.ArcgisAccount) {
	if t.r.Organization != nil {
		rel := t.r.Organization.o.Build()
		rel.R.Accounts = append(rel.R.Accounts, o)
		o.OrganizationID = rel.ID // h2
		o.R.Organization = rel
	}

	if t.r.ArcgisAccountOauthTokens != nil {
		rel := models.ArcgisOauthTokenSlice{}
		for _, r := range t.r.ArcgisAccountOauthTokens {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.ArcgisAccountID = null.From(o.ID) // h2
				rel.R.ArcgisAccountAccount = o
			}
			rel = append(rel, related...)
		}
		o.R.ArcgisAccountOauthTokens = rel
	}

	if t.r.ServiceFeatures != nil {
		rel := models.ArcgisServiceFeatureSlice{}
		for _, r := range t.r.ServiceFeatures {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.AccountID = null.From(o.ID) // h2
				rel.R.Account = o
			}
			rel = append(rel, related...)
		}
		o.R.ServiceFeatures = rel
	}

	if t.r.ServiceMaps != nil {
		rel := models.ArcgisServiceMapSlice{}
		for _, r := range t.r.ServiceMaps {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.AccountID = o.ID // h2
				rel.R.Account = o
			}
			rel = append(rel, related...)
		}
		o.R.ServiceMaps = rel
	}

	if t.r.ArcgisAccountOrganizations != nil {
		rel := models.OrganizationSlice{}
		for _, r := range t.r.ArcgisAccountOrganizations {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.ArcgisAccountID = null.From(o.ID) // h2
				rel.R.ArcgisAccountAccount = o
			}
			rel = append(rel, related...)
		}
		o.R.ArcgisAccountOrganizations = rel
	}
}

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

	if o.ID != nil {
		val := o.ID()
		m.ID = omit.From(val)
	}
	if o.Name != nil {
		val := o.Name()
		m.Name = omit.From(val)
	}
	if o.OrganizationID != nil {
		val := o.OrganizationID()
		m.OrganizationID = omit.From(val)
	}
	if o.URLFeatures != nil {
		val := o.URLFeatures()
		m.URLFeatures = omitnull.FromNull(val)
	}
	if o.URLInsights != nil {
		val := o.URLInsights()
		m.URLInsights = omitnull.FromNull(val)
	}
	if o.URLGeometry != nil {
		val := o.URLGeometry()
		m.URLGeometry = omitnull.FromNull(val)
	}
	if o.URLNotebooks != nil {
		val := o.URLNotebooks()
		m.URLNotebooks = omitnull.FromNull(val)
	}
	if o.URLTiles != nil {
		val := o.URLTiles()
		m.URLTiles = omitnull.FromNull(val)
	}

	return m
}

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

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

	return m
}

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

	if o.ID != nil {
		m.ID = o.ID()
	}
	if o.Name != nil {
		m.Name = o.Name()
	}
	if o.OrganizationID != nil {
		m.OrganizationID = o.OrganizationID()
	}
	if o.URLFeatures != nil {
		m.URLFeatures = o.URLFeatures()
	}
	if o.URLInsights != nil {
		m.URLInsights = o.URLInsights()
	}
	if o.URLGeometry != nil {
		m.URLGeometry = o.URLGeometry()
	}
	if o.URLNotebooks != nil {
		m.URLNotebooks = o.URLNotebooks()
	}
	if o.URLTiles != nil {
		m.URLTiles = o.URLTiles()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableArcgisAccount(m *models.ArcgisAccountSetter) {
	if !(m.ID.IsValue()) {
		val := random_string(nil)
		m.ID = omit.From(val)
	}
	if !(m.Name.IsValue()) {
		val := random_string(nil)
		m.Name = omit.From(val)
	}
	if !(m.OrganizationID.IsValue()) {
		val := random_int32(nil)
		m.OrganizationID = omit.From(val)
	}
}

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

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

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

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

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

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

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

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

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

	return err
}

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

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

	var rel0 *models.Organization

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

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

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

	m.R.Organization = rel0

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

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

// CreateOrFail builds a arcgisAccount 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 *ArcgisAccountTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ArcgisAccount {
	tb.Helper()
	m, err := o.Create(ctx, exec)
	if err != nil {
		tb.Fatal(err)
		return nil
	}
	return m
}

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

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

	return m, nil
}

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

// CreateManyOrFail builds multiple arcgisAccounts 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 ArcgisAccountTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ArcgisAccountSlice {
	tb.Helper()
	m, err := o.CreateMany(ctx, exec, number)
	if err != nil {
		tb.Fatal(err)
		return nil
	}
	return m
}

// ArcgisAccount has methods that act as mods for the ArcgisAccountTemplate
var ArcgisAccountMods arcgisAccountMods

type arcgisAccountMods struct{}

func (m arcgisAccountMods) RandomizeAllColumns(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModSlice{
		ArcgisAccountMods.RandomID(f),
		ArcgisAccountMods.RandomName(f),
		ArcgisAccountMods.RandomOrganizationID(f),
		ArcgisAccountMods.RandomURLFeatures(f),
		ArcgisAccountMods.RandomURLInsights(f),
		ArcgisAccountMods.RandomURLGeometry(f),
		ArcgisAccountMods.RandomURLNotebooks(f),
		ArcgisAccountMods.RandomURLTiles(f),
	}
}

// Set the model columns to this value
func (m arcgisAccountMods) ID(val string) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.ID = func() string { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) IDFunc(f func() string) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.ID = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetID() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		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 arcgisAccountMods) RandomID(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.ID = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisAccountMods) Name(val string) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.Name = func() string { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) NameFunc(f func() string) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.Name = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetName() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.Name = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisAccountMods) RandomName(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.Name = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisAccountMods) OrganizationID(val int32) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.OrganizationID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) OrganizationIDFunc(f func() int32) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.OrganizationID = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetOrganizationID() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		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 arcgisAccountMods) RandomOrganizationID(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.OrganizationID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisAccountMods) URLFeatures(val null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLFeatures = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) URLFeaturesFunc(f func() null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLFeatures = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetURLFeatures() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLFeatures = 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 arcgisAccountMods) RandomURLFeatures(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLFeatures = 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 arcgisAccountMods) RandomURLFeaturesNotNull(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLFeatures = 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 arcgisAccountMods) URLInsights(val null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLInsights = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) URLInsightsFunc(f func() null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLInsights = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetURLInsights() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLInsights = 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 arcgisAccountMods) RandomURLInsights(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLInsights = 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 arcgisAccountMods) RandomURLInsightsNotNull(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLInsights = 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 arcgisAccountMods) URLGeometry(val null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLGeometry = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) URLGeometryFunc(f func() null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLGeometry = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetURLGeometry() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLGeometry = 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 arcgisAccountMods) RandomURLGeometry(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLGeometry = 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 arcgisAccountMods) RandomURLGeometryNotNull(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLGeometry = 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 arcgisAccountMods) URLNotebooks(val null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLNotebooks = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) URLNotebooksFunc(f func() null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLNotebooks = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetURLNotebooks() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLNotebooks = 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 arcgisAccountMods) RandomURLNotebooks(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLNotebooks = 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 arcgisAccountMods) RandomURLNotebooksNotNull(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLNotebooks = 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 arcgisAccountMods) URLTiles(val null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLTiles = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisAccountMods) URLTilesFunc(f func() null.Val[string]) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLTiles = f
	})
}

// Clear any values for the column
func (m arcgisAccountMods) UnsetURLTiles() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLTiles = 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 arcgisAccountMods) RandomURLTiles(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLTiles = 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 arcgisAccountMods) RandomURLTilesNotNull(f *faker.Faker) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(_ context.Context, o *ArcgisAccountTemplate) {
		o.URLTiles = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

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

func (m arcgisAccountMods) WithParentsCascading() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		if isDone, _ := arcgisAccountWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = arcgisAccountWithParentsCascadingCtx.WithValue(ctx, true)
		{

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

func (m arcgisAccountMods) WithOrganization(rel *OrganizationTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.Organization = &arcgisAccountROrganizationR{
			o: rel,
		}
	})
}

func (m arcgisAccountMods) WithNewOrganization(mods ...OrganizationMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)

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

func (m arcgisAccountMods) WithExistingOrganization(em *models.Organization) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.Organization = &arcgisAccountROrganizationR{
			o: o.f.FromExistingOrganization(em),
		}
	})
}

func (m arcgisAccountMods) WithoutOrganization() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.Organization = nil
	})
}

func (m arcgisAccountMods) WithArcgisAccountOauthTokens(number int, related *ArcgisOauthTokenTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOauthTokens = []*arcgisAccountRArcgisAccountOauthTokensR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisAccountMods) WithNewArcgisAccountOauthTokens(number int, mods ...ArcgisOauthTokenMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
		m.WithArcgisAccountOauthTokens(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddArcgisAccountOauthTokens(number int, related *ArcgisOauthTokenTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOauthTokens = append(o.r.ArcgisAccountOauthTokens, &arcgisAccountRArcgisAccountOauthTokensR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisAccountMods) AddNewArcgisAccountOauthTokens(number int, mods ...ArcgisOauthTokenMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisOauthTokenWithContext(ctx, mods...)
		m.AddArcgisAccountOauthTokens(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddExistingArcgisAccountOauthTokens(existingModels ...*models.ArcgisOauthToken) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		for _, em := range existingModels {
			o.r.ArcgisAccountOauthTokens = append(o.r.ArcgisAccountOauthTokens, &arcgisAccountRArcgisAccountOauthTokensR{
				o: o.f.FromExistingArcgisOauthToken(em),
			})
		}
	})
}

func (m arcgisAccountMods) WithoutArcgisAccountOauthTokens() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOauthTokens = nil
	})
}

func (m arcgisAccountMods) WithServiceFeatures(number int, related *ArcgisServiceFeatureTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceFeatures = []*arcgisAccountRServiceFeaturesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisAccountMods) WithNewServiceFeatures(number int, mods ...ArcgisServiceFeatureMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisServiceFeatureWithContext(ctx, mods...)
		m.WithServiceFeatures(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddServiceFeatures(number int, related *ArcgisServiceFeatureTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceFeatures = append(o.r.ServiceFeatures, &arcgisAccountRServiceFeaturesR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisAccountMods) AddNewServiceFeatures(number int, mods ...ArcgisServiceFeatureMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisServiceFeatureWithContext(ctx, mods...)
		m.AddServiceFeatures(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddExistingServiceFeatures(existingModels ...*models.ArcgisServiceFeature) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		for _, em := range existingModels {
			o.r.ServiceFeatures = append(o.r.ServiceFeatures, &arcgisAccountRServiceFeaturesR{
				o: o.f.FromExistingArcgisServiceFeature(em),
			})
		}
	})
}

func (m arcgisAccountMods) WithoutServiceFeatures() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceFeatures = nil
	})
}

func (m arcgisAccountMods) WithServiceMaps(number int, related *ArcgisServiceMapTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceMaps = []*arcgisAccountRServiceMapsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisAccountMods) WithNewServiceMaps(number int, mods ...ArcgisServiceMapMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisServiceMapWithContext(ctx, mods...)
		m.WithServiceMaps(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddServiceMaps(number int, related *ArcgisServiceMapTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceMaps = append(o.r.ServiceMaps, &arcgisAccountRServiceMapsR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisAccountMods) AddNewServiceMaps(number int, mods ...ArcgisServiceMapMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewArcgisServiceMapWithContext(ctx, mods...)
		m.AddServiceMaps(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddExistingServiceMaps(existingModels ...*models.ArcgisServiceMap) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		for _, em := range existingModels {
			o.r.ServiceMaps = append(o.r.ServiceMaps, &arcgisAccountRServiceMapsR{
				o: o.f.FromExistingArcgisServiceMap(em),
			})
		}
	})
}

func (m arcgisAccountMods) WithoutServiceMaps() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ServiceMaps = nil
	})
}

func (m arcgisAccountMods) WithArcgisAccountOrganizations(number int, related *OrganizationTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOrganizations = []*arcgisAccountRArcgisAccountOrganizationsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisAccountMods) WithNewArcgisAccountOrganizations(number int, mods ...OrganizationMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.WithArcgisAccountOrganizations(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddArcgisAccountOrganizations(number int, related *OrganizationTemplate) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOrganizations = append(o.r.ArcgisAccountOrganizations, &arcgisAccountRArcgisAccountOrganizationsR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisAccountMods) AddNewArcgisAccountOrganizations(number int, mods ...OrganizationMod) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.AddArcgisAccountOrganizations(number, related).Apply(ctx, o)
	})
}

func (m arcgisAccountMods) AddExistingArcgisAccountOrganizations(existingModels ...*models.Organization) ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		for _, em := range existingModels {
			o.r.ArcgisAccountOrganizations = append(o.r.ArcgisAccountOrganizations, &arcgisAccountRArcgisAccountOrganizationsR{
				o: o.f.FromExistingOrganization(em),
			})
		}
	})
}

func (m arcgisAccountMods) WithoutArcgisAccountOrganizations() ArcgisAccountMod {
	return ArcgisAccountModFunc(func(ctx context.Context, o *ArcgisAccountTemplate) {
		o.r.ArcgisAccountOrganizations = nil
	})
}
