// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package models

import (
	"context"
	"database/sql"
	"fmt"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/aarondl/null/v8"
	"github.com/aarondl/sqlboiler/v4/boil"
	"github.com/aarondl/sqlboiler/v4/queries"
	"github.com/aarondl/sqlboiler/v4/queries/qm"
	"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
	"github.com/aarondl/strmangle"
	"github.com/friendsofgo/errors"
)

// Scenario is an object representing the database table.
type Scenario struct {
	ScenarioID int32       `boil:"scenario_id" json:"scenario_id" toml:"scenario_id" yaml:"scenario_id"`
	ProjectID  int32       `boil:"project_id" json:"project_id" toml:"project_id" yaml:"project_id"`
	Title      string      `boil:"title" json:"title" toml:"title" yaml:"title"`
	Descrip    null.String `boil:"descrip" json:"descrip,omitempty" toml:"descrip" yaml:"descrip,omitempty"`
	CreatedAt  time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	UpdatedAt  time.Time   `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
	DeletedAt  null.Time   `boil:"deleted_at" json:"deleted_at,omitempty" toml:"deleted_at" yaml:"deleted_at,omitempty"`
	Selectors  string      `boil:"selectors" json:"selectors" toml:"selectors" yaml:"selectors"`

	R *scenarioR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L scenarioL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var ScenarioColumns = struct {
	ScenarioID string
	ProjectID  string
	Title      string
	Descrip    string
	CreatedAt  string
	UpdatedAt  string
	DeletedAt  string
	Selectors  string
}{
	ScenarioID: "scenario_id",
	ProjectID:  "project_id",
	Title:      "title",
	Descrip:    "descrip",
	CreatedAt:  "created_at",
	UpdatedAt:  "updated_at",
	DeletedAt:  "deleted_at",
	Selectors:  "selectors",
}

var ScenarioTableColumns = struct {
	ScenarioID string
	ProjectID  string
	Title      string
	Descrip    string
	CreatedAt  string
	UpdatedAt  string
	DeletedAt  string
	Selectors  string
}{
	ScenarioID: "scenarios.scenario_id",
	ProjectID:  "scenarios.project_id",
	Title:      "scenarios.title",
	Descrip:    "scenarios.descrip",
	CreatedAt:  "scenarios.created_at",
	UpdatedAt:  "scenarios.updated_at",
	DeletedAt:  "scenarios.deleted_at",
	Selectors:  "scenarios.selectors",
}

// Generated where

var ScenarioWhere = struct {
	ScenarioID whereHelperint32
	ProjectID  whereHelperint32
	Title      whereHelperstring
	Descrip    whereHelpernull_String
	CreatedAt  whereHelpertime_Time
	UpdatedAt  whereHelpertime_Time
	DeletedAt  whereHelpernull_Time
	Selectors  whereHelperstring
}{
	ScenarioID: whereHelperint32{field: "\"scenarios\".\"scenario_id\""},
	ProjectID:  whereHelperint32{field: "\"scenarios\".\"project_id\""},
	Title:      whereHelperstring{field: "\"scenarios\".\"title\""},
	Descrip:    whereHelpernull_String{field: "\"scenarios\".\"descrip\""},
	CreatedAt:  whereHelpertime_Time{field: "\"scenarios\".\"created_at\""},
	UpdatedAt:  whereHelpertime_Time{field: "\"scenarios\".\"updated_at\""},
	DeletedAt:  whereHelpernull_Time{field: "\"scenarios\".\"deleted_at\""},
	Selectors:  whereHelperstring{field: "\"scenarios\".\"selectors\""},
}

// ScenarioRels is where relationship names are stored.
var ScenarioRels = struct {
	Project       string
	Scripts       string
	SimpleScripts string
}{
	Project:       "Project",
	Scripts:       "Scripts",
	SimpleScripts: "SimpleScripts",
}

// scenarioR is where relationships are stored.
type scenarioR struct {
	Project       *Project          `boil:"Project" json:"Project" toml:"Project" yaml:"Project"`
	Scripts       ScriptSlice       `boil:"Scripts" json:"Scripts" toml:"Scripts" yaml:"Scripts"`
	SimpleScripts SimpleScriptSlice `boil:"SimpleScripts" json:"SimpleScripts" toml:"SimpleScripts" yaml:"SimpleScripts"`
}

// NewStruct creates a new relationship struct
func (*scenarioR) NewStruct() *scenarioR {
	return &scenarioR{}
}

func (o *Scenario) GetProject() *Project {
	if o == nil {
		return nil
	}

	return o.R.GetProject()
}

func (r *scenarioR) GetProject() *Project {
	if r == nil {
		return nil
	}

	return r.Project
}

func (o *Scenario) GetScripts() ScriptSlice {
	if o == nil {
		return nil
	}

	return o.R.GetScripts()
}

func (r *scenarioR) GetScripts() ScriptSlice {
	if r == nil {
		return nil
	}

	return r.Scripts
}

func (o *Scenario) GetSimpleScripts() SimpleScriptSlice {
	if o == nil {
		return nil
	}

	return o.R.GetSimpleScripts()
}

func (r *scenarioR) GetSimpleScripts() SimpleScriptSlice {
	if r == nil {
		return nil
	}

	return r.SimpleScripts
}

// scenarioL is where Load methods for each relationship are stored.
type scenarioL struct{}

var (
	scenarioAllColumns            = []string{"scenario_id", "project_id", "title", "descrip", "created_at", "updated_at", "deleted_at", "selectors"}
	scenarioColumnsWithoutDefault = []string{"project_id", "title"}
	scenarioColumnsWithDefault    = []string{"scenario_id", "descrip", "created_at", "updated_at", "deleted_at", "selectors"}
	scenarioPrimaryKeyColumns     = []string{"scenario_id"}
	scenarioGeneratedColumns      = []string{}
)

type (
	// ScenarioSlice is an alias for a slice of pointers to Scenario.
	// This should almost always be used instead of []Scenario.
	ScenarioSlice []*Scenario
	// ScenarioHook is the signature for custom Scenario hook methods
	ScenarioHook func(context.Context, boil.ContextExecutor, *Scenario) error

	scenarioQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	scenarioType                 = reflect.TypeOf(&Scenario{})
	scenarioMapping              = queries.MakeStructMapping(scenarioType)
	scenarioPrimaryKeyMapping, _ = queries.BindMapping(scenarioType, scenarioMapping, scenarioPrimaryKeyColumns)
	scenarioInsertCacheMut       sync.RWMutex
	scenarioInsertCache          = make(map[string]insertCache)
	scenarioUpdateCacheMut       sync.RWMutex
	scenarioUpdateCache          = make(map[string]updateCache)
	scenarioUpsertCacheMut       sync.RWMutex
	scenarioUpsertCache          = make(map[string]insertCache)
)

var (
	// Force time package dependency for automated UpdatedAt/CreatedAt.
	_ = time.Second
	// Force qmhelper dependency for where clause generation (which doesn't
	// always happen)
	_ = qmhelper.Where
)

var scenarioAfterSelectMu sync.Mutex
var scenarioAfterSelectHooks []ScenarioHook

var scenarioBeforeInsertMu sync.Mutex
var scenarioBeforeInsertHooks []ScenarioHook
var scenarioAfterInsertMu sync.Mutex
var scenarioAfterInsertHooks []ScenarioHook

var scenarioBeforeUpdateMu sync.Mutex
var scenarioBeforeUpdateHooks []ScenarioHook
var scenarioAfterUpdateMu sync.Mutex
var scenarioAfterUpdateHooks []ScenarioHook

var scenarioBeforeDeleteMu sync.Mutex
var scenarioBeforeDeleteHooks []ScenarioHook
var scenarioAfterDeleteMu sync.Mutex
var scenarioAfterDeleteHooks []ScenarioHook

var scenarioBeforeUpsertMu sync.Mutex
var scenarioBeforeUpsertHooks []ScenarioHook
var scenarioAfterUpsertMu sync.Mutex
var scenarioAfterUpsertHooks []ScenarioHook

// doAfterSelectHooks executes all "after Select" hooks.
func (o *Scenario) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioAfterSelectHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeInsertHooks executes all "before insert" hooks.
func (o *Scenario) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioBeforeInsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterInsertHooks executes all "after Insert" hooks.
func (o *Scenario) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioAfterInsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *Scenario) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioBeforeUpdateHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterUpdateHooks executes all "after Update" hooks.
func (o *Scenario) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioAfterUpdateHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *Scenario) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioBeforeDeleteHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *Scenario) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioAfterDeleteHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *Scenario) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioBeforeUpsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *Scenario) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
	if boil.HooksAreSkipped(ctx) {
		return nil
	}

	for _, hook := range scenarioAfterUpsertHooks {
		if err := hook(ctx, exec, o); err != nil {
			return err
		}
	}

	return nil
}

// AddScenarioHook registers your hook function for all future operations.
func AddScenarioHook(hookPoint boil.HookPoint, scenarioHook ScenarioHook) {
	switch hookPoint {
	case boil.AfterSelectHook:
		scenarioAfterSelectMu.Lock()
		scenarioAfterSelectHooks = append(scenarioAfterSelectHooks, scenarioHook)
		scenarioAfterSelectMu.Unlock()
	case boil.BeforeInsertHook:
		scenarioBeforeInsertMu.Lock()
		scenarioBeforeInsertHooks = append(scenarioBeforeInsertHooks, scenarioHook)
		scenarioBeforeInsertMu.Unlock()
	case boil.AfterInsertHook:
		scenarioAfterInsertMu.Lock()
		scenarioAfterInsertHooks = append(scenarioAfterInsertHooks, scenarioHook)
		scenarioAfterInsertMu.Unlock()
	case boil.BeforeUpdateHook:
		scenarioBeforeUpdateMu.Lock()
		scenarioBeforeUpdateHooks = append(scenarioBeforeUpdateHooks, scenarioHook)
		scenarioBeforeUpdateMu.Unlock()
	case boil.AfterUpdateHook:
		scenarioAfterUpdateMu.Lock()
		scenarioAfterUpdateHooks = append(scenarioAfterUpdateHooks, scenarioHook)
		scenarioAfterUpdateMu.Unlock()
	case boil.BeforeDeleteHook:
		scenarioBeforeDeleteMu.Lock()
		scenarioBeforeDeleteHooks = append(scenarioBeforeDeleteHooks, scenarioHook)
		scenarioBeforeDeleteMu.Unlock()
	case boil.AfterDeleteHook:
		scenarioAfterDeleteMu.Lock()
		scenarioAfterDeleteHooks = append(scenarioAfterDeleteHooks, scenarioHook)
		scenarioAfterDeleteMu.Unlock()
	case boil.BeforeUpsertHook:
		scenarioBeforeUpsertMu.Lock()
		scenarioBeforeUpsertHooks = append(scenarioBeforeUpsertHooks, scenarioHook)
		scenarioBeforeUpsertMu.Unlock()
	case boil.AfterUpsertHook:
		scenarioAfterUpsertMu.Lock()
		scenarioAfterUpsertHooks = append(scenarioAfterUpsertHooks, scenarioHook)
		scenarioAfterUpsertMu.Unlock()
	}
}

// One returns a single scenario record from the query.
func (q scenarioQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Scenario, error) {
	o := &Scenario{}

	queries.SetLimit(q.Query, 1)

	err := q.Bind(ctx, exec, o)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: failed to execute a one query for scenarios")
	}

	if err := o.doAfterSelectHooks(ctx, exec); err != nil {
		return o, err
	}

	return o, nil
}

// All returns all Scenario records from the query.
func (q scenarioQuery) All(ctx context.Context, exec boil.ContextExecutor) (ScenarioSlice, error) {
	var o []*Scenario

	err := q.Bind(ctx, exec, &o)
	if err != nil {
		return nil, errors.Wrap(err, "models: failed to assign all query results to Scenario slice")
	}

	if len(scenarioAfterSelectHooks) != 0 {
		for _, obj := range o {
			if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
				return o, err
			}
		}
	}

	return o, nil
}

// Count returns the count of all Scenario records in the query.
func (q scenarioQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to count scenarios rows")
	}

	return count, nil
}

// Exists checks if the row exists in the table.
func (q scenarioQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "models: failed to check if scenarios exists")
	}

	return count > 0, nil
}

// Project pointed to by the foreign key.
func (o *Scenario) Project(mods ...qm.QueryMod) projectQuery {
	queryMods := []qm.QueryMod{
		qm.Where("\"id\" = ?", o.ProjectID),
	}

	queryMods = append(queryMods, mods...)

	return Projects(queryMods...)
}

// Scripts retrieves all the script's Scripts with an executor.
func (o *Scenario) Scripts(mods ...qm.QueryMod) scriptQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}

	queryMods = append(queryMods,
		qm.Where("\"scripts\".\"scenario_id\"=?", o.ScenarioID),
	)

	return Scripts(queryMods...)
}

// SimpleScripts retrieves all the simple_script's SimpleScripts with an executor.
func (o *Scenario) SimpleScripts(mods ...qm.QueryMod) simpleScriptQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}

	queryMods = append(queryMods,
		qm.Where("\"simple_scripts\".\"scenario_id\"=?", o.ScenarioID),
	)

	return SimpleScripts(queryMods...)
}

// LoadProject allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (scenarioL) LoadProject(ctx context.Context, e boil.ContextExecutor, singular bool, maybeScenario interface{}, mods queries.Applicator) error {
	var slice []*Scenario
	var object *Scenario

	if singular {
		var ok bool
		object, ok = maybeScenario.(*Scenario)
		if !ok {
			object = new(Scenario)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeScenario))
			}
		}
	} else {
		s, ok := maybeScenario.(*[]*Scenario)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeScenario))
			}
		}
	}

	args := make(map[interface{}]struct{})
	if singular {
		if object.R == nil {
			object.R = &scenarioR{}
		}
		args[object.ProjectID] = struct{}{}

	} else {
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &scenarioR{}
			}

			args[obj.ProjectID] = struct{}{}

		}
	}

	if len(args) == 0 {
		return nil
	}

	argsSlice := make([]interface{}, len(args))
	i := 0
	for arg := range args {
		argsSlice[i] = arg
		i++
	}

	query := NewQuery(
		qm.From(`projects`),
		qm.WhereIn(`projects.id in ?`, argsSlice...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load Project")
	}

	var resultSlice []*Project
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Project")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results of eager load for projects")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for projects")
	}

	if len(projectAfterSelectHooks) != 0 {
		for _, obj := range resultSlice {
			if err := obj.doAfterSelectHooks(ctx, e); err != nil {
				return err
			}
		}
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		foreign := resultSlice[0]
		object.R.Project = foreign
		if foreign.R == nil {
			foreign.R = &projectR{}
		}
		foreign.R.Scenarios = append(foreign.R.Scenarios, object)
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.ProjectID == foreign.ID {
				local.R.Project = foreign
				if foreign.R == nil {
					foreign.R = &projectR{}
				}
				foreign.R.Scenarios = append(foreign.R.Scenarios, local)
				break
			}
		}
	}

	return nil
}

// LoadScripts allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (scenarioL) LoadScripts(ctx context.Context, e boil.ContextExecutor, singular bool, maybeScenario interface{}, mods queries.Applicator) error {
	var slice []*Scenario
	var object *Scenario

	if singular {
		var ok bool
		object, ok = maybeScenario.(*Scenario)
		if !ok {
			object = new(Scenario)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeScenario))
			}
		}
	} else {
		s, ok := maybeScenario.(*[]*Scenario)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeScenario))
			}
		}
	}

	args := make(map[interface{}]struct{})
	if singular {
		if object.R == nil {
			object.R = &scenarioR{}
		}
		args[object.ScenarioID] = struct{}{}
	} else {
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &scenarioR{}
			}
			args[obj.ScenarioID] = struct{}{}
		}
	}

	if len(args) == 0 {
		return nil
	}

	argsSlice := make([]interface{}, len(args))
	i := 0
	for arg := range args {
		argsSlice[i] = arg
		i++
	}

	query := NewQuery(
		qm.From(`scripts`),
		qm.WhereIn(`scripts.scenario_id in ?`, argsSlice...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load scripts")
	}

	var resultSlice []*Script
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice scripts")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results in eager load on scripts")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for scripts")
	}

	if len(scriptAfterSelectHooks) != 0 {
		for _, obj := range resultSlice {
			if err := obj.doAfterSelectHooks(ctx, e); err != nil {
				return err
			}
		}
	}
	if singular {
		object.R.Scripts = resultSlice
		for _, foreign := range resultSlice {
			if foreign.R == nil {
				foreign.R = &scriptR{}
			}
			foreign.R.Scenario = object
		}
		return nil
	}

	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ScenarioID == foreign.ScenarioID {
				local.R.Scripts = append(local.R.Scripts, foreign)
				if foreign.R == nil {
					foreign.R = &scriptR{}
				}
				foreign.R.Scenario = local
				break
			}
		}
	}

	return nil
}

// LoadSimpleScripts allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (scenarioL) LoadSimpleScripts(ctx context.Context, e boil.ContextExecutor, singular bool, maybeScenario interface{}, mods queries.Applicator) error {
	var slice []*Scenario
	var object *Scenario

	if singular {
		var ok bool
		object, ok = maybeScenario.(*Scenario)
		if !ok {
			object = new(Scenario)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeScenario))
			}
		}
	} else {
		s, ok := maybeScenario.(*[]*Scenario)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeScenario)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeScenario))
			}
		}
	}

	args := make(map[interface{}]struct{})
	if singular {
		if object.R == nil {
			object.R = &scenarioR{}
		}
		args[object.ScenarioID] = struct{}{}
	} else {
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &scenarioR{}
			}
			args[obj.ScenarioID] = struct{}{}
		}
	}

	if len(args) == 0 {
		return nil
	}

	argsSlice := make([]interface{}, len(args))
	i := 0
	for arg := range args {
		argsSlice[i] = arg
		i++
	}

	query := NewQuery(
		qm.From(`simple_scripts`),
		qm.WhereIn(`simple_scripts.scenario_id in ?`, argsSlice...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load simple_scripts")
	}

	var resultSlice []*SimpleScript
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice simple_scripts")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results in eager load on simple_scripts")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for simple_scripts")
	}

	if len(simpleScriptAfterSelectHooks) != 0 {
		for _, obj := range resultSlice {
			if err := obj.doAfterSelectHooks(ctx, e); err != nil {
				return err
			}
		}
	}
	if singular {
		object.R.SimpleScripts = resultSlice
		for _, foreign := range resultSlice {
			if foreign.R == nil {
				foreign.R = &simpleScriptR{}
			}
			foreign.R.Scenario = object
		}
		return nil
	}

	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ScenarioID == foreign.ScenarioID {
				local.R.SimpleScripts = append(local.R.SimpleScripts, foreign)
				if foreign.R == nil {
					foreign.R = &simpleScriptR{}
				}
				foreign.R.Scenario = local
				break
			}
		}
	}

	return nil
}

// SetProject of the scenario to the related item.
// Sets o.R.Project to related.
// Adds o to related.R.Scenarios.
func (o *Scenario) SetProject(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Project) error {
	var err error
	if insert {
		if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE \"scenarios\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"project_id"}),
		strmangle.WhereClause("\"", "\"", 2, scenarioPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ScenarioID}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, updateQuery)
		fmt.Fprintln(writer, values)
	}
	if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}

	o.ProjectID = related.ID
	if o.R == nil {
		o.R = &scenarioR{
			Project: related,
		}
	} else {
		o.R.Project = related
	}

	if related.R == nil {
		related.R = &projectR{
			Scenarios: ScenarioSlice{o},
		}
	} else {
		related.R.Scenarios = append(related.R.Scenarios, o)
	}

	return nil
}

// AddScripts adds the given related objects to the existing relationships
// of the scenario, optionally inserting them as new records.
// Appends related to o.R.Scripts.
// Sets related.R.Scenario appropriately.
func (o *Scenario) AddScripts(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Script) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.ScenarioID = o.ScenarioID
			if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"scripts\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"scenario_id"}),
				strmangle.WhereClause("\"", "\"", 2, scriptPrimaryKeyColumns),
			)
			values := []interface{}{o.ScenarioID, rel.ScriptID}

			if boil.IsDebug(ctx) {
				writer := boil.DebugWriterFrom(ctx)
				fmt.Fprintln(writer, updateQuery)
				fmt.Fprintln(writer, values)
			}
			if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
				return errors.Wrap(err, "failed to update foreign table")
			}

			rel.ScenarioID = o.ScenarioID
		}
	}

	if o.R == nil {
		o.R = &scenarioR{
			Scripts: related,
		}
	} else {
		o.R.Scripts = append(o.R.Scripts, related...)
	}

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &scriptR{
				Scenario: o,
			}
		} else {
			rel.R.Scenario = o
		}
	}
	return nil
}

// AddSimpleScripts adds the given related objects to the existing relationships
// of the scenario, optionally inserting them as new records.
// Appends related to o.R.SimpleScripts.
// Sets related.R.Scenario appropriately.
func (o *Scenario) AddSimpleScripts(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*SimpleScript) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.ScenarioID = o.ScenarioID
			if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"simple_scripts\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"scenario_id"}),
				strmangle.WhereClause("\"", "\"", 2, simpleScriptPrimaryKeyColumns),
			)
			values := []interface{}{o.ScenarioID, rel.ScriptID}

			if boil.IsDebug(ctx) {
				writer := boil.DebugWriterFrom(ctx)
				fmt.Fprintln(writer, updateQuery)
				fmt.Fprintln(writer, values)
			}
			if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
				return errors.Wrap(err, "failed to update foreign table")
			}

			rel.ScenarioID = o.ScenarioID
		}
	}

	if o.R == nil {
		o.R = &scenarioR{
			SimpleScripts: related,
		}
	} else {
		o.R.SimpleScripts = append(o.R.SimpleScripts, related...)
	}

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &simpleScriptR{
				Scenario: o,
			}
		} else {
			rel.R.Scenario = o
		}
	}
	return nil
}

// Scenarios retrieves all the records using an executor.
func Scenarios(mods ...qm.QueryMod) scenarioQuery {
	mods = append(mods, qm.From("\"scenarios\""))
	q := NewQuery(mods...)
	if len(queries.GetSelect(q)) == 0 {
		queries.SetSelect(q, []string{"\"scenarios\".*"})
	}

	return scenarioQuery{q}
}

// FindScenario retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindScenario(ctx context.Context, exec boil.ContextExecutor, scenarioID int32, selectCols ...string) (*Scenario, error) {
	scenarioObj := &Scenario{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"scenarios\" where \"scenario_id\"=$1", sel,
	)

	q := queries.Raw(query, scenarioID)

	err := q.Bind(ctx, exec, scenarioObj)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "models: unable to select from scenarios")
	}

	if err = scenarioObj.doAfterSelectHooks(ctx, exec); err != nil {
		return scenarioObj, err
	}

	return scenarioObj, nil
}

// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *Scenario) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no scenarios provided for insertion")
	}

	var err error
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

		if o.CreatedAt.IsZero() {
			o.CreatedAt = currTime
		}
		if o.UpdatedAt.IsZero() {
			o.UpdatedAt = currTime
		}
	}

	if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
		return err
	}

	nzDefaults := queries.NonZeroDefaultSet(scenarioColumnsWithDefault, o)

	key := makeCacheKey(columns, nzDefaults)
	scenarioInsertCacheMut.RLock()
	cache, cached := scenarioInsertCache[key]
	scenarioInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			scenarioAllColumns,
			scenarioColumnsWithDefault,
			scenarioColumnsWithoutDefault,
			nzDefaults,
		)

		cache.valueMapping, err = queries.BindMapping(scenarioType, scenarioMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(scenarioType, scenarioMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"scenarios\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"scenarios\" %sDEFAULT VALUES%s"
		}

		var queryOutput, queryReturning string

		if len(cache.retMapping) != 0 {
			queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
		}

		cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}

	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}

	if err != nil {
		return errors.Wrap(err, "models: unable to insert into scenarios")
	}

	if !cached {
		scenarioInsertCacheMut.Lock()
		scenarioInsertCache[key] = cache
		scenarioInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}

// Update uses an executor to update the Scenario.
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
func (o *Scenario) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

		o.UpdatedAt = currTime
	}

	var err error
	if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
		return 0, err
	}
	key := makeCacheKey(columns, nil)
	scenarioUpdateCacheMut.RLock()
	cache, cached := scenarioUpdateCache[key]
	scenarioUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			scenarioAllColumns,
			scenarioPrimaryKeyColumns,
		)

		if !columns.IsWhitelist() {
			wl = strmangle.SetComplement(wl, []string{"created_at"})
		}
		if len(wl) == 0 {
			return 0, errors.New("models: unable to update scenarios, could not build whitelist")
		}

		cache.query = fmt.Sprintf("UPDATE \"scenarios\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, scenarioPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(scenarioType, scenarioMapping, append(wl, scenarioPrimaryKeyColumns...))
		if err != nil {
			return 0, err
		}
	}

	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, values)
	}
	var result sql.Result
	result, err = exec.ExecContext(ctx, cache.query, values...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update scenarios row")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by update for scenarios")
	}

	if !cached {
		scenarioUpdateCacheMut.Lock()
		scenarioUpdateCache[key] = cache
		scenarioUpdateCacheMut.Unlock()
	}

	return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}

// UpdateAll updates all rows with the specified column values.
func (q scenarioQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
	queries.SetUpdate(q.Query, cols)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update all for scenarios")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to retrieve rows affected for scenarios")
	}

	return rowsAff, nil
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o ScenarioSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
	ln := int64(len(o))
	if ln == 0 {
		return 0, nil
	}

	if len(cols) == 0 {
		return 0, errors.New("models: update all requires at least one column argument")
	}

	colNames := make([]string, len(cols))
	args := make([]interface{}, len(cols))

	i := 0
	for name, value := range cols {
		colNames[i] = name
		args[i] = value
		i++
	}

	// Append all of the primary key values for each column
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), scenarioPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf("UPDATE \"scenarios\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, scenarioPrimaryKeyColumns, len(o)))

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args...)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to update all in scenario slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all scenario")
	}
	return rowsAff, nil
}

// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
func (o *Scenario) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
	if o == nil {
		return errors.New("models: no scenarios provided for upsert")
	}
	if !boil.TimestampsAreSkipped(ctx) {
		currTime := time.Now().In(boil.GetLocation())

		if o.CreatedAt.IsZero() {
			o.CreatedAt = currTime
		}
		o.UpdatedAt = currTime
	}

	if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
		return err
	}

	nzDefaults := queries.NonZeroDefaultSet(scenarioColumnsWithDefault, o)

	// Build cache key in-line uglily - mysql vs psql problems
	buf := strmangle.GetBuffer()
	if updateOnConflict {
		buf.WriteByte('t')
	} else {
		buf.WriteByte('f')
	}
	buf.WriteByte('.')
	for _, c := range conflictColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	buf.WriteString(strconv.Itoa(updateColumns.Kind))
	for _, c := range updateColumns.Cols {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	buf.WriteString(strconv.Itoa(insertColumns.Kind))
	for _, c := range insertColumns.Cols {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)

	scenarioUpsertCacheMut.RLock()
	cache, cached := scenarioUpsertCache[key]
	scenarioUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, _ := insertColumns.InsertColumnSet(
			scenarioAllColumns,
			scenarioColumnsWithDefault,
			scenarioColumnsWithoutDefault,
			nzDefaults,
		)

		update := updateColumns.UpdateColumnSet(
			scenarioAllColumns,
			scenarioPrimaryKeyColumns,
		)

		if updateOnConflict && len(update) == 0 {
			return errors.New("models: unable to upsert scenarios, could not build update column list")
		}

		ret := strmangle.SetComplement(scenarioAllColumns, strmangle.SetIntersect(insert, update))

		conflict := conflictColumns
		if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
			if len(scenarioPrimaryKeyColumns) == 0 {
				return errors.New("models: unable to upsert scenarios, could not build conflict column list")
			}

			conflict = make([]string, len(scenarioPrimaryKeyColumns))
			copy(conflict, scenarioPrimaryKeyColumns)
		}
		cache.query = buildUpsertQueryPostgres(dialect, "\"scenarios\"", updateOnConflict, ret, update, conflict, insert, opts...)

		cache.valueMapping, err = queries.BindMapping(scenarioType, scenarioMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(scenarioType, scenarioMapping, ret)
			if err != nil {
				return err
			}
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
		if errors.Is(err, sql.ErrNoRows) {
			err = nil // Postgres doesn't return anything when there's no update
		}
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "models: unable to upsert scenarios")
	}

	if !cached {
		scenarioUpsertCacheMut.Lock()
		scenarioUpsertCache[key] = cache
		scenarioUpsertCacheMut.Unlock()
	}

	return o.doAfterUpsertHooks(ctx, exec)
}

// Delete deletes a single Scenario record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Scenario) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if o == nil {
		return 0, errors.New("models: no Scenario provided for delete")
	}

	if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
		return 0, err
	}

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), scenarioPrimaryKeyMapping)
	sql := "DELETE FROM \"scenarios\" WHERE \"scenario_id\"=$1"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args...)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete from scenarios")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by delete for scenarios")
	}

	if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
		return 0, err
	}

	return rowsAff, nil
}

// DeleteAll deletes all matching rows.
func (q scenarioQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if q.Query == nil {
		return 0, errors.New("models: no scenarioQuery provided for delete all")
	}

	queries.SetDelete(q.Query)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete all from scenarios")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for scenarios")
	}

	return rowsAff, nil
}

// DeleteAll deletes all rows in the slice, using an executor.
func (o ScenarioSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if len(o) == 0 {
		return 0, nil
	}

	if len(scenarioBeforeDeleteHooks) != 0 {
		for _, obj := range o {
			if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
				return 0, err
			}
		}
	}

	var args []interface{}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), scenarioPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "DELETE FROM \"scenarios\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, scenarioPrimaryKeyColumns, len(o))

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "models: unable to delete all from scenario slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for scenarios")
	}

	if len(scenarioAfterDeleteHooks) != 0 {
		for _, obj := range o {
			if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
				return 0, err
			}
		}
	}

	return rowsAff, nil
}

// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *Scenario) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindScenario(ctx, exec, o.ScenarioID)
	if err != nil {
		return err
	}

	*o = *ret
	return nil
}

// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *ScenarioSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

	slice := ScenarioSlice{}
	var args []interface{}
	for _, obj := range *o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), scenarioPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "SELECT \"scenarios\".* FROM \"scenarios\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, scenarioPrimaryKeyColumns, len(*o))

	q := queries.Raw(sql, args...)

	err := q.Bind(ctx, exec, &slice)
	if err != nil {
		return errors.Wrap(err, "models: unable to reload all in ScenarioSlice")
	}

	*o = slice

	return nil
}

// ScenarioExists checks if the Scenario row exists.
func ScenarioExists(ctx context.Context, exec boil.ContextExecutor, scenarioID int32) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from \"scenarios\" where \"scenario_id\"=$1 limit 1)"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, scenarioID)
	}
	row := exec.QueryRowContext(ctx, sql, scenarioID)

	err := row.Scan(&exists)
	if err != nil {
		return false, errors.Wrap(err, "models: unable to check if scenarios exists")
	}

	return exists, nil
}

// Exists checks if the Scenario row exists.
func (o *Scenario) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	return ScenarioExists(ctx, exec, o.ScenarioID)
}
