// 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"
	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/jaswdr/faker/v2"
)

type CommsPhoneMod interface {
	Apply(context.Context, *CommsPhoneTemplate)
}

type CommsPhoneModFunc func(context.Context, *CommsPhoneTemplate)

func (f CommsPhoneModFunc) Apply(ctx context.Context, n *CommsPhoneTemplate) {
	f(ctx, n)
}

type CommsPhoneModSlice []CommsPhoneMod

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

// CommsPhoneTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsPhoneTemplate struct {
	E164         func() string
	IsSubscribed func() bool
	Status       func() enums.CommsPhonestatustype

	r commsPhoneR
	f *Factory

	alreadyPersisted bool
}

type commsPhoneR struct {
	DestinationTextJobs           []*commsPhoneRDestinationTextJobsR
	DestinationTextLogs           []*commsPhoneRDestinationTextLogsR
	SourceTextLogs                []*commsPhoneRSourceTextLogsR
	Organizations                 []*commsPhoneROrganizationsR
	PropertyOwnerPhoneE164Pools   []*commsPhoneRPropertyOwnerPhoneE164PoolsR
	ResidentPhoneE164Pools        []*commsPhoneRResidentPhoneE164PoolsR
	PhoneE164NotifyPhoneNuisances []*commsPhoneRPhoneE164NotifyPhoneNuisancesR
	PhoneE164NotifyPhonePools     []*commsPhoneRPhoneE164NotifyPhonePoolsR
	PhoneE164SubscribePhones      []*commsPhoneRPhoneE164SubscribePhonesR
	PhoneMobileResidents          []*commsPhoneRPhoneMobileResidentsR
}

type commsPhoneRDestinationTextJobsR struct {
	number int
	o      *CommsTextJobTemplate
}
type commsPhoneRDestinationTextLogsR struct {
	number int
	o      *CommsTextLogTemplate
}
type commsPhoneRSourceTextLogsR struct {
	number int
	o      *CommsTextLogTemplate
}
type commsPhoneROrganizationsR struct {
	number int
	o      *OrganizationTemplate
}
type commsPhoneRPropertyOwnerPhoneE164PoolsR struct {
	number int
	o      *FileuploadPoolTemplate
}
type commsPhoneRResidentPhoneE164PoolsR struct {
	number int
	o      *FileuploadPoolTemplate
}
type commsPhoneRPhoneE164NotifyPhoneNuisancesR struct {
	number int
	o      *PublicreportNotifyPhoneNuisanceTemplate
}
type commsPhoneRPhoneE164NotifyPhonePoolsR struct {
	number int
	o      *PublicreportNotifyPhonePoolTemplate
}
type commsPhoneRPhoneE164SubscribePhonesR struct {
	number int
	o      *PublicreportSubscribePhoneTemplate
}
type commsPhoneRPhoneMobileResidentsR struct {
	number int
	o      *ResidentTemplate
}

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

