// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package factory

import (
	"context"
	"testing"
	"time"

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

type FileuploadFileMod interface {
	Apply(context.Context, *FileuploadFileTemplate)
}

type FileuploadFileModFunc func(context.Context, *FileuploadFileTemplate)

func (f FileuploadFileModFunc) Apply(ctx context.Context, n *FileuploadFileTemplate) {
	f(ctx, n)
}

type FileuploadFileModSlice []FileuploadFileMod

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

// FileuploadFileTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type FileuploadFileTemplate struct {
	ID             func() int32
	ContentType    func() string
	Created        func() time.Time
	CreatorID      func() int32
	Deleted        func() null.Val[time.Time]
	Name           func() string
	OrganizationID func() int32
	Status         func() enums.FileuploadFilestatustype
	SizeBytes      func() int32
	FileUUID       func() uuid.UUID

	r fileuploadFileR
	f *Factory

	alreadyPersisted bool
}

type fileuploadFileR struct {
	CSV          *fileuploadFileRCSVR
	ErrorFiles   []*fileuploadFileRErrorFilesR
	CreatorUser  *fileuploadFileRCreatorUserR
	Organization *fileuploadFileROrganizationR
	Sites        []*fileuploadFileRSitesR
}

type fileuploadFileRCSVR struct {
	o *FileuploadCSVTemplate
}
type fileuploadFileRErrorFilesR struct {
	number int
	o      *FileuploadErrorFileTemplate
}
type fileuploadFileRCreatorUserR struct {
	o *UserTemplate
}
type fileuploadFileROrganizationR struct {
	o *OrganizationTemplate
}
type fileuploadFileRSitesR struct {
	number int
	o      *SiteTemplate
}

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

// setModelRels creates and sets the relationships on *models.FileuploadFile
// according to the relationships in the template. Nothing is inserted into the db
func (t FileuploadFileTemplate) setModelRels(o *models.FileuploadFile) {
	if t.r.CSV != nil {
		rel := t.r.CSV.o.Build()
		rel.R.File = o
		rel.FileID = o.ID // h2
		o.R.CSV = rel
	}

	if t.r.ErrorFiles != nil {
		rel := models.FileuploadErrorFileSlice{}
		for _, r := range t.r.ErrorFiles {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.FileID = o.ID // h2
				rel.R.File = o
			}
			rel = append(rel, related...)
		}
		o.R.ErrorFiles = rel
	}

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

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

	if t.r.Sites != nil {
		rel := models.SiteSlice{}
		for _, r := range t.r.Sites {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.FileID = null.From(o.ID) // h2
				rel.R.File = o
			}
			rel = append(rel, related...)
		}
		o.R.Sites = rel
	}
}

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

	if o.ID != nil {
		val := o.ID()
		m.ID = omit.From(val)
	}
	if o.ContentType != nil {
		val := o.ContentType()
		m.ContentType = omit.From(val)
	}
	if o.Created != nil {
		val := o.Created()
		m.Created = omit.From(val)
	}
	if o.CreatorID != nil {
		val := o.CreatorID()
		m.CreatorID = omit.From(val)
	}
	if o.Deleted != nil {
		val := o.Deleted()
		m.Deleted = omitnull.FromNull(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.Status != nil {
		val := o.Status()
		m.Status = omit.From(val)
	}
	if o.SizeBytes != nil {
		val := o.SizeBytes()
		m.SizeBytes = omit.From(val)
	}
	if o.FileUUID != nil {
		val := o.FileUUID()
		m.FileUUID = omit.From(val)
	}

	return m
}

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

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

	return m
}

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

	if o.ID != nil {
		m.ID = o.ID()
	}
	if o.ContentType != nil {
		m.ContentType = o.ContentType()
	}
	if o.Created != nil {
		m.Created = o.Created()
	}
	if o.CreatorID != nil {
		m.CreatorID = o.CreatorID()
	}
	if o.Deleted != nil {
		m.Deleted = o.Deleted()
	}
	if o.Name != nil {
		m.Name = o.Name()
	}
	if o.OrganizationID != nil {
		m.OrganizationID = o.OrganizationID()
	}
	if o.Status != nil {
		m.Status = o.Status()
	}
	if o.SizeBytes != nil {
		m.SizeBytes = o.SizeBytes()
	}
	if o.FileUUID != nil {
		m.FileUUID = o.FileUUID()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableFileuploadFile(m *models.FileuploadFileSetter) {
	if !(m.ContentType.IsValue()) {
		val := random_string(nil)
		m.ContentType = omit.From(val)
	}
	if !(m.Created.IsValue()) {
		val := random_time_Time(nil)
		m.Created = omit.From(val)
	}
	if !(m.CreatorID.IsValue()) {
		val := random_int32(nil)
		m.CreatorID = 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)
	}
	if !(m.Status.IsValue()) {
		val := random_enums_FileuploadFilestatustype(nil)
		m.Status = omit.From(val)
	}
	if !(m.SizeBytes.IsValue()) {
		val := random_int32(nil)
		m.SizeBytes = omit.From(val)
	}
	if !(m.FileUUID.IsValue()) {
		val := random_uuid_UUID(nil)
		m.FileUUID = omit.From(val)
	}
}

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

	isCSVDone, _ := fileuploadFileRelCSVCtx.Value(ctx)
	if !isCSVDone && o.r.CSV != nil {
		ctx = fileuploadFileRelCSVCtx.WithValue(ctx, true)
		if o.r.CSV.o.alreadyPersisted {
			m.R.CSV = o.r.CSV.o.Build()
		} else {
			var rel0 *models.FileuploadCSV
			rel0, err = o.r.CSV.o.Create(ctx, exec)
			if err != nil {
				return err
			}
			err = m.AttachCSV(ctx, exec, rel0)
			if err != nil {
				return err
			}
		}

	}

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

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

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

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

	return err
}

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

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

	var rel2 *models.User

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

	opt.CreatorID = omit.From(rel2.ID)

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

	var rel3 *models.Organization

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

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

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

	m.R.CreatorUser = rel2
	m.R.Organization = rel3

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

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

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

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

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

	return m, nil
}

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

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

