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

	"github.com/Gleipnir-Technology/bob"
	models "github.com/Gleipnir-Technology/nidus-sync/db/models"
	"github.com/aarondl/opt/null"
	"github.com/aarondl/opt/omit"
	"github.com/aarondl/opt/omitnull"
	"github.com/jaswdr/faker/v2"
)

type ArcgisServiceFeatureMod interface {
	Apply(context.Context, *ArcgisServiceFeatureTemplate)
}

type ArcgisServiceFeatureModFunc func(context.Context, *ArcgisServiceFeatureTemplate)

func (f ArcgisServiceFeatureModFunc) Apply(ctx context.Context, n *ArcgisServiceFeatureTemplate) {
	f(ctx, n)
}

type ArcgisServiceFeatureModSlice []ArcgisServiceFeatureMod

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

// ArcgisServiceFeatureTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type ArcgisServiceFeatureTemplate struct {
	Extent           func() string
	ItemID           func() string
	SpatialReference func() int32
	URL              func() string
	AccountID        func() null.Val[string]

	r arcgisServiceFeatureR
	f *Factory

	alreadyPersisted bool
}

type arcgisServiceFeatureR struct {
	FeatureServiceItemLayers                   []*arcgisServiceFeatureRFeatureServiceItemLayersR
	Account                                    *arcgisServiceFeatureRAccountR
	FieldseekerServiceFeatureItemOrganizations []*arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR
}

type arcgisServiceFeatureRFeatureServiceItemLayersR struct {
	number int
	o      *ArcgisLayerTemplate
}
type arcgisServiceFeatureRAccountR struct {
	o *ArcgisAccountTemplate
}
type arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR struct {
	number int
	o      *OrganizationTemplate
}

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

// setModelRels creates and sets the relationships on *models.ArcgisServiceFeature
// according to the relationships in the template. Nothing is inserted into the db
func (t ArcgisServiceFeatureTemplate) setModelRels(o *models.ArcgisServiceFeature) {
	if t.r.FeatureServiceItemLayers != nil {
		rel := models.ArcgisLayerSlice{}
		for _, r := range t.r.FeatureServiceItemLayers {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.FeatureServiceItemID = o.ItemID // h2
				rel.R.FeatureServiceItemServiceFeature = o
			}
			rel = append(rel, related...)
		}
		o.R.FeatureServiceItemLayers = rel
	}

	if t.r.Account != nil {
		rel := t.r.Account.o.Build()
		rel.R.ServiceFeatures = append(rel.R.ServiceFeatures, o)
		o.AccountID = null.From(rel.ID) // h2
		o.R.Account = rel
	}

	if t.r.FieldseekerServiceFeatureItemOrganizations != nil {
		rel := models.OrganizationSlice{}
		for _, r := range t.r.FieldseekerServiceFeatureItemOrganizations {
			related := r.o.BuildMany(r.number)
			for _, rel := range related {
				rel.FieldseekerServiceFeatureItemID = null.From(o.ItemID) // h2
				rel.R.FieldseekerServiceFeatureItemServiceFeature = o
			}
			rel = append(rel, related...)
		}
		o.R.FieldseekerServiceFeatureItemOrganizations = rel
	}
}

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

	if o.Extent != nil {
		val := o.Extent()
		m.Extent = omit.From(val)
	}
	if o.ItemID != nil {
		val := o.ItemID()
		m.ItemID = omit.From(val)
	}
	if o.SpatialReference != nil {
		val := o.SpatialReference()
		m.SpatialReference = omit.From(val)
	}
	if o.URL != nil {
		val := o.URL()
		m.URL = omit.From(val)
	}
	if o.AccountID != nil {
		val := o.AccountID()
		m.AccountID = omitnull.FromNull(val)
	}

	return m
}

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

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

	return m
}

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

	if o.Extent != nil {
		m.Extent = o.Extent()
	}
	if o.ItemID != nil {
		m.ItemID = o.ItemID()
	}
	if o.SpatialReference != nil {
		m.SpatialReference = o.SpatialReference()
	}
	if o.URL != nil {
		m.URL = o.URL()
	}
	if o.AccountID != nil {
		m.AccountID = o.AccountID()
	}

	o.setModelRels(m)

	return m
}

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

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

	return m
}

