// 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"
	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 ResidentMod interface {
	Apply(context.Context, *ResidentTemplate)
}

type ResidentModFunc func(context.Context, *ResidentTemplate)

func (f ResidentModFunc) Apply(ctx context.Context, n *ResidentTemplate) {
	f(ctx, n)
}

type ResidentModSlice []ResidentMod

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

// ResidentTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ResidentTemplate struct {
	AddressID   func() int32
	Created     func() time.Time
	Creator     func() int32
	ID          func() int32
	Name        func() string
	PhoneMobile func() null.Val[string]
	SiteID      func() int32
	SiteVersion func() int32

	r residentR
	f *Factory

	alreadyPersisted bool
}

type residentR struct {
	Address          *residentRAddressR
	CreatorUser      *residentRCreatorUserR
	PhoneMobilePhone *residentRPhoneMobilePhoneR
	Site             *residentRSiteR
}

type residentRAddressR struct {
	o *AddressTemplate
}
type residentRCreatorUserR struct {
	o *UserTemplate
}
type residentRPhoneMobilePhoneR struct {
	o *CommsPhoneTemplate
}
type residentRSiteR struct {
	o *SiteTemplate
}

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

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

	if t.r.CreatorUser != nil {
		rel := t.r.CreatorUser.o.Build()
		rel.R.CreatorResidents = append(rel.R.CreatorResidents, o)
		o.Creator = rel.ID // h2
		o.R.CreatorUser = rel
	}

	if t.r.PhoneMobilePhone != nil {
		rel := t.r.PhoneMobilePhone.o.Build()
		rel.R.PhoneMobileResidents = append(rel.R.PhoneMobileResidents, o)
		o.PhoneMobile = null.From(rel.E164) // h2
		o.R.PhoneMobilePhone = rel
	}

	if t.r.Site != nil {
		rel := t.r.Site.o.Build()
		rel.R.Residents = append(rel.R.Residents, o)
		o.SiteID = rel.ID           // h2
		o.SiteVersion = rel.Version // h2
		o.R.Site = rel
	}
}

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

	if o.AddressID != nil {
		val := o.AddressID()
		m.AddressID = omit.From(val)
	}
	if o.Created != nil {
		val := o.Created()
		m.Created = omit.From(val)
	}
	if o.Creator != nil {
		val := o.Creator()
		m.Creator = omit.From(val)
	}
	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.PhoneMobile != nil {
		val := o.PhoneMobile()
		m.PhoneMobile = omitnull.FromNull(val)
	}
	if o.SiteID != nil {
		val := o.SiteID()
		m.SiteID = omit.From(val)
	}
	if o.SiteVersion != nil {
		val := o.SiteVersion()
		m.SiteVersion = omit.From(val)
	}

	return m
}

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

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

	return m
}

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

	if o.AddressID != nil {
		m.AddressID = o.AddressID()
	}
	if o.Created != nil {
		m.Created = o.Created()
	}
	if o.Creator != nil {
		m.Creator = o.Creator()
	}
	if o.ID != nil {
		m.ID = o.ID()
	}
	if o.Name != nil {
		m.Name = o.Name()
	}
	if o.PhoneMobile != nil {
		m.PhoneMobile = o.PhoneMobile()
	}
	if o.SiteID != nil {
		m.SiteID = o.SiteID()
	}
	if o.SiteVersion != nil {
		m.SiteVersion = o.SiteVersion()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableResident(m *models.ResidentSetter) {
	if !(m.AddressID.IsValue()) {
		val := random_int32(nil)
		m.AddressID = omit.From(val)
	}
	if !(m.Created.IsValue()) {
		val := random_time_Time(nil)
		m.Created = omit.From(val)
	}
	if !(m.Creator.IsValue()) {
		val := random_int32(nil)
		m.Creator = omit.From(val)
	}
	if !(m.Name.IsValue()) {
		val := random_string(nil)
		m.Name = omit.From(val)
	}
	if !(m.SiteID.IsValue()) {
		val := random_int32(nil)
		m.SiteID = omit.From(val)
	}
	if !(m.SiteVersion.IsValue()) {
		val := random_int32(nil)
		m.SiteVersion = omit.From(val)
	}
}

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

	isPhoneMobilePhoneDone, _ := residentRelPhoneMobilePhoneCtx.Value(ctx)
	if !isPhoneMobilePhoneDone && o.r.PhoneMobilePhone != nil {
		ctx = residentRelPhoneMobilePhoneCtx.WithValue(ctx, true)
		if o.r.PhoneMobilePhone.o.alreadyPersisted {
			m.R.PhoneMobilePhone = o.r.PhoneMobilePhone.o.Build()
		} else {
			var rel2 *models.CommsPhone
			rel2, err = o.r.PhoneMobilePhone.o.Create(ctx, exec)
			if err != nil {
				return err
			}
			err = m.AttachPhoneMobilePhone(ctx, exec, rel2)
			if err != nil {
				return err
			}
		}

	}

	return err
}

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

	if o.r.Address == nil {
		ResidentMods.WithNewAddress().Apply(ctx, o)
	}

	var rel0 *models.Address

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

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

	if o.r.CreatorUser == nil {
		ResidentMods.WithNewCreatorUser().Apply(ctx, o)
	}

	var rel1 *models.User

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

	opt.Creator = omit.From(rel1.ID)

	if o.r.Site == nil {
		ResidentMods.WithNewSite().Apply(ctx, o)
	}

	var rel3 *models.Site

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

	opt.SiteID = omit.From(rel3.ID)
	opt.SiteVersion = omit.From(rel3.Version)

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

	m.R.Address = rel0
	m.R.CreatorUser = rel1
	m.R.Site = rel3

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

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

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

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

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

	return m, nil
}

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

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