// FileuploadFile has methods that act as mods for the FileuploadFileTemplate
var FileuploadFileMods fileuploadFileMods

type fileuploadFileMods struct{}

func (m fileuploadFileMods) RandomizeAllColumns(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModSlice{
		FileuploadFileMods.RandomID(f),
		FileuploadFileMods.RandomContentType(f),
		FileuploadFileMods.RandomCreated(f),
		FileuploadFileMods.RandomCreatorID(f),
		FileuploadFileMods.RandomDeleted(f),
		FileuploadFileMods.RandomName(f),
		FileuploadFileMods.RandomOrganizationID(f),
		FileuploadFileMods.RandomStatus(f),
		FileuploadFileMods.RandomSizeBytes(f),
		FileuploadFileMods.RandomFileUUID(f),
	}
}

// Set the model columns to this value
func (m fileuploadFileMods) ID(val int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) IDFunc(f func() int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ID = f
	})
}

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

// Set the model columns to this value
func (m fileuploadFileMods) ContentType(val string) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ContentType = func() string { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) ContentTypeFunc(f func() string) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ContentType = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetContentType() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ContentType = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m fileuploadFileMods) RandomContentType(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.ContentType = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m fileuploadFileMods) Created(val time.Time) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Created = func() time.Time { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) CreatedFunc(f func() time.Time) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Created = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetCreated() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		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 fileuploadFileMods) RandomCreated(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Created = func() time.Time {
			return random_time_Time(f)
		}
	})
}

// Set the model columns to this value
func (m fileuploadFileMods) CreatorID(val int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.CreatorID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) CreatorIDFunc(f func() int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.CreatorID = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetCreatorID() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.CreatorID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m fileuploadFileMods) RandomCreatorID(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.CreatorID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m fileuploadFileMods) Deleted(val null.Val[time.Time]) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Deleted = func() null.Val[time.Time] { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) DeletedFunc(f func() null.Val[time.Time]) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Deleted = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetDeleted() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Deleted = 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 fileuploadFileMods) RandomDeleted(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Deleted = func() null.Val[time.Time] {
			if f == nil {
				f = &defaultFaker
			}

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

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m fileuploadFileMods) RandomDeletedNotNull(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Deleted = func() null.Val[time.Time] {
			if f == nil {
				f = &defaultFaker
			}

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

// Set the model columns to this value
func (m fileuploadFileMods) Name(val string) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Name = func() string { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) NameFunc(f func() string) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Name = f
	})
}

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

// Set the model columns to this value
func (m fileuploadFileMods) OrganizationID(val int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.OrganizationID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) OrganizationIDFunc(f func() int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.OrganizationID = f
	})
}

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

// Set the model columns to this value
func (m fileuploadFileMods) Status(val enums.FileuploadFilestatustype) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Status = func() enums.FileuploadFilestatustype { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) StatusFunc(f func() enums.FileuploadFilestatustype) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Status = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetStatus() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		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 fileuploadFileMods) RandomStatus(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.Status = func() enums.FileuploadFilestatustype {
			return random_enums_FileuploadFilestatustype(f)
		}
	})
}

// Set the model columns to this value
func (m fileuploadFileMods) SizeBytes(val int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.SizeBytes = func() int32 { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) SizeBytesFunc(f func() int32) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.SizeBytes = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetSizeBytes() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.SizeBytes = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m fileuploadFileMods) RandomSizeBytes(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.SizeBytes = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m fileuploadFileMods) FileUUID(val uuid.UUID) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.FileUUID = func() uuid.UUID { return val }
	})
}

// Set the Column from the function
func (m fileuploadFileMods) FileUUIDFunc(f func() uuid.UUID) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.FileUUID = f
	})
}

