nidus-sync/db/factory/comms.email_log.bob.go
Eli Ribble f4a88623af
Overhaul system for handling text messaging
Move away from "SMS" as the operative word - we're going RCS.
Move all comms processing to a separate goroutine
Rename the DB tables
2026-01-21 03:30:03 +00:00

523 lines
15 KiB
Go

// Code generated by BobGen psql v0.42.1. 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"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type CommsEmailLogMod interface {
Apply(context.Context, *CommsEmailLogTemplate)
}
type CommsEmailLogModFunc func(context.Context, *CommsEmailLogTemplate)
func (f CommsEmailLogModFunc) Apply(ctx context.Context, n *CommsEmailLogTemplate) {
f(ctx, n)
}
type CommsEmailLogModSlice []CommsEmailLogMod
func (mods CommsEmailLogModSlice) Apply(ctx context.Context, n *CommsEmailLogTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsEmailLogTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsEmailLogTemplate struct {
Created func() time.Time
Destination func() string
Source func() string
Type func() enums.CommsMessagetypeemail
r commsEmailLogR
f *Factory
alreadyPersisted bool
}
type commsEmailLogR struct {
DestinationEmail *commsEmailLogRDestinationEmailR
SourcePhone *commsEmailLogRSourcePhoneR
}
type commsEmailLogRDestinationEmailR struct {
o *CommsEmailTemplate
}
type commsEmailLogRSourcePhoneR struct {
o *CommsPhoneTemplate
}
// Apply mods to the CommsEmailLogTemplate
func (o *CommsEmailLogTemplate) Apply(ctx context.Context, mods ...CommsEmailLogMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsEmailLog
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsEmailLogTemplate) setModelRels(o *models.CommsEmailLog) {
if t.r.DestinationEmail != nil {
rel := t.r.DestinationEmail.o.Build()
rel.R.DestinationEmailLogs = append(rel.R.DestinationEmailLogs, o)
o.Destination = rel.Address // h2
o.R.DestinationEmail = rel
}
if t.r.SourcePhone != nil {
rel := t.r.SourcePhone.o.Build()
rel.R.SourceEmailLogs = append(rel.R.SourceEmailLogs, o)
o.Source = rel.E164 // h2
o.R.SourcePhone = rel
}
}
// BuildSetter returns an *models.CommsEmailLogSetter
// this does nothing with the relationship templates
func (o CommsEmailLogTemplate) BuildSetter() *models.CommsEmailLogSetter {
m := &models.CommsEmailLogSetter{}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Destination != nil {
val := o.Destination()
m.Destination = omit.From(val)
}
if o.Source != nil {
val := o.Source()
m.Source = omit.From(val)
}
if o.Type != nil {
val := o.Type()
m.Type = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsEmailLogSetter
// this does nothing with the relationship templates
func (o CommsEmailLogTemplate) BuildManySetter(number int) []*models.CommsEmailLogSetter {
m := make([]*models.CommsEmailLogSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsEmailLog
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailLogTemplate.Create
func (o CommsEmailLogTemplate) Build() *models.CommsEmailLog {
m := &models.CommsEmailLog{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Destination != nil {
m.Destination = o.Destination()
}
if o.Source != nil {
m.Source = o.Source()
}
if o.Type != nil {
m.Type = o.Type()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsEmailLogSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailLogTemplate.CreateMany
func (o CommsEmailLogTemplate) BuildMany(number int) models.CommsEmailLogSlice {
m := make(models.CommsEmailLogSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsEmailLog(m *models.CommsEmailLogSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Destination.IsValue()) {
val := random_string(nil)
m.Destination = omit.From(val)
}
if !(m.Source.IsValue()) {
val := random_string(nil)
m.Source = omit.From(val)
}
if !(m.Type.IsValue()) {
val := random_enums_CommsMessagetypeemail(nil)
m.Type = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsEmailLog
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsEmailLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsEmailLog) error {
var err error
return err
}
// Create builds a commsEmailLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsEmailLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsEmailLog, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsEmailLog(opt)
if o.r.DestinationEmail == nil {
CommsEmailLogMods.WithNewDestinationEmail().Apply(ctx, o)
}
var rel0 *models.CommsEmail
if o.r.DestinationEmail.o.alreadyPersisted {
rel0 = o.r.DestinationEmail.o.Build()
} else {
rel0, err = o.r.DestinationEmail.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Destination = omit.From(rel0.Address)
if o.r.SourcePhone == nil {
CommsEmailLogMods.WithNewSourcePhone().Apply(ctx, o)
}
var rel1 *models.CommsPhone
if o.r.SourcePhone.o.alreadyPersisted {
rel1 = o.r.SourcePhone.o.Build()
} else {
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Source = omit.From(rel1.E164)
m, err := models.CommsEmailLogs.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.DestinationEmail = rel0
m.R.SourcePhone = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a commsEmailLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsEmailLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsEmailLog {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsEmailLog 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 *CommsEmailLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsEmailLog {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsEmailLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsEmailLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsEmailLogSlice, error) {
var err error
m := make(models.CommsEmailLogSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsEmailLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsEmailLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsEmailLogSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsEmailLogs 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 CommsEmailLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsEmailLogSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsEmailLog has methods that act as mods for the CommsEmailLogTemplate
var CommsEmailLogMods commsEmailLogMods
type commsEmailLogMods struct{}
func (m commsEmailLogMods) RandomizeAllColumns(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModSlice{
CommsEmailLogMods.RandomCreated(f),
CommsEmailLogMods.RandomDestination(f),
CommsEmailLogMods.RandomSource(f),
CommsEmailLogMods.RandomType(f),
}
}
// Set the model columns to this value
func (m commsEmailLogMods) Created(val time.Time) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) CreatedFunc(f func() time.Time) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetCreated() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
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 commsEmailLogMods) RandomCreated(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Destination(val string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = func() string { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) DestinationFunc(f func() string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetDestination() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomDestination(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Source(val string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = func() string { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) SourceFunc(f func() string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetSource() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomSource(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Type(val enums.CommsMessagetypeemail) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = func() enums.CommsMessagetypeemail { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) TypeFunc(f func() enums.CommsMessagetypeemail) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetType() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomType(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = func() enums.CommsMessagetypeemail {
return random_enums_CommsMessagetypeemail(f)
}
})
}
func (m commsEmailLogMods) WithParentsCascading() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
if isDone, _ := commsEmailLogWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsEmailLogWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsEmailWithContext(ctx, CommsEmailMods.WithParentsCascading())
m.WithDestinationEmail(related).Apply(ctx, o)
}
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithSourcePhone(related).Apply(ctx, o)
}
})
}
func (m commsEmailLogMods) WithDestinationEmail(rel *CommsEmailTemplate) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = &commsEmailLogRDestinationEmailR{
o: rel,
}
})
}
func (m commsEmailLogMods) WithNewDestinationEmail(mods ...CommsEmailMod) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
related := o.f.NewCommsEmailWithContext(ctx, mods...)
m.WithDestinationEmail(related).Apply(ctx, o)
})
}
func (m commsEmailLogMods) WithExistingDestinationEmail(em *models.CommsEmail) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = &commsEmailLogRDestinationEmailR{
o: o.f.FromExistingCommsEmail(em),
}
})
}
func (m commsEmailLogMods) WithoutDestinationEmail() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = nil
})
}
func (m commsEmailLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = &commsEmailLogRSourcePhoneR{
o: rel,
}
})
}
func (m commsEmailLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithSourcePhone(related).Apply(ctx, o)
})
}
func (m commsEmailLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = &commsEmailLogRSourcePhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m commsEmailLogMods) WithoutSourcePhone() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = nil
})
}