// setModelRels creates and sets the relationships on *models.CommsPhone
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
	if t.r.DestinationTextJobs != nil {
		rel := models.CommsTextJobSlice{}
		for _, r := range t.r.DestinationTextJobs {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.Destination = o.E164 // h2
				rel.R.DestinationPhone = o
			}
			rel = append(rel, related...)
		}
		o.R.DestinationTextJobs = rel
	}

	if t.r.DestinationTextLogs != nil {
		rel := models.CommsTextLogSlice{}
		for _, r := range t.r.DestinationTextLogs {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.Destination = o.E164 // h2
				rel.R.DestinationPhone = o
			}
			rel = append(rel, related...)
		}
		o.R.DestinationTextLogs = rel
	}

	if t.r.SourceTextLogs != nil {
		rel := models.CommsTextLogSlice{}
		for _, r := range t.r.SourceTextLogs {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.Source = o.E164 // h2
				rel.R.SourcePhone = o
			}
			rel = append(rel, related...)
		}
		o.R.SourceTextLogs = rel
	}

	if t.r.Organizations != nil {
		rel := models.OrganizationSlice{}
		for _, r := range t.r.Organizations {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.R.Phones = append(rel.R.Phones, o)
			}
			rel = append(rel, related...)
		}
		o.R.Organizations = rel
	}

	if t.r.PropertyOwnerPhoneE164Pools != nil {
		rel := models.FileuploadPoolSlice{}
		for _, r := range t.r.PropertyOwnerPhoneE164Pools {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PropertyOwnerPhoneE164 = null.From(o.E164) // h2
				rel.R.PropertyOwnerPhoneE164Phone = o
			}
			rel = append(rel, related...)
		}
		o.R.PropertyOwnerPhoneE164Pools = rel
	}

	if t.r.ResidentPhoneE164Pools != nil {
		rel := models.FileuploadPoolSlice{}
		for _, r := range t.r.ResidentPhoneE164Pools {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.ResidentPhoneE164 = null.From(o.E164) // h2
				rel.R.ResidentPhoneE164Phone = o
			}
			rel = append(rel, related...)
		}
		o.R.ResidentPhoneE164Pools = rel
	}

	if t.r.PhoneE164NotifyPhoneNuisances != nil {
		rel := models.PublicreportNotifyPhoneNuisanceSlice{}
		for _, r := range t.r.PhoneE164NotifyPhoneNuisances {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PhoneE164 = o.E164 // h2
				rel.R.PhoneE164Phone = o
			}
			rel = append(rel, related...)
		}
		o.R.PhoneE164NotifyPhoneNuisances = rel
	}

	if t.r.PhoneE164NotifyPhonePools != nil {
		rel := models.PublicreportNotifyPhonePoolSlice{}
		for _, r := range t.r.PhoneE164NotifyPhonePools {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PhoneE164 = o.E164 // h2
				rel.R.PhoneE164Phone = o
			}
			rel = append(rel, related...)
		}
		o.R.PhoneE164NotifyPhonePools = rel
	}

	if t.r.PhoneE164SubscribePhones != nil {
		rel := models.PublicreportSubscribePhoneSlice{}
		for _, r := range t.r.PhoneE164SubscribePhones {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PhoneE164 = o.E164 // h2
				rel.R.PhoneE164Phone = o
			}
			rel = append(rel, related...)
		}
		o.R.PhoneE164SubscribePhones = rel
	}

	if t.r.PhoneMobileResidents != nil {
		rel := models.ResidentSlice{}
		for _, r := range t.r.PhoneMobileResidents {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.PhoneMobile = null.From(o.E164) // h2
				rel.R.PhoneMobilePhone = o
			}
			rel = append(rel, related...)
		}
		o.R.PhoneMobileResidents = rel
	}
}

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

	if o.E164 != nil {
		val := o.E164()
		m.E164 = omit.From(val)
	}
	if o.IsSubscribed != nil {
		val := o.IsSubscribed()
		m.IsSubscribed = omit.From(val)
	}
	if o.Status != nil {
		val := o.Status()
		m.Status = omit.From(val)
	}

	return m
}

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

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

	return m
}

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

	if o.E164 != nil {
		m.E164 = o.E164()
	}
	if o.IsSubscribed != nil {
		m.IsSubscribed = o.IsSubscribed()
	}
	if o.Status != nil {
		m.Status = o.Status()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableCommsPhone(m *models.CommsPhoneSetter) {
	if !(m.E164.IsValue()) {
		val := random_string(nil)
		m.E164 = omit.From(val)
	}
	if !(m.IsSubscribed.IsValue()) {
		val := random_bool(nil)
		m.IsSubscribed = omit.From(val)
	}
	if !(m.Status.IsValue()) {
		val := random_enums_CommsPhonestatustype(nil)
		m.Status = omit.From(val)
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return err
}

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

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

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

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

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

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

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

	return m, nil
}

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

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

// CommsPhone has methods that act as mods for the CommsPhoneTemplate
var CommsPhoneMods commsPhoneMods

type commsPhoneMods struct{}

func (m commsPhoneMods) RandomizeAllColumns(f *faker.Faker) CommsPhoneMod {
	return CommsPhoneModSlice{
		CommsPhoneMods.RandomE164(f),
		CommsPhoneMods.RandomIsSubscribed(f),
		CommsPhoneMods.RandomStatus(f),
	}
}

// Set the model columns to this value
func (m commsPhoneMods) E164(val string) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.E164 = func() string { return val }
	})
}

