// 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"

	models "github.com/Gleipnir-Technology/nidus-sync/db/models"
	"github.com/jaswdr/faker/v2"
)

type ComplianceReportRequestMailerMod interface {
	Apply(context.Context, *ComplianceReportRequestMailerTemplate)
}

type ComplianceReportRequestMailerModFunc func(context.Context, *ComplianceReportRequestMailerTemplate)

func (f ComplianceReportRequestMailerModFunc) Apply(ctx context.Context, n *ComplianceReportRequestMailerTemplate) {
	f(ctx, n)
}

type ComplianceReportRequestMailerModSlice []ComplianceReportRequestMailerMod

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

// ComplianceReportRequestMailerTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ComplianceReportRequestMailerTemplate struct {
	ComplianceReportRequestID func() int32
	MailerID                  func() int32

	r complianceReportRequestMailerR
	f *Factory

	alreadyPersisted bool
}

type complianceReportRequestMailerR struct {
	ComplianceReportRequest *complianceReportRequestMailerRComplianceReportRequestR
	Mailer                  *complianceReportRequestMailerRMailerR
}

type complianceReportRequestMailerRComplianceReportRequestR struct {
	o *ComplianceReportRequestTemplate
}
type complianceReportRequestMailerRMailerR struct {
	o *CommsMailerTemplate
}

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

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

	if t.r.Mailer != nil {
		rel := t.r.Mailer.o.Build()
		o.MailerID = rel.ID // h2
		o.R.Mailer = rel
	}
}

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

	if o.ComplianceReportRequestID != nil {
		m.ComplianceReportRequestID = o.ComplianceReportRequestID()
	}
	if o.MailerID != nil {
		m.MailerID = o.MailerID()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

// ComplianceReportRequestMailer has methods that act as mods for the ComplianceReportRequestMailerTemplate
var ComplianceReportRequestMailerMods complianceReportRequestMailerMods

type complianceReportRequestMailerMods struct{}

func (m complianceReportRequestMailerMods) RandomizeAllColumns(f *faker.Faker) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModSlice{
		ComplianceReportRequestMailerMods.RandomComplianceReportRequestID(f),
		ComplianceReportRequestMailerMods.RandomMailerID(f),
	}
}

// Set the model columns to this value
func (m complianceReportRequestMailerMods) ComplianceReportRequestID(val int32) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.ComplianceReportRequestID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m complianceReportRequestMailerMods) ComplianceReportRequestIDFunc(f func() int32) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.ComplianceReportRequestID = f
	})
}

// Clear any values for the column
func (m complianceReportRequestMailerMods) UnsetComplianceReportRequestID() ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.ComplianceReportRequestID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMailerMods) RandomComplianceReportRequestID(f *faker.Faker) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.ComplianceReportRequestID = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m complianceReportRequestMailerMods) MailerID(val int32) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.MailerID = func() int32 { return val }
	})
}

// Set the Column from the function
func (m complianceReportRequestMailerMods) MailerIDFunc(f func() int32) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.MailerID = f
	})
}

// Clear any values for the column
func (m complianceReportRequestMailerMods) UnsetMailerID() ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.MailerID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m complianceReportRequestMailerMods) RandomMailerID(f *faker.Faker) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(_ context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.MailerID = func() int32 {
			return random_int32(f)
		}
	})
}

func (m complianceReportRequestMailerMods) WithParentsCascading() ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		if isDone, _ := complianceReportRequestMailerWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = complianceReportRequestMailerWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewComplianceReportRequestWithContext(ctx, ComplianceReportRequestMods.WithParentsCascading())
			m.WithComplianceReportRequest(related).Apply(ctx, o)
		}
		{

			related := o.f.NewCommsMailerWithContext(ctx, CommsMailerMods.WithParentsCascading())
			m.WithMailer(related).Apply(ctx, o)
		}
	})
}

func (m complianceReportRequestMailerMods) WithComplianceReportRequest(rel *ComplianceReportRequestTemplate) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.ComplianceReportRequest = &complianceReportRequestMailerRComplianceReportRequestR{
			o: rel,
		}
	})
}

func (m complianceReportRequestMailerMods) WithNewComplianceReportRequest(mods ...ComplianceReportRequestMod) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)

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

func (m complianceReportRequestMailerMods) WithExistingComplianceReportRequest(em *models.ComplianceReportRequest) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.ComplianceReportRequest = &complianceReportRequestMailerRComplianceReportRequestR{
			o: o.f.FromExistingComplianceReportRequest(em),
		}
	})
}

func (m complianceReportRequestMailerMods) WithoutComplianceReportRequest() ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.ComplianceReportRequest = nil
	})
}

func (m complianceReportRequestMailerMods) WithMailer(rel *CommsMailerTemplate) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.Mailer = &complianceReportRequestMailerRMailerR{
			o: rel,
		}
	})
}

func (m complianceReportRequestMailerMods) WithNewMailer(mods ...CommsMailerMod) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		related := o.f.NewCommsMailerWithContext(ctx, mods...)

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

func (m complianceReportRequestMailerMods) WithExistingMailer(em *models.CommsMailer) ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.Mailer = &complianceReportRequestMailerRMailerR{
			o: o.f.FromExistingCommsMailer(em),
		}
	})
}

func (m complianceReportRequestMailerMods) WithoutMailer() ComplianceReportRequestMailerMod {
	return ComplianceReportRequestMailerModFunc(func(ctx context.Context, o *ComplianceReportRequestMailerTemplate) {
		o.r.Mailer = nil
	})
}
