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

package factory

import (
	"context"

	"github.com/aarondl/opt/null"
	models "github.com/safing/portmaster/base/database/storage/sqlite/models"
)

type Factory struct {
	baseRecordMods RecordModSlice
}

func New() *Factory {
	return &Factory{}
}

func (f *Factory) NewRecord(mods ...RecordMod) *RecordTemplate {
	return f.NewRecordWithContext(context.Background(), mods...)
}

func (f *Factory) NewRecordWithContext(ctx context.Context, mods ...RecordMod) *RecordTemplate {
	o := &RecordTemplate{f: f}

	if f != nil {
		f.baseRecordMods.Apply(ctx, o)
	}

	RecordModSlice(mods).Apply(ctx, o)

	return o
}

func (f *Factory) FromExistingRecord(m *models.Record) *RecordTemplate {
	o := &RecordTemplate{f: f, alreadyPersisted: true}

	o.Key = func() string { return m.Key }
	o.Format = func() null.Val[int64] { return m.Format }
	o.Value = func() null.Val[[]byte] { return m.Value }
	o.Created = func() int64 { return m.Created }
	o.Modified = func() int64 { return m.Modified }
	o.Expires = func() int64 { return m.Expires }
	o.Deleted = func() int64 { return m.Deleted }
	o.Secret = func() bool { return m.Secret }
	o.Crownjewel = func() bool { return m.Crownjewel }

	return o
}

func (f *Factory) ClearBaseRecordMods() {
	f.baseRecordMods = nil
}

func (f *Factory) AddBaseRecordMod(mods ...RecordMod) {
	f.baseRecordMods = append(f.baseRecordMods, mods...)
}