// Set the Column from the function
func (m commsPhoneMods) E164Func(f func() string) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.E164 = f
	})
}

// Clear any values for the column
func (m commsPhoneMods) UnsetE164() CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.E164 = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsPhoneMods) RandomE164(f *faker.Faker) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.E164 = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m commsPhoneMods) IsSubscribed(val bool) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.IsSubscribed = func() bool { return val }
	})
}

// Set the Column from the function
func (m commsPhoneMods) IsSubscribedFunc(f func() bool) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.IsSubscribed = f
	})
}

// Clear any values for the column
func (m commsPhoneMods) UnsetIsSubscribed() CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.IsSubscribed = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsPhoneMods) RandomIsSubscribed(f *faker.Faker) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.IsSubscribed = func() bool {
			return random_bool(f)
		}
	})
}

// Set the model columns to this value
func (m commsPhoneMods) Status(val enums.CommsPhonestatustype) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.Status = func() enums.CommsPhonestatustype { return val }
	})
}

// Set the Column from the function
func (m commsPhoneMods) StatusFunc(f func() enums.CommsPhonestatustype) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.Status = f
	})
}

// Clear any values for the column
func (m commsPhoneMods) UnsetStatus() CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.Status = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsPhoneMods) RandomStatus(f *faker.Faker) CommsPhoneMod {
	return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
		o.Status = func() enums.CommsPhonestatustype {
			return random_enums_CommsPhonestatustype(f)
		}
	})
}

func (m commsPhoneMods) WithParentsCascading() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		if isDone, _ := commsPhoneWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = commsPhoneWithParentsCascadingCtx.WithValue(ctx, true)
	})
}

