// 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/omit"
	"github.com/google/uuid"
	"github.com/jaswdr/faker/v2"
)

type NoteImageBreadcrumbMod interface {
	Apply(context.Context, *NoteImageBreadcrumbTemplate)
}

type NoteImageBreadcrumbModFunc func(context.Context, *NoteImageBreadcrumbTemplate)

func (f NoteImageBreadcrumbModFunc) Apply(ctx context.Context, n *NoteImageBreadcrumbTemplate) {
	f(ctx, n)
}

type NoteImageBreadcrumbModSlice []NoteImageBreadcrumbMod

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

// NoteImageBreadcrumbTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type NoteImageBreadcrumbTemplate struct {
	Cell             func() string
	Created          func() time.Time
	ManuallySelected func() bool
	NoteImageVersion func() int32
	NoteImageUUID    func() uuid.UUID
	Position         func() int32

	r noteImageBreadcrumbR
	f *Factory

	alreadyPersisted bool
}

type noteImageBreadcrumbR struct {
	NoteImage *noteImageBreadcrumbRNoteImageR
}

type noteImageBreadcrumbRNoteImageR struct {
	o *NoteImageTemplate
}

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

// setModelRels creates and sets the relationships on *models.NoteImageBreadcrumb
// according to the relationships in the template. Nothing is inserted into the db
func (t NoteImageBreadcrumbTemplate) setModelRels(o *models.NoteImageBreadcrumb) {
	if t.r.NoteImage != nil {
		rel := t.r.NoteImage.o.Build()
		rel.R.NoteImageBreadcrumbs = append(rel.R.NoteImageBreadcrumbs, o)
		o.NoteImageVersion = rel.Version // h2
		o.NoteImageUUID = rel.UUID       // h2
		o.R.NoteImage = rel
	}
}

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

	if o.Cell != nil {
		val := o.Cell()
		m.Cell = omit.From(val)
	}
	if o.Created != nil {
		val := o.Created()
		m.Created = omit.From(val)
	}
	if o.ManuallySelected != nil {
		val := o.ManuallySelected()
		m.ManuallySelected = omit.From(val)
	}
	if o.NoteImageVersion != nil {
		val := o.NoteImageVersion()
		m.NoteImageVersion = omit.From(val)
	}
	if o.NoteImageUUID != nil {
		val := o.NoteImageUUID()
		m.NoteImageUUID = omit.From(val)
	}
	if o.Position != nil {
		val := o.Position()
		m.Position = omit.From(val)
	}

	return m
}

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

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

	return m
}

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

	if o.Cell != nil {
		m.Cell = o.Cell()
	}
	if o.Created != nil {
		m.Created = o.Created()
	}
	if o.ManuallySelected != nil {
		m.ManuallySelected = o.ManuallySelected()
	}
	if o.NoteImageVersion != nil {
		m.NoteImageVersion = o.NoteImageVersion()
	}
	if o.NoteImageUUID != nil {
		m.NoteImageUUID = o.NoteImageUUID()
	}
	if o.Position != nil {
		m.Position = o.Position()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableNoteImageBreadcrumb(m *models.NoteImageBreadcrumbSetter) {
	if !(m.Cell.IsValue()) {
		val := random_string(nil)
		m.Cell = omit.From(val)
	}
	if !(m.Created.IsValue()) {
		val := random_time_Time(nil)
		m.Created = omit.From(val)
	}
	if !(m.ManuallySelected.IsValue()) {
		val := random_bool(nil)
		m.ManuallySelected = omit.From(val)
	}
	if !(m.NoteImageVersion.IsValue()) {
		val := random_int32(nil)
		m.NoteImageVersion = omit.From(val)
	}
	if !(m.NoteImageUUID.IsValue()) {
		val := random_uuid_UUID(nil)
		m.NoteImageUUID = omit.From(val)
	}
	if !(m.Position.IsValue()) {
		val := random_int32(nil)
		m.Position = omit.From(val)
	}
}

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

	return err
}

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

	if o.r.NoteImage == nil {
		NoteImageBreadcrumbMods.WithNewNoteImage().Apply(ctx, o)
	}

	var rel0 *models.NoteImage

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

	opt.NoteImageVersion = omit.From(rel0.Version)
	opt.NoteImageUUID = omit.From(rel0.UUID)

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

	m.R.NoteImage = rel0

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

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

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

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

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

	return m, nil
}

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

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

// NoteImageBreadcrumb has methods that act as mods for the NoteImageBreadcrumbTemplate
var NoteImageBreadcrumbMods noteImageBreadcrumbMods

type noteImageBreadcrumbMods struct{}