func ensureCreatableArcgisServiceFeature(m *models.ArcgisServiceFeatureSetter) {
	if !(m.Extent.IsValue()) {
		val := random_string(nil)
		m.Extent = omit.From(val)
	}
	if !(m.ItemID.IsValue()) {
		val := random_string(nil)
		m.ItemID = omit.From(val)
	}
	if !(m.SpatialReference.IsValue()) {
		val := random_int32(nil)
		m.SpatialReference = omit.From(val)
	}
	if !(m.URL.IsValue()) {
		val := random_string(nil)
		m.URL = omit.From(val)
	}
}

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

	isFeatureServiceItemLayersDone, _ := arcgisServiceFeatureRelFeatureServiceItemLayersCtx.Value(ctx)
	if !isFeatureServiceItemLayersDone && o.r.FeatureServiceItemLayers != nil {
		ctx = arcgisServiceFeatureRelFeatureServiceItemLayersCtx.WithValue(ctx, true)
		for _, r := range o.r.FeatureServiceItemLayers {
			if r.o.alreadyPersisted {
				m.R.FeatureServiceItemLayers = append(m.R.FeatureServiceItemLayers, r.o.Build())
			} else {
				rel0, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachFeatureServiceItemLayers(ctx, exec, rel0...)
				if err != nil {
					return err
				}
			}
		}
	}

	isAccountDone, _ := arcgisServiceFeatureRelAccountCtx.Value(ctx)
	if !isAccountDone && o.r.Account != nil {
		ctx = arcgisServiceFeatureRelAccountCtx.WithValue(ctx, true)
		if o.r.Account.o.alreadyPersisted {
			m.R.Account = o.r.Account.o.Build()
		} else {
			var rel1 *models.ArcgisAccount
			rel1, err = o.r.Account.o.Create(ctx, exec)
			if err != nil {
				return err
			}
			err = m.AttachAccount(ctx, exec, rel1)
			if err != nil {
				return err
			}
		}

	}

	isFieldseekerServiceFeatureItemOrganizationsDone, _ := arcgisServiceFeatureRelFieldseekerServiceFeatureItemOrganizationsCtx.Value(ctx)
	if !isFieldseekerServiceFeatureItemOrganizationsDone && o.r.FieldseekerServiceFeatureItemOrganizations != nil {
		ctx = arcgisServiceFeatureRelFieldseekerServiceFeatureItemOrganizationsCtx.WithValue(ctx, true)
		for _, r := range o.r.FieldseekerServiceFeatureItemOrganizations {
			if r.o.alreadyPersisted {
				m.R.FieldseekerServiceFeatureItemOrganizations = append(m.R.FieldseekerServiceFeatureItemOrganizations, r.o.Build())
			} else {
				rel2, err := r.o.CreateMany(ctx, exec, r.number)
				if err != nil {
					return err
				}

				err = m.AttachFieldseekerServiceFeatureItemOrganizations(ctx, exec, rel2...)
				if err != nil {
					return err
				}
			}
		}
	}

	return err
}

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

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

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

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

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

	return m, nil
}

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

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

// ArcgisServiceFeature has methods that act as mods for the ArcgisServiceFeatureTemplate
var ArcgisServiceFeatureMods arcgisServiceFeatureMods

type arcgisServiceFeatureMods struct{}

func (m arcgisServiceFeatureMods) RandomizeAllColumns(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModSlice{
		ArcgisServiceFeatureMods.RandomExtent(f),
		ArcgisServiceFeatureMods.RandomItemID(f),
		ArcgisServiceFeatureMods.RandomSpatialReference(f),
		ArcgisServiceFeatureMods.RandomURL(f),
		ArcgisServiceFeatureMods.RandomAccountID(f),
	}
}

// Set the model columns to this value
func (m arcgisServiceFeatureMods) Extent(val string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.Extent = func() string { return val }
	})
}

// Set the Column from the function
func (m arcgisServiceFeatureMods) ExtentFunc(f func() string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.Extent = f
	})
}

// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetExtent() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.Extent = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomExtent(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.Extent = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisServiceFeatureMods) ItemID(val string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.ItemID = func() string { return val }
	})
}

// Set the Column from the function
func (m arcgisServiceFeatureMods) ItemIDFunc(f func() string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.ItemID = f
	})
}

// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetItemID() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.ItemID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomItemID(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.ItemID = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisServiceFeatureMods) SpatialReference(val int32) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.SpatialReference = func() int32 { return val }
	})
}

// Set the Column from the function
func (m arcgisServiceFeatureMods) SpatialReferenceFunc(f func() int32) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.SpatialReference = f
	})
}

// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetSpatialReference() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.SpatialReference = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomSpatialReference(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.SpatialReference = func() int32 {
			return random_int32(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisServiceFeatureMods) URL(val string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.URL = func() string { return val }
	})
}

// Set the Column from the function
func (m arcgisServiceFeatureMods) URLFunc(f func() string) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.URL = f
	})
}

// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetURL() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.URL = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m arcgisServiceFeatureMods) RandomURL(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.URL = func() string {
			return random_string(f)
		}
	})
}

// Set the model columns to this value
func (m arcgisServiceFeatureMods) AccountID(val null.Val[string]) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.AccountID = func() null.Val[string] { return val }
	})
}

// Set the Column from the function
func (m arcgisServiceFeatureMods) AccountIDFunc(f func() null.Val[string]) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.AccountID = f
	})
}