// Resident has methods that act as mods for the ResidentTemplate
var ResidentMods residentMods

type residentMods struct{}

func (m residentMods) RandomizeAllColumns(f *faker.Faker) ResidentMod {
	return ResidentModSlice{
		ResidentMods.RandomAddressID(f),
		ResidentMods.RandomCreated(f),
		ResidentMods.RandomCreator(f),
		ResidentMods.RandomID(f),
		ResidentMods.RandomName(f),
		ResidentMods.RandomPhoneMobile(f),
		ResidentMods.RandomSiteID(f),
		ResidentMods.RandomSiteVersion(f),
	}
}

// Set the model columns to this value
func (m residentMods) AddressID(val int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.AddressID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m residentMods) AddressIDFunc(f func() int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.AddressID = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetAddressID() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.AddressID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomAddressID(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.AddressID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) Created(val time.Time) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Created = func() time.Time { return val }
	})
}

// Set the Column from the function
func (m residentMods) CreatedFunc(f func() time.Time) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Created = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetCreated() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Created = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomCreated(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Created = func() time.Time {
			return random_time_Time(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) Creator(val int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Creator = func() int32 { return val }
	})
}

// Set the Column from the function
func (m residentMods) CreatorFunc(f func() int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Creator = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetCreator() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Creator = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomCreator(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Creator = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) ID(val int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.ID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m residentMods) IDFunc(f func() int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.ID = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetID() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		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 residentMods) RandomID(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.ID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) Name(val string) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Name = func() string { return val }
	})
}

// Set the Column from the function
func (m residentMods) NameFunc(f func() string) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Name = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetName() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		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 residentMods) RandomName(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.Name = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) PhoneMobile(val null.Val[string]) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.PhoneMobile = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m residentMods) PhoneMobileFunc(f func() null.Val[string]) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.PhoneMobile = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetPhoneMobile() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.PhoneMobile = 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 residentMods) RandomPhoneMobile(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.PhoneMobile = 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 residentMods) RandomPhoneMobileNotNull(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.PhoneMobile = 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 residentMods) SiteID(val int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m residentMods) SiteIDFunc(f func() int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteID = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetSiteID() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomSiteID(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m residentMods) SiteVersion(val int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteVersion = func() int32 { return val }
	})
}

// Set the Column from the function
func (m residentMods) SiteVersionFunc(f func() int32) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteVersion = f
	})
}

// Clear any values for the column
func (m residentMods) UnsetSiteVersion() ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteVersion = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m residentMods) RandomSiteVersion(f *faker.Faker) ResidentMod {
	return ResidentModFunc(func(_ context.Context, o *ResidentTemplate) {
		o.SiteVersion = func() int32 {
			return random_int32(f)
		}
	})
}

func (m residentMods) WithParentsCascading() ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		if isDone, _ := residentWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = residentWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewAddressWithContext(ctx, AddressMods.WithParentsCascading())
			m.WithAddress(related).Apply(ctx, o)
		}
		{

			related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
			m.WithCreatorUser(related).Apply(ctx, o)
		}
		{

			related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
			m.WithPhoneMobilePhone(related).Apply(ctx, o)
		}
		{

			related := o.f.NewSiteWithContext(ctx, SiteMods.WithParentsCascading())
			m.WithSite(related).Apply(ctx, o)
		}
	})
}

func (m residentMods) WithAddress(rel *AddressTemplate) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Address = &residentRAddressR{
			o: rel,
		}
	})
}

func (m residentMods) WithNewAddress(mods ...AddressMod) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		related := o.f.NewAddressWithContext(ctx, mods...)

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

func (m residentMods) WithExistingAddress(em *models.Address) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Address = &residentRAddressR{
			o: o.f.FromExistingAddress(em),
		}
	})
}

func (m residentMods) WithoutAddress() ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Address = nil
	})
}

func (m residentMods) WithCreatorUser(rel *UserTemplate) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.CreatorUser = &residentRCreatorUserR{
			o: rel,
		}
	})
}

func (m residentMods) WithNewCreatorUser(mods ...UserMod) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		related := o.f.NewUserWithContext(ctx, mods...)

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

func (m residentMods) WithExistingCreatorUser(em *models.User) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.CreatorUser = &residentRCreatorUserR{
			o: o.f.FromExistingUser(em),
		}
	})
}

func (m residentMods) WithoutCreatorUser() ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.CreatorUser = nil
	})
}

func (m residentMods) WithPhoneMobilePhone(rel *CommsPhoneTemplate) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.PhoneMobilePhone = &residentRPhoneMobilePhoneR{
			o: rel,
		}
	})
}

func (m residentMods) WithNewPhoneMobilePhone(mods ...CommsPhoneMod) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		related := o.f.NewCommsPhoneWithContext(ctx, mods...)

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

func (m residentMods) WithExistingPhoneMobilePhone(em *models.CommsPhone) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.PhoneMobilePhone = &residentRPhoneMobilePhoneR{
			o: o.f.FromExistingCommsPhone(em),
		}
	})
}

func (m residentMods) WithoutPhoneMobilePhone() ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.PhoneMobilePhone = nil
	})
}

func (m residentMods) WithSite(rel *SiteTemplate) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Site = &residentRSiteR{
			o: rel,
		}
	})
}

func (m residentMods) WithNewSite(mods ...SiteMod) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		related := o.f.NewSiteWithContext(ctx, mods...)

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

func (m residentMods) WithExistingSite(em *models.Site) ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Site = &residentRSiteR{
			o: o.f.FromExistingSite(em),
		}
	})
}

func (m residentMods) WithoutSite() ResidentMod {
	return ResidentModFunc(func(ctx context.Context, o *ResidentTemplate) {
		o.r.Site = nil
	})
}
