// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"example/myco-api/ent/grainjar"
	"example/myco-api/ent/predicate"
	"example/myco-api/ent/sporesyringe"
	"fmt"
	"sync"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeGrainJar     = "GrainJar"
	TypeSporeSyringe = "SporeSyringe"
)

// GrainJarMutation represents an operation that mutates the GrainJar nodes in the graph.
type GrainJarMutation struct {
	config
	op                   Op
	typ                  string
	id                   *int
	_InnoculationDate    *time.Time
	_Grain               *string
	_HarvestDate         *time.Time
	clearedFields        map[string]struct{}
	sporeSyringes        *int
	clearedsporeSyringes bool
	done                 bool
	oldValue             func(context.Context) (*GrainJar, error)
	predicates           []predicate.GrainJar
}

var _ ent.Mutation = (*GrainJarMutation)(nil)

// grainjarOption allows management of the mutation configuration using functional options.
type grainjarOption func(*GrainJarMutation)

// newGrainJarMutation creates new mutation for the GrainJar entity.
func newGrainJarMutation(c config, op Op, opts ...grainjarOption) *GrainJarMutation {
	m := &GrainJarMutation{
		config:        c,
		op:            op,
		typ:           TypeGrainJar,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withGrainJarID sets the ID field of the mutation.
func withGrainJarID(id int) grainjarOption {
	return func(m *GrainJarMutation) {
		var (
			err   error
			once  sync.Once
			value *GrainJar
		)
		m.oldValue = func(ctx context.Context) (*GrainJar, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().GrainJar.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withGrainJar sets the old GrainJar of the mutation.
func withGrainJar(node *GrainJar) grainjarOption {
	return func(m *GrainJarMutation) {
		m.oldValue = func(context.Context) (*GrainJar, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m GrainJarMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m GrainJarMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *GrainJarMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *GrainJarMutation) IDs(ctx context.Context) ([]int, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().GrainJar.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetInnoculationDate sets the "InnoculationDate" field.
func (m *GrainJarMutation) SetInnoculationDate(t time.Time) {
	m._InnoculationDate = &t
}

// InnoculationDate returns the value of the "InnoculationDate" field in the mutation.
func (m *GrainJarMutation) InnoculationDate() (r time.Time, exists bool) {
	v := m._InnoculationDate
	if v == nil {
		return
	}
	return *v, true
}

// OldInnoculationDate returns the old "InnoculationDate" field's value of the GrainJar entity.
// If the GrainJar object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GrainJarMutation) OldInnoculationDate(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInnoculationDate is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInnoculationDate requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInnoculationDate: %w", err)
	}
	return oldValue.InnoculationDate, nil
}

// ResetInnoculationDate resets all changes to the "InnoculationDate" field.
func (m *GrainJarMutation) ResetInnoculationDate() {
	m._InnoculationDate = nil
}

// SetGrain sets the "Grain" field.
func (m *GrainJarMutation) SetGrain(s string) {
	m._Grain = &s
}

// Grain returns the value of the "Grain" field in the mutation.
func (m *GrainJarMutation) Grain() (r string, exists bool) {
	v := m._Grain
	if v == nil {
		return
	}
	return *v, true
}

// OldGrain returns the old "Grain" field's value of the GrainJar entity.
// If the GrainJar object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GrainJarMutation) OldGrain(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGrain is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGrain requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGrain: %w", err)
	}
	return oldValue.Grain, nil
}

// ResetGrain resets all changes to the "Grain" field.
func (m *GrainJarMutation) ResetGrain() {
	m._Grain = nil
}

// SetHarvestDate sets the "HarvestDate" field.
func (m *GrainJarMutation) SetHarvestDate(t time.Time) {
	m._HarvestDate = &t
}

// HarvestDate returns the value of the "HarvestDate" field in the mutation.
func (m *GrainJarMutation) HarvestDate() (r time.Time, exists bool) {
	v := m._HarvestDate
	if v == nil {
		return
	}
	return *v, true
}

// OldHarvestDate returns the old "HarvestDate" field's value of the GrainJar entity.
// If the GrainJar object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GrainJarMutation) OldHarvestDate(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldHarvestDate is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldHarvestDate requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldHarvestDate: %w", err)
	}
	return oldValue.HarvestDate, nil
}

// ClearHarvestDate clears the value of the "HarvestDate" field.
func (m *GrainJarMutation) ClearHarvestDate() {
	m._HarvestDate = nil
	m.clearedFields[grainjar.FieldHarvestDate] = struct{}{}
}

// HarvestDateCleared returns if the "HarvestDate" field was cleared in this mutation.
func (m *GrainJarMutation) HarvestDateCleared() bool {
	_, ok := m.clearedFields[grainjar.FieldHarvestDate]
	return ok
}

// ResetHarvestDate resets all changes to the "HarvestDate" field.
func (m *GrainJarMutation) ResetHarvestDate() {
	m._HarvestDate = nil
	delete(m.clearedFields, grainjar.FieldHarvestDate)
}

// SetSporeSyringesID sets the "sporeSyringes" edge to the SporeSyringe entity by id.
func (m *GrainJarMutation) SetSporeSyringesID(id int) {
	m.sporeSyringes = &id
}

// ClearSporeSyringes clears the "sporeSyringes" edge to the SporeSyringe entity.
func (m *GrainJarMutation) ClearSporeSyringes() {
	m.clearedsporeSyringes = true
}

// SporeSyringesCleared reports if the "sporeSyringes" edge to the SporeSyringe entity was cleared.
func (m *GrainJarMutation) SporeSyringesCleared() bool {
	return m.clearedsporeSyringes
}

// SporeSyringesID returns the "sporeSyringes" edge ID in the mutation.
func (m *GrainJarMutation) SporeSyringesID() (id int, exists bool) {
	if m.sporeSyringes != nil {
		return *m.sporeSyringes, true
	}
	return
}

// SporeSyringesIDs returns the "sporeSyringes" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SporeSyringesID instead. It exists only for internal usage by the builders.
func (m *GrainJarMutation) SporeSyringesIDs() (ids []int) {
	if id := m.sporeSyringes; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetSporeSyringes resets all changes to the "sporeSyringes" edge.
func (m *GrainJarMutation) ResetSporeSyringes() {
	m.sporeSyringes = nil
	m.clearedsporeSyringes = false
}

// Where appends a list predicates to the GrainJarMutation builder.
func (m *GrainJarMutation) Where(ps ...predicate.GrainJar) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the GrainJarMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *GrainJarMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.GrainJar, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *GrainJarMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *GrainJarMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (GrainJar).
func (m *GrainJarMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GrainJarMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m._InnoculationDate != nil {
		fields = append(fields, grainjar.FieldInnoculationDate)
	}
	if m._Grain != nil {
		fields = append(fields, grainjar.FieldGrain)
	}
	if m._HarvestDate != nil {
		fields = append(fields, grainjar.FieldHarvestDate)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *GrainJarMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case grainjar.FieldInnoculationDate:
		return m.InnoculationDate()
	case grainjar.FieldGrain:
		return m.Grain()
	case grainjar.FieldHarvestDate:
		return m.HarvestDate()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *GrainJarMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case grainjar.FieldInnoculationDate:
		return m.OldInnoculationDate(ctx)
	case grainjar.FieldGrain:
		return m.OldGrain(ctx)
	case grainjar.FieldHarvestDate:
		return m.OldHarvestDate(ctx)
	}
	return nil, fmt.Errorf("unknown GrainJar field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GrainJarMutation) SetField(name string, value ent.Value) error {
	switch name {
	case grainjar.FieldInnoculationDate:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInnoculationDate(v)
		return nil
	case grainjar.FieldGrain:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGrain(v)
		return nil
	case grainjar.FieldHarvestDate:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHarvestDate(v)
		return nil
	}
	return fmt.Errorf("unknown GrainJar field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *GrainJarMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *GrainJarMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GrainJarMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown GrainJar numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *GrainJarMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(grainjar.FieldHarvestDate) {
		fields = append(fields, grainjar.FieldHarvestDate)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GrainJarMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *GrainJarMutation) ClearField(name string) error {
	switch name {
	case grainjar.FieldHarvestDate:
		m.ClearHarvestDate()
		return nil
	}
	return fmt.Errorf("unknown GrainJar nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *GrainJarMutation) ResetField(name string) error {
	switch name {
	case grainjar.FieldInnoculationDate:
		m.ResetInnoculationDate()
		return nil
	case grainjar.FieldGrain:
		m.ResetGrain()
		return nil
	case grainjar.FieldHarvestDate:
		m.ResetHarvestDate()
		return nil
	}
	return fmt.Errorf("unknown GrainJar field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GrainJarMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.sporeSyringes != nil {
		edges = append(edges, grainjar.EdgeSporeSyringes)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *GrainJarMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case grainjar.EdgeSporeSyringes:
		if id := m.sporeSyringes; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GrainJarMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GrainJarMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GrainJarMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedsporeSyringes {
		edges = append(edges, grainjar.EdgeSporeSyringes)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GrainJarMutation) EdgeCleared(name string) bool {
	switch name {
	case grainjar.EdgeSporeSyringes:
		return m.clearedsporeSyringes
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *GrainJarMutation) ClearEdge(name string) error {
	switch name {
	case grainjar.EdgeSporeSyringes:
		m.ClearSporeSyringes()
		return nil
	}
	return fmt.Errorf("unknown GrainJar unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *GrainJarMutation) ResetEdge(name string) error {
	switch name {
	case grainjar.EdgeSporeSyringes:
		m.ResetSporeSyringes()
		return nil
	}
	return fmt.Errorf("unknown GrainJar edge %s", name)
}

// SporeSyringeMutation represents an operation that mutates the SporeSyringe nodes in the graph.
type SporeSyringeMutation struct {
	config
	op               Op
	typ              string
	id               *int
	_RecievedDate    *time.Time
	_Species         *string
	_Supplier        *string
	clearedFields    map[string]struct{}
	grainJars        map[int]struct{}
	removedgrainJars map[int]struct{}
	clearedgrainJars bool
	done             bool
	oldValue         func(context.Context) (*SporeSyringe, error)
	predicates       []predicate.SporeSyringe
}

var _ ent.Mutation = (*SporeSyringeMutation)(nil)

// sporesyringeOption allows management of the mutation configuration using functional options.
type sporesyringeOption func(*SporeSyringeMutation)

// newSporeSyringeMutation creates new mutation for the SporeSyringe entity.
func newSporeSyringeMutation(c config, op Op, opts ...sporesyringeOption) *SporeSyringeMutation {
	m := &SporeSyringeMutation{
		config:        c,
		op:            op,
		typ:           TypeSporeSyringe,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withSporeSyringeID sets the ID field of the mutation.
func withSporeSyringeID(id int) sporesyringeOption {
	return func(m *SporeSyringeMutation) {
		var (
			err   error
			once  sync.Once
			value *SporeSyringe
		)
		m.oldValue = func(ctx context.Context) (*SporeSyringe, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().SporeSyringe.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withSporeSyringe sets the old SporeSyringe of the mutation.
func withSporeSyringe(node *SporeSyringe) sporesyringeOption {
	return func(m *SporeSyringeMutation) {
		m.oldValue = func(context.Context) (*SporeSyringe, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m SporeSyringeMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m SporeSyringeMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SporeSyringeMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *SporeSyringeMutation) IDs(ctx context.Context) ([]int, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().SporeSyringe.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetRecievedDate sets the "RecievedDate" field.
func (m *SporeSyringeMutation) SetRecievedDate(t time.Time) {
	m._RecievedDate = &t
}

// RecievedDate returns the value of the "RecievedDate" field in the mutation.
func (m *SporeSyringeMutation) RecievedDate() (r time.Time, exists bool) {
	v := m._RecievedDate
	if v == nil {
		return
	}
	return *v, true
}

// OldRecievedDate returns the old "RecievedDate" field's value of the SporeSyringe entity.
// If the SporeSyringe object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SporeSyringeMutation) OldRecievedDate(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRecievedDate is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRecievedDate requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRecievedDate: %w", err)
	}
	return oldValue.RecievedDate, nil
}

// ResetRecievedDate resets all changes to the "RecievedDate" field.
func (m *SporeSyringeMutation) ResetRecievedDate() {
	m._RecievedDate = nil
}

// SetSpecies sets the "Species" field.
func (m *SporeSyringeMutation) SetSpecies(s string) {
	m._Species = &s
}

// Species returns the value of the "Species" field in the mutation.
func (m *SporeSyringeMutation) Species() (r string, exists bool) {
	v := m._Species
	if v == nil {
		return
	}
	return *v, true
}

// OldSpecies returns the old "Species" field's value of the SporeSyringe entity.
// If the SporeSyringe object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SporeSyringeMutation) OldSpecies(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSpecies is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSpecies requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSpecies: %w", err)
	}
	return oldValue.Species, nil
}

// ResetSpecies resets all changes to the "Species" field.
func (m *SporeSyringeMutation) ResetSpecies() {
	m._Species = nil
}

// SetSupplier sets the "Supplier" field.
func (m *SporeSyringeMutation) SetSupplier(s string) {
	m._Supplier = &s
}

// Supplier returns the value of the "Supplier" field in the mutation.
func (m *SporeSyringeMutation) Supplier() (r string, exists bool) {
	v := m._Supplier
	if v == nil {
		return
	}
	return *v, true
}

// OldSupplier returns the old "Supplier" field's value of the SporeSyringe entity.
// If the SporeSyringe object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SporeSyringeMutation) OldSupplier(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSupplier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSupplier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSupplier: %w", err)
	}
	return oldValue.Supplier, nil
}

// ResetSupplier resets all changes to the "Supplier" field.
func (m *SporeSyringeMutation) ResetSupplier() {
	m._Supplier = nil
}

// AddGrainJarIDs adds the "grainJars" edge to the GrainJar entity by ids.
func (m *SporeSyringeMutation) AddGrainJarIDs(ids ...int) {
	if m.grainJars == nil {
		m.grainJars = make(map[int]struct{})
	}
	for i := range ids {
		m.grainJars[ids[i]] = struct{}{}
	}
}

// ClearGrainJars clears the "grainJars" edge to the GrainJar entity.
func (m *SporeSyringeMutation) ClearGrainJars() {
	m.clearedgrainJars = true
}

// GrainJarsCleared reports if the "grainJars" edge to the GrainJar entity was cleared.
func (m *SporeSyringeMutation) GrainJarsCleared() bool {
	return m.clearedgrainJars
}

// RemoveGrainJarIDs removes the "grainJars" edge to the GrainJar entity by IDs.
func (m *SporeSyringeMutation) RemoveGrainJarIDs(ids ...int) {
	if m.removedgrainJars == nil {
		m.removedgrainJars = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.grainJars, ids[i])
		m.removedgrainJars[ids[i]] = struct{}{}
	}
}

// RemovedGrainJars returns the removed IDs of the "grainJars" edge to the GrainJar entity.
func (m *SporeSyringeMutation) RemovedGrainJarsIDs() (ids []int) {
	for id := range m.removedgrainJars {
		ids = append(ids, id)
	}
	return
}

// GrainJarsIDs returns the "grainJars" edge IDs in the mutation.
func (m *SporeSyringeMutation) GrainJarsIDs() (ids []int) {
	for id := range m.grainJars {
		ids = append(ids, id)
	}
	return
}

// ResetGrainJars resets all changes to the "grainJars" edge.
func (m *SporeSyringeMutation) ResetGrainJars() {
	m.grainJars = nil
	m.clearedgrainJars = false
	m.removedgrainJars = nil
}

// Where appends a list predicates to the SporeSyringeMutation builder.
func (m *SporeSyringeMutation) Where(ps ...predicate.SporeSyringe) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the SporeSyringeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SporeSyringeMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.SporeSyringe, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *SporeSyringeMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *SporeSyringeMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (SporeSyringe).
func (m *SporeSyringeMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *SporeSyringeMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m._RecievedDate != nil {
		fields = append(fields, sporesyringe.FieldRecievedDate)
	}
	if m._Species != nil {
		fields = append(fields, sporesyringe.FieldSpecies)
	}
	if m._Supplier != nil {
		fields = append(fields, sporesyringe.FieldSupplier)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *SporeSyringeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case sporesyringe.FieldRecievedDate:
		return m.RecievedDate()
	case sporesyringe.FieldSpecies:
		return m.Species()
	case sporesyringe.FieldSupplier:
		return m.Supplier()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *SporeSyringeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case sporesyringe.FieldRecievedDate:
		return m.OldRecievedDate(ctx)
	case sporesyringe.FieldSpecies:
		return m.OldSpecies(ctx)
	case sporesyringe.FieldSupplier:
		return m.OldSupplier(ctx)
	}
	return nil, fmt.Errorf("unknown SporeSyringe field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *SporeSyringeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case sporesyringe.FieldRecievedDate:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRecievedDate(v)
		return nil
	case sporesyringe.FieldSpecies:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSpecies(v)
		return nil
	case sporesyringe.FieldSupplier:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSupplier(v)
		return nil
	}
	return fmt.Errorf("unknown SporeSyringe field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SporeSyringeMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *SporeSyringeMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *SporeSyringeMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown SporeSyringe numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SporeSyringeMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SporeSyringeMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *SporeSyringeMutation) ClearField(name string) error {
	return fmt.Errorf("unknown SporeSyringe nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *SporeSyringeMutation) ResetField(name string) error {
	switch name {
	case sporesyringe.FieldRecievedDate:
		m.ResetRecievedDate()
		return nil
	case sporesyringe.FieldSpecies:
		m.ResetSpecies()
		return nil
	case sporesyringe.FieldSupplier:
		m.ResetSupplier()
		return nil
	}
	return fmt.Errorf("unknown SporeSyringe field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SporeSyringeMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.grainJars != nil {
		edges = append(edges, sporesyringe.EdgeGrainJars)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SporeSyringeMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case sporesyringe.EdgeGrainJars:
		ids := make([]ent.Value, 0, len(m.grainJars))
		for id := range m.grainJars {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SporeSyringeMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedgrainJars != nil {
		edges = append(edges, sporesyringe.EdgeGrainJars)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SporeSyringeMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case sporesyringe.EdgeGrainJars:
		ids := make([]ent.Value, 0, len(m.removedgrainJars))
		for id := range m.removedgrainJars {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SporeSyringeMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedgrainJars {
		edges = append(edges, sporesyringe.EdgeGrainJars)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SporeSyringeMutation) EdgeCleared(name string) bool {
	switch name {
	case sporesyringe.EdgeGrainJars:
		return m.clearedgrainJars
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SporeSyringeMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown SporeSyringe unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *SporeSyringeMutation) ResetEdge(name string) error {
	switch name {
	case sporesyringe.EdgeGrainJars:
		m.ResetGrainJars()
		return nil
	}
	return fmt.Errorf("unknown SporeSyringe edge %s", name)
}