// Clear any values for the column
func (m arcgisServiceFeatureMods) UnsetAccountID() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.AccountID = nil
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m arcgisServiceFeatureMods) RandomAccountID(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.AccountID = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m arcgisServiceFeatureMods) RandomAccountIDNotNull(f *faker.Faker) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(_ context.Context, o *ArcgisServiceFeatureTemplate) {
		o.AccountID = func() null.Val[string] {
			if f == nil {
				f = &defaultFaker
			}

			val := random_string(f)
			return null.From(val)
		}
	})
}

func (m arcgisServiceFeatureMods) WithParentsCascading() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		if isDone, _ := arcgisServiceFeatureWithParentsCascadingCtx.Value(ctx); isDone {
			return
		}
		ctx = arcgisServiceFeatureWithParentsCascadingCtx.WithValue(ctx, true)
		{

			related := o.f.NewArcgisAccountWithContext(ctx, ArcgisAccountMods.WithParentsCascading())
			m.WithAccount(related).Apply(ctx, o)
		}
	})
}

func (m arcgisServiceFeatureMods) WithAccount(rel *ArcgisAccountTemplate) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.Account = &arcgisServiceFeatureRAccountR{
			o: rel,
		}
	})
}

func (m arcgisServiceFeatureMods) WithNewAccount(mods ...ArcgisAccountMod) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		related := o.f.NewArcgisAccountWithContext(ctx, mods...)

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

func (m arcgisServiceFeatureMods) WithExistingAccount(em *models.ArcgisAccount) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.Account = &arcgisServiceFeatureRAccountR{
			o: o.f.FromExistingArcgisAccount(em),
		}
	})
}

func (m arcgisServiceFeatureMods) WithoutAccount() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.Account = nil
	})
}

func (m arcgisServiceFeatureMods) WithFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FeatureServiceItemLayers = []*arcgisServiceFeatureRFeatureServiceItemLayersR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisServiceFeatureMods) WithNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		related := o.f.NewArcgisLayerWithContext(ctx, mods...)
		m.WithFeatureServiceItemLayers(number, related).Apply(ctx, o)
	})
}

func (m arcgisServiceFeatureMods) AddFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisServiceFeatureRFeatureServiceItemLayersR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisServiceFeatureMods) AddNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		related := o.f.NewArcgisLayerWithContext(ctx, mods...)
		m.AddFeatureServiceItemLayers(number, related).Apply(ctx, o)
	})
}

func (m arcgisServiceFeatureMods) AddExistingFeatureServiceItemLayers(existingModels ...*models.ArcgisLayer) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		for _, em := range existingModels {
			o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisServiceFeatureRFeatureServiceItemLayersR{
				o: o.f.FromExistingArcgisLayer(em),
			})
		}
	})
}

func (m arcgisServiceFeatureMods) WithoutFeatureServiceItemLayers() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FeatureServiceItemLayers = nil
	})
}

func (m arcgisServiceFeatureMods) WithFieldseekerServiceFeatureItemOrganizations(number int, related *OrganizationTemplate) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FieldseekerServiceFeatureItemOrganizations = []*arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{{
			number: number,
			o:      related,
		}}
	})
}

func (m arcgisServiceFeatureMods) WithNewFieldseekerServiceFeatureItemOrganizations(number int, mods ...OrganizationMod) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.WithFieldseekerServiceFeatureItemOrganizations(number, related).Apply(ctx, o)
	})
}

func (m arcgisServiceFeatureMods) AddFieldseekerServiceFeatureItemOrganizations(number int, related *OrganizationTemplate) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FieldseekerServiceFeatureItemOrganizations = append(o.r.FieldseekerServiceFeatureItemOrganizations, &arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{
			number: number,
			o:      related,
		})
	})
}

func (m arcgisServiceFeatureMods) AddNewFieldseekerServiceFeatureItemOrganizations(number int, mods ...OrganizationMod) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		related := o.f.NewOrganizationWithContext(ctx, mods...)
		m.AddFieldseekerServiceFeatureItemOrganizations(number, related).Apply(ctx, o)
	})
}

func (m arcgisServiceFeatureMods) AddExistingFieldseekerServiceFeatureItemOrganizations(existingModels ...*models.Organization) ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		for _, em := range existingModels {
			o.r.FieldseekerServiceFeatureItemOrganizations = append(o.r.FieldseekerServiceFeatureItemOrganizations, &arcgisServiceFeatureRFieldseekerServiceFeatureItemOrganizationsR{
				o: o.f.FromExistingOrganization(em),
			})
		}
	})
}

func (m arcgisServiceFeatureMods) WithoutFieldseekerServiceFeatureItemOrganizations() ArcgisServiceFeatureMod {
	return ArcgisServiceFeatureModFunc(func(ctx context.Context, o *ArcgisServiceFeatureTemplate) {
		o.r.FieldseekerServiceFeatureItemOrganizations = nil
	})
}