func (m commsPhoneMods) WithDestinationTextJobs(number int, related *CommsTextJobTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextJobs = []*commsPhoneRDestinationTextJobsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewDestinationTextJobs(number int, mods ...CommsTextJobMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextJobWithContext(ctx, mods...)
		m.WithDestinationTextJobs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddDestinationTextJobs(number int, related *CommsTextJobTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextJobs = append(o.r.DestinationTextJobs, &commsPhoneRDestinationTextJobsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewDestinationTextJobs(number int, mods ...CommsTextJobMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextJobWithContext(ctx, mods...)
		m.AddDestinationTextJobs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingDestinationTextJobs(existingModels ...*models.CommsTextJob) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.DestinationTextJobs = append(o.r.DestinationTextJobs, &commsPhoneRDestinationTextJobsR{
				o: o.f.FromExistingCommsTextJob(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutDestinationTextJobs() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextJobs = nil
	})
}

func (m commsPhoneMods) WithDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextLogs = []*commsPhoneRDestinationTextLogsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextLogWithContext(ctx, mods...)
		m.WithDestinationTextLogs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextLogWithContext(ctx, mods...)
		m.AddDestinationTextLogs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingDestinationTextLogs(existingModels ...*models.CommsTextLog) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{
				o: o.f.FromExistingCommsTextLog(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutDestinationTextLogs() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.DestinationTextLogs = nil
	})
}

func (m commsPhoneMods) WithSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.SourceTextLogs = []*commsPhoneRSourceTextLogsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextLogWithContext(ctx, mods...)
		m.WithSourceTextLogs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewCommsTextLogWithContext(ctx, mods...)
		m.AddSourceTextLogs(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingSourceTextLogs(existingModels ...*models.CommsTextLog) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{
				o: o.f.FromExistingCommsTextLog(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutSourceTextLogs() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.SourceTextLogs = nil
	})
}

func (m commsPhoneMods) WithOrganizations(number int, related *OrganizationTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.Organizations = []*commsPhoneROrganizationsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewOrganizations(number int, mods ...OrganizationMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.WithOrganizations(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddOrganizations(number int, related *OrganizationTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.Organizations = append(o.r.Organizations, &commsPhoneROrganizationsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewOrganizations(number int, mods ...OrganizationMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.AddOrganizations(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingOrganizations(existingModels ...*models.Organization) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.Organizations = append(o.r.Organizations, &commsPhoneROrganizationsR{
				o: o.f.FromExistingOrganization(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutOrganizations() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.Organizations = nil
	})
}

func (m commsPhoneMods) WithPropertyOwnerPhoneE164Pools(number int, related *FileuploadPoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PropertyOwnerPhoneE164Pools = []*commsPhoneRPropertyOwnerPhoneE164PoolsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewPropertyOwnerPhoneE164Pools(number int, mods ...FileuploadPoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.WithPropertyOwnerPhoneE164Pools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddPropertyOwnerPhoneE164Pools(number int, related *FileuploadPoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PropertyOwnerPhoneE164Pools = append(o.r.PropertyOwnerPhoneE164Pools, &commsPhoneRPropertyOwnerPhoneE164PoolsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewPropertyOwnerPhoneE164Pools(number int, mods ...FileuploadPoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.AddPropertyOwnerPhoneE164Pools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingPropertyOwnerPhoneE164Pools(existingModels ...*models.FileuploadPool) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.PropertyOwnerPhoneE164Pools = append(o.r.PropertyOwnerPhoneE164Pools, &commsPhoneRPropertyOwnerPhoneE164PoolsR{
				o: o.f.FromExistingFileuploadPool(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutPropertyOwnerPhoneE164Pools() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PropertyOwnerPhoneE164Pools = nil
	})
}

func (m commsPhoneMods) WithResidentPhoneE164Pools(number int, related *FileuploadPoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.ResidentPhoneE164Pools = []*commsPhoneRResidentPhoneE164PoolsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewResidentPhoneE164Pools(number int, mods ...FileuploadPoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.WithResidentPhoneE164Pools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddResidentPhoneE164Pools(number int, related *FileuploadPoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.ResidentPhoneE164Pools = append(o.r.ResidentPhoneE164Pools, &commsPhoneRResidentPhoneE164PoolsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewResidentPhoneE164Pools(number int, mods ...FileuploadPoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewFileuploadPoolWithContext(ctx, mods...)
		m.AddResidentPhoneE164Pools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingResidentPhoneE164Pools(existingModels ...*models.FileuploadPool) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.ResidentPhoneE164Pools = append(o.r.ResidentPhoneE164Pools, &commsPhoneRResidentPhoneE164PoolsR{
				o: o.f.FromExistingFileuploadPool(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutResidentPhoneE164Pools() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.ResidentPhoneE164Pools = nil
	})
}

func (m commsPhoneMods) WithPhoneE164NotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhoneNuisances = []*commsPhoneRPhoneE164NotifyPhoneNuisancesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewPhoneE164NotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
		m.WithPhoneE164NotifyPhoneNuisances(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddPhoneE164NotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhoneNuisances = append(o.r.PhoneE164NotifyPhoneNuisances, &commsPhoneRPhoneE164NotifyPhoneNuisancesR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewPhoneE164NotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
		m.AddPhoneE164NotifyPhoneNuisances(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingPhoneE164NotifyPhoneNuisances(existingModels ...*models.PublicreportNotifyPhoneNuisance) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.PhoneE164NotifyPhoneNuisances = append(o.r.PhoneE164NotifyPhoneNuisances, &commsPhoneRPhoneE164NotifyPhoneNuisancesR{
				o: o.f.FromExistingPublicreportNotifyPhoneNuisance(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutPhoneE164NotifyPhoneNuisances() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhoneNuisances = nil
	})
}

func (m commsPhoneMods) WithPhoneE164NotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhonePools = []*commsPhoneRPhoneE164NotifyPhonePoolsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewPhoneE164NotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
		m.WithPhoneE164NotifyPhonePools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddPhoneE164NotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhonePools = append(o.r.PhoneE164NotifyPhonePools, &commsPhoneRPhoneE164NotifyPhonePoolsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewPhoneE164NotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
		m.AddPhoneE164NotifyPhonePools(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingPhoneE164NotifyPhonePools(existingModels ...*models.PublicreportNotifyPhonePool) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.PhoneE164NotifyPhonePools = append(o.r.PhoneE164NotifyPhonePools, &commsPhoneRPhoneE164NotifyPhonePoolsR{
				o: o.f.FromExistingPublicreportNotifyPhonePool(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutPhoneE164NotifyPhonePools() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164NotifyPhonePools = nil
	})
}

func (m commsPhoneMods) WithPhoneE164SubscribePhones(number int, related *PublicreportSubscribePhoneTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164SubscribePhones = []*commsPhoneRPhoneE164SubscribePhonesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewPhoneE164SubscribePhones(number int, mods ...PublicreportSubscribePhoneMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportSubscribePhoneWithContext(ctx, mods...)
		m.WithPhoneE164SubscribePhones(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddPhoneE164SubscribePhones(number int, related *PublicreportSubscribePhoneTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164SubscribePhones = append(o.r.PhoneE164SubscribePhones, &commsPhoneRPhoneE164SubscribePhonesR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewPhoneE164SubscribePhones(number int, mods ...PublicreportSubscribePhoneMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewPublicreportSubscribePhoneWithContext(ctx, mods...)
		m.AddPhoneE164SubscribePhones(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingPhoneE164SubscribePhones(existingModels ...*models.PublicreportSubscribePhone) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.PhoneE164SubscribePhones = append(o.r.PhoneE164SubscribePhones, &commsPhoneRPhoneE164SubscribePhonesR{
				o: o.f.FromExistingPublicreportSubscribePhone(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutPhoneE164SubscribePhones() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneE164SubscribePhones = nil
	})
}

func (m commsPhoneMods) WithPhoneMobileResidents(number int, related *ResidentTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneMobileResidents = []*commsPhoneRPhoneMobileResidentsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m commsPhoneMods) WithNewPhoneMobileResidents(number int, mods ...ResidentMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewResidentWithContext(ctx, mods...)
		m.WithPhoneMobileResidents(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddPhoneMobileResidents(number int, related *ResidentTemplate) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneMobileResidents = append(o.r.PhoneMobileResidents, &commsPhoneRPhoneMobileResidentsR{
			number: number,
			o:      related,
		})
	})
}

func (m commsPhoneMods) AddNewPhoneMobileResidents(number int, mods ...ResidentMod) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		related := o.f.NewResidentWithContext(ctx, mods...)
		m.AddPhoneMobileResidents(number, related).Apply(ctx, o)
	})
}

func (m commsPhoneMods) AddExistingPhoneMobileResidents(existingModels ...*models.Resident) CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		for _, em := range existingModels {
			o.r.PhoneMobileResidents = append(o.r.PhoneMobileResidents, &commsPhoneRPhoneMobileResidentsR{
				o: o.f.FromExistingResident(em),
			})
		}
	})
}

func (m commsPhoneMods) WithoutPhoneMobileResidents() CommsPhoneMod {
	return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
		o.r.PhoneMobileResidents = nil
	})
}