func (m noteImageBreadcrumbMods) RandomizeAllColumns(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModSlice{
		NoteImageBreadcrumbMods.RandomCell(f),
		NoteImageBreadcrumbMods.RandomCreated(f),
		NoteImageBreadcrumbMods.RandomManuallySelected(f),
		NoteImageBreadcrumbMods.RandomNoteImageVersion(f),
		NoteImageBreadcrumbMods.RandomNoteImageUUID(f),
		NoteImageBreadcrumbMods.RandomPosition(f),
	}
}

// Set the model columns to this value
func (m noteImageBreadcrumbMods) Cell(val string) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Cell = func() string { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) CellFunc(f func() string) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Cell = f
	})
}

// Clear any values for the column
func (m noteImageBreadcrumbMods) UnsetCell() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Cell = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m noteImageBreadcrumbMods) RandomCell(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Cell = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m noteImageBreadcrumbMods) Created(val time.Time) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Created = func() time.Time { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) CreatedFunc(f func() time.Time) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Created = f
	})
}

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

// Set the model columns to this value
func (m noteImageBreadcrumbMods) ManuallySelected(val bool) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.ManuallySelected = func() bool { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) ManuallySelectedFunc(f func() bool) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.ManuallySelected = f
	})
}

// Clear any values for the column
func (m noteImageBreadcrumbMods) UnsetManuallySelected() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.ManuallySelected = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m noteImageBreadcrumbMods) RandomManuallySelected(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.ManuallySelected = func() bool {
			return random_bool(f)
		}
	})
}

// Set the model columns to this value
func (m noteImageBreadcrumbMods) NoteImageVersion(val int32) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageVersion = func() int32 { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) NoteImageVersionFunc(f func() int32) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageVersion = f
	})
}

// Clear any values for the column
func (m noteImageBreadcrumbMods) UnsetNoteImageVersion() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageVersion = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m noteImageBreadcrumbMods) RandomNoteImageVersion(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageVersion = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m noteImageBreadcrumbMods) NoteImageUUID(val uuid.UUID) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageUUID = func() uuid.UUID { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) NoteImageUUIDFunc(f func() uuid.UUID) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageUUID = f
	})
}

// Clear any values for the column
func (m noteImageBreadcrumbMods) UnsetNoteImageUUID() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageUUID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m noteImageBreadcrumbMods) RandomNoteImageUUID(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.NoteImageUUID = func() uuid.UUID {
			return random_uuid_UUID(f)
		}
	})
}

// Set the model columns to this value
func (m noteImageBreadcrumbMods) Position(val int32) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Position = func() int32 { return val }
	})
}

// Set the Column from the function
func (m noteImageBreadcrumbMods) PositionFunc(f func() int32) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Position = f
	})
}

// Clear any values for the column
func (m noteImageBreadcrumbMods) UnsetPosition() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Position = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m noteImageBreadcrumbMods) RandomPosition(f *faker.Faker) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(_ context.Context, o *NoteImageBreadcrumbTemplate) {
		o.Position = func() int32 {
			return random_int32(f)
		}
	})
}

func (m noteImageBreadcrumbMods) WithParentsCascading() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(ctx context.Context, o *NoteImageBreadcrumbTemplate) {
		if isDone, _ := noteImageBreadcrumbWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = noteImageBreadcrumbWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewNoteImageWithContext(ctx, NoteImageMods.WithParentsCascading())
			m.WithNoteImage(related).Apply(ctx, o)
		}
	})
}

func (m noteImageBreadcrumbMods) WithNoteImage(rel *NoteImageTemplate) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(ctx context.Context, o *NoteImageBreadcrumbTemplate) {
		o.r.NoteImage = &noteImageBreadcrumbRNoteImageR{
			o: rel,
		}
	})
}

func (m noteImageBreadcrumbMods) WithNewNoteImage(mods ...NoteImageMod) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(ctx context.Context, o *NoteImageBreadcrumbTemplate) {
		related := o.f.NewNoteImageWithContext(ctx, mods...)

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

func (m noteImageBreadcrumbMods) WithExistingNoteImage(em *models.NoteImage) NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(ctx context.Context, o *NoteImageBreadcrumbTemplate) {
		o.r.NoteImage = &noteImageBreadcrumbRNoteImageR{
			o: o.f.FromExistingNoteImage(em),
		}
	})
}

func (m noteImageBreadcrumbMods) WithoutNoteImage() NoteImageBreadcrumbMod {
	return NoteImageBreadcrumbModFunc(func(ctx context.Context, o *NoteImageBreadcrumbTemplate) {
		o.r.NoteImage = nil
	})
}