// Clear any values for the column
func (m fileuploadFileMods) UnsetFileUUID() FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.FileUUID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m fileuploadFileMods) RandomFileUUID(f *faker.Faker) FileuploadFileMod {
	return FileuploadFileModFunc(func(_ context.Context, o *FileuploadFileTemplate) {
		o.FileUUID = func() uuid.UUID {
			return random_uuid_UUID(f)
		}
	})
}

func (m fileuploadFileMods) WithParentsCascading() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		if isDone, _ := fileuploadFileWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = fileuploadFileWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewFileuploadCSVWithContext(ctx, FileuploadCSVMods.WithParentsCascading())
			m.WithCSV(related).Apply(ctx, o)
		}
		{

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

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

func (m fileuploadFileMods) WithCSV(rel *FileuploadCSVTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CSV = &fileuploadFileRCSVR{
			o: rel,
		}
	})
}

func (m fileuploadFileMods) WithNewCSV(mods ...FileuploadCSVMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewFileuploadCSVWithContext(ctx, mods...)

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

func (m fileuploadFileMods) WithExistingCSV(em *models.FileuploadCSV) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CSV = &fileuploadFileRCSVR{
			o: o.f.FromExistingFileuploadCSV(em),
		}
	})
}

func (m fileuploadFileMods) WithoutCSV() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CSV = nil
	})
}

func (m fileuploadFileMods) WithCreatorUser(rel *UserTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CreatorUser = &fileuploadFileRCreatorUserR{
			o: rel,
		}
	})
}

func (m fileuploadFileMods) WithNewCreatorUser(mods ...UserMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewUserWithContext(ctx, mods...)

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

func (m fileuploadFileMods) WithExistingCreatorUser(em *models.User) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CreatorUser = &fileuploadFileRCreatorUserR{
			o: o.f.FromExistingUser(em),
		}
	})
}

func (m fileuploadFileMods) WithoutCreatorUser() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.CreatorUser = nil
	})
}

func (m fileuploadFileMods) WithOrganization(rel *OrganizationTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Organization = &fileuploadFileROrganizationR{
			o: rel,
		}
	})
}

func (m fileuploadFileMods) WithNewOrganization(mods ...OrganizationMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)

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

func (m fileuploadFileMods) WithExistingOrganization(em *models.Organization) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Organization = &fileuploadFileROrganizationR{
			o: o.f.FromExistingOrganization(em),
		}
	})
}

func (m fileuploadFileMods) WithoutOrganization() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Organization = nil
	})
}

func (m fileuploadFileMods) WithErrorFiles(number int, related *FileuploadErrorFileTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.ErrorFiles = []*fileuploadFileRErrorFilesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m fileuploadFileMods) WithNewErrorFiles(number int, mods ...FileuploadErrorFileMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewFileuploadErrorFileWithContext(ctx, mods...)
		m.WithErrorFiles(number, related).Apply(ctx, o)
	})
}

func (m fileuploadFileMods) AddErrorFiles(number int, related *FileuploadErrorFileTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.ErrorFiles = append(o.r.ErrorFiles, &fileuploadFileRErrorFilesR{
			number: number,
			o:      related,
		})
	})
}

func (m fileuploadFileMods) AddNewErrorFiles(number int, mods ...FileuploadErrorFileMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewFileuploadErrorFileWithContext(ctx, mods...)
		m.AddErrorFiles(number, related).Apply(ctx, o)
	})
}

func (m fileuploadFileMods) AddExistingErrorFiles(existingModels ...*models.FileuploadErrorFile) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		for _, em := range existingModels {
			o.r.ErrorFiles = append(o.r.ErrorFiles, &fileuploadFileRErrorFilesR{
				o: o.f.FromExistingFileuploadErrorFile(em),
			})
		}
	})
}

func (m fileuploadFileMods) WithoutErrorFiles() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.ErrorFiles = nil
	})
}

func (m fileuploadFileMods) WithSites(number int, related *SiteTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Sites = []*fileuploadFileRSitesR{{
			number: number,
			o:      related,
		}}
	})
}

func (m fileuploadFileMods) WithNewSites(number int, mods ...SiteMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewSiteWithContext(ctx, mods...)
		m.WithSites(number, related).Apply(ctx, o)
	})
}

func (m fileuploadFileMods) AddSites(number int, related *SiteTemplate) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Sites = append(o.r.Sites, &fileuploadFileRSitesR{
			number: number,
			o:      related,
		})
	})
}

func (m fileuploadFileMods) AddNewSites(number int, mods ...SiteMod) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		related := o.f.NewSiteWithContext(ctx, mods...)
		m.AddSites(number, related).Apply(ctx, o)
	})
}

func (m fileuploadFileMods) AddExistingSites(existingModels ...*models.Site) FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		for _, em := range existingModels {
			o.r.Sites = append(o.r.Sites, &fileuploadFileRSitesR{
				o: o.f.FromExistingSite(em),
			})
		}
	})
}

func (m fileuploadFileMods) WithoutSites() FileuploadFileMod {
	return FileuploadFileModFunc(func(ctx context.Context, o *FileuploadFileTemplate) {
		o.r.Sites = nil
	})
}
