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

type GooseDBVersionMod interface {
	Apply(context.Context, *GooseDBVersionTemplate)
}

type GooseDBVersionModFunc func(context.Context, *GooseDBVersionTemplate)

func (f GooseDBVersionModFunc) Apply(ctx context.Context, n *GooseDBVersionTemplate) {
	f(ctx, n)
}

type GooseDBVersionModSlice []GooseDBVersionMod

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

// GooseDBVersionTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type GooseDBVersionTemplate struct {
	ID        func() int32
	VersionID func() int64
	IsApplied func() bool
	Tstamp    func() time.Time

	f *Factory

	alreadyPersisted bool
}

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

// setModelRels creates and sets the relationships on *models.GooseDBVersion
// according to the relationships in the template. Nothing is inserted into the db
func (t GooseDBVersionTemplate) setModelRels(o *models.GooseDBVersion) {}

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

	if o.ID != nil {
		val := o.ID()
		m.ID = omit.From(val)
	}
	if o.VersionID != nil {
		val := o.VersionID()
		m.VersionID = omit.From(val)
	}
	if o.IsApplied != nil {
		val := o.IsApplied()
		m.IsApplied = omit.From(val)
	}
	if o.Tstamp != nil {
		val := o.Tstamp()
		m.Tstamp = omit.From(val)
	}

	return m
}

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

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

	return m
}

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

	if o.ID != nil {
		m.ID = o.ID()
	}
	if o.VersionID != nil {
		m.VersionID = o.VersionID()
	}
	if o.IsApplied != nil {
		m.IsApplied = o.IsApplied()
	}
	if o.Tstamp != nil {
		m.Tstamp = o.Tstamp()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableGooseDBVersion(m *models.GooseDBVersionSetter) {
	if !(m.VersionID.IsValue()) {
		val := random_int64(nil)
		m.VersionID = omit.From(val)
	}
	if !(m.IsApplied.IsValue()) {
		val := random_bool(nil)
		m.IsApplied = omit.From(val)
	}
}

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

	return err
}

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

	m, err := models.GooseDBVersions.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 gooseDBVersion and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *GooseDBVersionTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.GooseDBVersion {
	m, err := o.Create(ctx, exec)
	if err != nil {
		panic(err)
	}
	return m
}

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

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

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

	return m, nil
}

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

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

// GooseDBVersion has methods that act as mods for the GooseDBVersionTemplate
var GooseDBVersionMods gooseDBVersionMods

type gooseDBVersionMods struct{}

func (m gooseDBVersionMods) RandomizeAllColumns(f *faker.Faker) GooseDBVersionMod {
	return GooseDBVersionModSlice{
		GooseDBVersionMods.RandomID(f),
		GooseDBVersionMods.RandomVersionID(f),
		GooseDBVersionMods.RandomIsApplied(f),
		GooseDBVersionMods.RandomTstamp(f),
	}
}

// Set the model columns to this value
func (m gooseDBVersionMods) ID(val int32) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.ID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m gooseDBVersionMods) IDFunc(f func() int32) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.ID = f
	})
}

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

// Set the model columns to this value
func (m gooseDBVersionMods) VersionID(val int64) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.VersionID = func() int64 { return val }
	})
}

// Set the Column from the function
func (m gooseDBVersionMods) VersionIDFunc(f func() int64) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.VersionID = f
	})
}

// Clear any values for the column
func (m gooseDBVersionMods) UnsetVersionID() GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.VersionID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m gooseDBVersionMods) RandomVersionID(f *faker.Faker) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.VersionID = func() int64 {
			return random_int64(f)
		}
	})
}

// Set the model columns to this value
func (m gooseDBVersionMods) IsApplied(val bool) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.IsApplied = func() bool { return val }
	})
}

// Set the Column from the function
func (m gooseDBVersionMods) IsAppliedFunc(f func() bool) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.IsApplied = f
	})
}

// Clear any values for the column
func (m gooseDBVersionMods) UnsetIsApplied() GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.IsApplied = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m gooseDBVersionMods) RandomIsApplied(f *faker.Faker) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.IsApplied = func() bool {
			return random_bool(f)
		}
	})
}

// Set the model columns to this value
func (m gooseDBVersionMods) Tstamp(val time.Time) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.Tstamp = func() time.Time { return val }
	})
}

// Set the Column from the function
func (m gooseDBVersionMods) TstampFunc(f func() time.Time) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.Tstamp = f
	})
}

// Clear any values for the column
func (m gooseDBVersionMods) UnsetTstamp() GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.Tstamp = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m gooseDBVersionMods) RandomTstamp(f *faker.Faker) GooseDBVersionMod {
	return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
		o.Tstamp = func() time.Time {
			return random_time_Time(f)
		}
	})
}

func (m gooseDBVersionMods) WithParentsCascading() GooseDBVersionMod {
	return GooseDBVersionModFunc(func(ctx context.Context, o *GooseDBVersionTemplate) {
		if isDone, _ := gooseDBVersionWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = gooseDBVersionWithParentsCascadingCtx.WithValue(ctx, true)
	})
}
