// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"sync"
	"time"

	"ariga.io/ogent/internal/integration/ogent/ent/alltypes"
	"ariga.io/ogent/internal/integration/ogent/ent/category"
	"ariga.io/ogent/internal/integration/ogent/ent/hat"
	"ariga.io/ogent/internal/integration/ogent/ent/pet"
	"ariga.io/ogent/internal/integration/ogent/ent/predicate"
	"ariga.io/ogent/internal/integration/ogent/ent/schema"
	"ariga.io/ogent/internal/integration/ogent/ent/user"
	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
)

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

	// Node types.
	TypeAllTypes = "AllTypes"
	TypeCategory = "Category"
	TypeHat      = "Hat"
	TypePet      = "Pet"
	TypeUser     = "User"
)

// AllTypesMutation represents an operation that mutates the AllTypes nodes in the graph.
type AllTypesMutation struct {
	config
	op            Op
	typ           string
	id            *uint32
	int           *int
	addint        *int
	int8          *int8
	addint8       *int8
	int16         *int16
	addint16      *int16
	int32         *int32
	addint32      *int32
	int64         *int64
	addint64      *int64
	uint          *uint
	adduint       *int
	uint8         *uint8
	adduint8      *int8
	uint16        *uint16
	adduint16     *int16
	uint32        *uint32
	adduint32     *int32
	uint64        *uint64
	adduint64     *int64
	float32       *float32
	addfloat32    *float32
	float64       *float64
	addfloat64    *float64
	string_type   *string
	bool          *bool
	uuid          *uuid.UUID
	time          *time.Time
	text          *string
	state         *alltypes.State
	bytes         *[]byte
	nilable       *string
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*AllTypes, error)
	predicates    []predicate.AllTypes
}

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

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

// newAllTypesMutation creates new mutation for the AllTypes entity.
func newAllTypesMutation(c config, op Op, opts ...alltypesOption) *AllTypesMutation {
	m := &AllTypesMutation{
		config:        c,
		op:            op,
		typ:           TypeAllTypes,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withAllTypes sets the old AllTypes of the mutation.
func withAllTypes(node *AllTypes) alltypesOption {
	return func(m *AllTypesMutation) {
		m.oldValue = func(context.Context) (*AllTypes, 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 AllTypesMutation) 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 AllTypesMutation) 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
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of AllTypes entities.
func (m *AllTypesMutation) SetID(id uint32) {
	m.id = &id
}

// 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 *AllTypesMutation) ID() (id uint32, 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 *AllTypesMutation) IDs(ctx context.Context) ([]uint32, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uint32{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().AllTypes.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetInt sets the "int" field.
func (m *AllTypesMutation) SetInt(i int) {
	m.int = &i
	m.addint = nil
}

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

// OldInt returns the old "int" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldInt(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInt: %w", err)
	}
	return oldValue.Int, nil
}

// AddInt adds i to the "int" field.
func (m *AllTypesMutation) AddInt(i int) {
	if m.addint != nil {
		*m.addint += i
	} else {
		m.addint = &i
	}
}

// AddedInt returns the value that was added to the "int" field in this mutation.
func (m *AllTypesMutation) AddedInt() (r int, exists bool) {
	v := m.addint
	if v == nil {
		return
	}
	return *v, true
}

// ResetInt resets all changes to the "int" field.
func (m *AllTypesMutation) ResetInt() {
	m.int = nil
	m.addint = nil
}

// SetInt8 sets the "int8" field.
func (m *AllTypesMutation) SetInt8(i int8) {
	m.int8 = &i
	m.addint8 = nil
}

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

// OldInt8 returns the old "int8" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldInt8(ctx context.Context) (v int8, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInt8 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInt8 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInt8: %w", err)
	}
	return oldValue.Int8, nil
}

// AddInt8 adds i to the "int8" field.
func (m *AllTypesMutation) AddInt8(i int8) {
	if m.addint8 != nil {
		*m.addint8 += i
	} else {
		m.addint8 = &i
	}
}

// AddedInt8 returns the value that was added to the "int8" field in this mutation.
func (m *AllTypesMutation) AddedInt8() (r int8, exists bool) {
	v := m.addint8
	if v == nil {
		return
	}
	return *v, true
}

// ResetInt8 resets all changes to the "int8" field.
func (m *AllTypesMutation) ResetInt8() {
	m.int8 = nil
	m.addint8 = nil
}

// SetInt16 sets the "int16" field.
func (m *AllTypesMutation) SetInt16(i int16) {
	m.int16 = &i
	m.addint16 = nil
}

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

// OldInt16 returns the old "int16" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldInt16(ctx context.Context) (v int16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInt16 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInt16 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInt16: %w", err)
	}
	return oldValue.Int16, nil
}

// AddInt16 adds i to the "int16" field.
func (m *AllTypesMutation) AddInt16(i int16) {
	if m.addint16 != nil {
		*m.addint16 += i
	} else {
		m.addint16 = &i
	}
}

// AddedInt16 returns the value that was added to the "int16" field in this mutation.
func (m *AllTypesMutation) AddedInt16() (r int16, exists bool) {
	v := m.addint16
	if v == nil {
		return
	}
	return *v, true
}

// ResetInt16 resets all changes to the "int16" field.
func (m *AllTypesMutation) ResetInt16() {
	m.int16 = nil
	m.addint16 = nil
}

// SetInt32 sets the "int32" field.
func (m *AllTypesMutation) SetInt32(i int32) {
	m.int32 = &i
	m.addint32 = nil
}

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

// OldInt32 returns the old "int32" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldInt32(ctx context.Context) (v int32, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInt32 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInt32 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInt32: %w", err)
	}
	return oldValue.Int32, nil
}

// AddInt32 adds i to the "int32" field.
func (m *AllTypesMutation) AddInt32(i int32) {
	if m.addint32 != nil {
		*m.addint32 += i
	} else {
		m.addint32 = &i
	}
}

// AddedInt32 returns the value that was added to the "int32" field in this mutation.
func (m *AllTypesMutation) AddedInt32() (r int32, exists bool) {
	v := m.addint32
	if v == nil {
		return
	}
	return *v, true
}

// ResetInt32 resets all changes to the "int32" field.
func (m *AllTypesMutation) ResetInt32() {
	m.int32 = nil
	m.addint32 = nil
}

// SetInt64 sets the "int64" field.
func (m *AllTypesMutation) SetInt64(i int64) {
	m.int64 = &i
	m.addint64 = nil
}

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

// OldInt64 returns the old "int64" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldInt64(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInt64 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInt64 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInt64: %w", err)
	}
	return oldValue.Int64, nil
}

// AddInt64 adds i to the "int64" field.
func (m *AllTypesMutation) AddInt64(i int64) {
	if m.addint64 != nil {
		*m.addint64 += i
	} else {
		m.addint64 = &i
	}
}

// AddedInt64 returns the value that was added to the "int64" field in this mutation.
func (m *AllTypesMutation) AddedInt64() (r int64, exists bool) {
	v := m.addint64
	if v == nil {
		return
	}
	return *v, true
}

// ResetInt64 resets all changes to the "int64" field.
func (m *AllTypesMutation) ResetInt64() {
	m.int64 = nil
	m.addint64 = nil
}

// SetUint sets the "uint" field.
func (m *AllTypesMutation) SetUint(u uint) {
	m.uint = &u
	m.adduint = nil
}

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

// OldUint returns the old "uint" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUint(ctx context.Context) (v uint, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUint is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUint requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUint: %w", err)
	}
	return oldValue.Uint, nil
}

// AddUint adds u to the "uint" field.
func (m *AllTypesMutation) AddUint(u int) {
	if m.adduint != nil {
		*m.adduint += u
	} else {
		m.adduint = &u
	}
}

// AddedUint returns the value that was added to the "uint" field in this mutation.
func (m *AllTypesMutation) AddedUint() (r int, exists bool) {
	v := m.adduint
	if v == nil {
		return
	}
	return *v, true
}

// ResetUint resets all changes to the "uint" field.
func (m *AllTypesMutation) ResetUint() {
	m.uint = nil
	m.adduint = nil
}

// SetUint8 sets the "uint8" field.
func (m *AllTypesMutation) SetUint8(u uint8) {
	m.uint8 = &u
	m.adduint8 = nil
}

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

// OldUint8 returns the old "uint8" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUint8(ctx context.Context) (v uint8, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUint8 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUint8 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUint8: %w", err)
	}
	return oldValue.Uint8, nil
}

// AddUint8 adds u to the "uint8" field.
func (m *AllTypesMutation) AddUint8(u int8) {
	if m.adduint8 != nil {
		*m.adduint8 += u
	} else {
		m.adduint8 = &u
	}
}

// AddedUint8 returns the value that was added to the "uint8" field in this mutation.
func (m *AllTypesMutation) AddedUint8() (r int8, exists bool) {
	v := m.adduint8
	if v == nil {
		return
	}
	return *v, true
}

// ResetUint8 resets all changes to the "uint8" field.
func (m *AllTypesMutation) ResetUint8() {
	m.uint8 = nil
	m.adduint8 = nil
}

// SetUint16 sets the "uint16" field.
func (m *AllTypesMutation) SetUint16(u uint16) {
	m.uint16 = &u
	m.adduint16 = nil
}

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

// OldUint16 returns the old "uint16" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUint16(ctx context.Context) (v uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUint16 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUint16 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUint16: %w", err)
	}
	return oldValue.Uint16, nil
}

// AddUint16 adds u to the "uint16" field.
func (m *AllTypesMutation) AddUint16(u int16) {
	if m.adduint16 != nil {
		*m.adduint16 += u
	} else {
		m.adduint16 = &u
	}
}

// AddedUint16 returns the value that was added to the "uint16" field in this mutation.
func (m *AllTypesMutation) AddedUint16() (r int16, exists bool) {
	v := m.adduint16
	if v == nil {
		return
	}
	return *v, true
}

// ResetUint16 resets all changes to the "uint16" field.
func (m *AllTypesMutation) ResetUint16() {
	m.uint16 = nil
	m.adduint16 = nil
}

// SetUint32 sets the "uint32" field.
func (m *AllTypesMutation) SetUint32(u uint32) {
	m.uint32 = &u
	m.adduint32 = nil
}

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

// OldUint32 returns the old "uint32" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUint32(ctx context.Context) (v uint32, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUint32 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUint32 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUint32: %w", err)
	}
	return oldValue.Uint32, nil
}

// AddUint32 adds u to the "uint32" field.
func (m *AllTypesMutation) AddUint32(u int32) {
	if m.adduint32 != nil {
		*m.adduint32 += u
	} else {
		m.adduint32 = &u
	}
}

// AddedUint32 returns the value that was added to the "uint32" field in this mutation.
func (m *AllTypesMutation) AddedUint32() (r int32, exists bool) {
	v := m.adduint32
	if v == nil {
		return
	}
	return *v, true
}

// ResetUint32 resets all changes to the "uint32" field.
func (m *AllTypesMutation) ResetUint32() {
	m.uint32 = nil
	m.adduint32 = nil
}

// SetUint64 sets the "uint64" field.
func (m *AllTypesMutation) SetUint64(u uint64) {
	m.uint64 = &u
	m.adduint64 = nil
}

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

// OldUint64 returns the old "uint64" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUint64(ctx context.Context) (v uint64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUint64 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUint64 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUint64: %w", err)
	}
	return oldValue.Uint64, nil
}

// AddUint64 adds u to the "uint64" field.
func (m *AllTypesMutation) AddUint64(u int64) {
	if m.adduint64 != nil {
		*m.adduint64 += u
	} else {
		m.adduint64 = &u
	}
}

// AddedUint64 returns the value that was added to the "uint64" field in this mutation.
func (m *AllTypesMutation) AddedUint64() (r int64, exists bool) {
	v := m.adduint64
	if v == nil {
		return
	}
	return *v, true
}

// ResetUint64 resets all changes to the "uint64" field.
func (m *AllTypesMutation) ResetUint64() {
	m.uint64 = nil
	m.adduint64 = nil
}

// SetFloat32 sets the "float32" field.
func (m *AllTypesMutation) SetFloat32(f float32) {
	m.float32 = &f
	m.addfloat32 = nil
}

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

// OldFloat32 returns the old "float32" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldFloat32(ctx context.Context) (v float32, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFloat32 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFloat32 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFloat32: %w", err)
	}
	return oldValue.Float32, nil
}

// AddFloat32 adds f to the "float32" field.
func (m *AllTypesMutation) AddFloat32(f float32) {
	if m.addfloat32 != nil {
		*m.addfloat32 += f
	} else {
		m.addfloat32 = &f
	}
}

// AddedFloat32 returns the value that was added to the "float32" field in this mutation.
func (m *AllTypesMutation) AddedFloat32() (r float32, exists bool) {
	v := m.addfloat32
	if v == nil {
		return
	}
	return *v, true
}

// ResetFloat32 resets all changes to the "float32" field.
func (m *AllTypesMutation) ResetFloat32() {
	m.float32 = nil
	m.addfloat32 = nil
}

// SetFloat64 sets the "float64" field.
func (m *AllTypesMutation) SetFloat64(f float64) {
	m.float64 = &f
	m.addfloat64 = nil
}

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

// OldFloat64 returns the old "float64" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldFloat64(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFloat64 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFloat64 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFloat64: %w", err)
	}
	return oldValue.Float64, nil
}

// AddFloat64 adds f to the "float64" field.
func (m *AllTypesMutation) AddFloat64(f float64) {
	if m.addfloat64 != nil {
		*m.addfloat64 += f
	} else {
		m.addfloat64 = &f
	}
}

// AddedFloat64 returns the value that was added to the "float64" field in this mutation.
func (m *AllTypesMutation) AddedFloat64() (r float64, exists bool) {
	v := m.addfloat64
	if v == nil {
		return
	}
	return *v, true
}

// ResetFloat64 resets all changes to the "float64" field.
func (m *AllTypesMutation) ResetFloat64() {
	m.float64 = nil
	m.addfloat64 = nil
}

// SetStringType sets the "string_type" field.
func (m *AllTypesMutation) SetStringType(s string) {
	m.string_type = &s
}

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

// OldStringType returns the old "string_type" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldStringType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStringType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStringType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStringType: %w", err)
	}
	return oldValue.StringType, nil
}

// ResetStringType resets all changes to the "string_type" field.
func (m *AllTypesMutation) ResetStringType() {
	m.string_type = nil
}

// SetBool sets the "bool" field.
func (m *AllTypesMutation) SetBool(b bool) {
	m.bool = &b
}

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

// OldBool returns the old "bool" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldBool(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBool is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBool requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBool: %w", err)
	}
	return oldValue.Bool, nil
}

// ResetBool resets all changes to the "bool" field.
func (m *AllTypesMutation) ResetBool() {
	m.bool = nil
}

// SetUUID sets the "uuid" field.
func (m *AllTypesMutation) SetUUID(u uuid.UUID) {
	m.uuid = &u
}

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

// OldUUID returns the old "uuid" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUUID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUUID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUUID: %w", err)
	}
	return oldValue.UUID, nil
}

// ResetUUID resets all changes to the "uuid" field.
func (m *AllTypesMutation) ResetUUID() {
	m.uuid = nil
}

// SetTime sets the "time" field.
func (m *AllTypesMutation) SetTime(t time.Time) {
	m.time = &t
}

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

// OldTime returns the old "time" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldTime(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTime is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTime requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTime: %w", err)
	}
	return oldValue.Time, nil
}

// ResetTime resets all changes to the "time" field.
func (m *AllTypesMutation) ResetTime() {
	m.time = nil
}

// SetText sets the "text" field.
func (m *AllTypesMutation) SetText(s string) {
	m.text = &s
}

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

// OldText returns the old "text" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldText(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldText is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldText requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldText: %w", err)
	}
	return oldValue.Text, nil
}

// ResetText resets all changes to the "text" field.
func (m *AllTypesMutation) ResetText() {
	m.text = nil
}

// SetState sets the "state" field.
func (m *AllTypesMutation) SetState(a alltypes.State) {
	m.state = &a
}

// State returns the value of the "state" field in the mutation.
func (m *AllTypesMutation) State() (r alltypes.State, exists bool) {
	v := m.state
	if v == nil {
		return
	}
	return *v, true
}

// OldState returns the old "state" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldState(ctx context.Context) (v alltypes.State, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldState is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldState requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldState: %w", err)
	}
	return oldValue.State, nil
}

// ResetState resets all changes to the "state" field.
func (m *AllTypesMutation) ResetState() {
	m.state = nil
}

// SetBytes sets the "bytes" field.
func (m *AllTypesMutation) SetBytes(b []byte) {
	m.bytes = &b
}

// Bytes returns the value of the "bytes" field in the mutation.
func (m *AllTypesMutation) Bytes() (r []byte, exists bool) {
	v := m.bytes
	if v == nil {
		return
	}
	return *v, true
}

// OldBytes returns the old "bytes" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldBytes(ctx context.Context) (v []byte, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBytes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBytes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBytes: %w", err)
	}
	return oldValue.Bytes, nil
}

// ResetBytes resets all changes to the "bytes" field.
func (m *AllTypesMutation) ResetBytes() {
	m.bytes = nil
}

// SetNilable sets the "nilable" field.
func (m *AllTypesMutation) SetNilable(s string) {
	m.nilable = &s
}

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

// OldNilable returns the old "nilable" field's value of the AllTypes entity.
// If the AllTypes 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 *AllTypesMutation) OldNilable(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNilable is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNilable requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNilable: %w", err)
	}
	return oldValue.Nilable, nil
}

// ResetNilable resets all changes to the "nilable" field.
func (m *AllTypesMutation) ResetNilable() {
	m.nilable = nil
}

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

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

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

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

// Type returns the node type of this mutation (AllTypes).
func (m *AllTypesMutation) 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 *AllTypesMutation) Fields() []string {
	fields := make([]string, 0, 20)
	if m.int != nil {
		fields = append(fields, alltypes.FieldInt)
	}
	if m.int8 != nil {
		fields = append(fields, alltypes.FieldInt8)
	}
	if m.int16 != nil {
		fields = append(fields, alltypes.FieldInt16)
	}
	if m.int32 != nil {
		fields = append(fields, alltypes.FieldInt32)
	}
	if m.int64 != nil {
		fields = append(fields, alltypes.FieldInt64)
	}
	if m.uint != nil {
		fields = append(fields, alltypes.FieldUint)
	}
	if m.uint8 != nil {
		fields = append(fields, alltypes.FieldUint8)
	}
	if m.uint16 != nil {
		fields = append(fields, alltypes.FieldUint16)
	}
	if m.uint32 != nil {
		fields = append(fields, alltypes.FieldUint32)
	}
	if m.uint64 != nil {
		fields = append(fields, alltypes.FieldUint64)
	}
	if m.float32 != nil {
		fields = append(fields, alltypes.FieldFloat32)
	}
	if m.float64 != nil {
		fields = append(fields, alltypes.FieldFloat64)
	}
	if m.string_type != nil {
		fields = append(fields, alltypes.FieldStringType)
	}
	if m.bool != nil {
		fields = append(fields, alltypes.FieldBool)
	}
	if m.uuid != nil {
		fields = append(fields, alltypes.FieldUUID)
	}
	if m.time != nil {
		fields = append(fields, alltypes.FieldTime)
	}
	if m.text != nil {
		fields = append(fields, alltypes.FieldText)
	}
	if m.state != nil {
		fields = append(fields, alltypes.FieldState)
	}
	if m.bytes != nil {
		fields = append(fields, alltypes.FieldBytes)
	}
	if m.nilable != nil {
		fields = append(fields, alltypes.FieldNilable)
	}
	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 *AllTypesMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case alltypes.FieldInt:
		return m.Int()
	case alltypes.FieldInt8:
		return m.Int8()
	case alltypes.FieldInt16:
		return m.Int16()
	case alltypes.FieldInt32:
		return m.Int32()
	case alltypes.FieldInt64:
		return m.Int64()
	case alltypes.FieldUint:
		return m.Uint()
	case alltypes.FieldUint8:
		return m.Uint8()
	case alltypes.FieldUint16:
		return m.Uint16()
	case alltypes.FieldUint32:
		return m.Uint32()
	case alltypes.FieldUint64:
		return m.Uint64()
	case alltypes.FieldFloat32:
		return m.Float32()
	case alltypes.FieldFloat64:
		return m.Float64()
	case alltypes.FieldStringType:
		return m.StringType()
	case alltypes.FieldBool:
		return m.Bool()
	case alltypes.FieldUUID:
		return m.UUID()
	case alltypes.FieldTime:
		return m.Time()
	case alltypes.FieldText:
		return m.Text()
	case alltypes.FieldState:
		return m.State()
	case alltypes.FieldBytes:
		return m.Bytes()
	case alltypes.FieldNilable:
		return m.Nilable()
	}
	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 *AllTypesMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case alltypes.FieldInt:
		return m.OldInt(ctx)
	case alltypes.FieldInt8:
		return m.OldInt8(ctx)
	case alltypes.FieldInt16:
		return m.OldInt16(ctx)
	case alltypes.FieldInt32:
		return m.OldInt32(ctx)
	case alltypes.FieldInt64:
		return m.OldInt64(ctx)
	case alltypes.FieldUint:
		return m.OldUint(ctx)
	case alltypes.FieldUint8:
		return m.OldUint8(ctx)
	case alltypes.FieldUint16:
		return m.OldUint16(ctx)
	case alltypes.FieldUint32:
		return m.OldUint32(ctx)
	case alltypes.FieldUint64:
		return m.OldUint64(ctx)
	case alltypes.FieldFloat32:
		return m.OldFloat32(ctx)
	case alltypes.FieldFloat64:
		return m.OldFloat64(ctx)
	case alltypes.FieldStringType:
		return m.OldStringType(ctx)
	case alltypes.FieldBool:
		return m.OldBool(ctx)
	case alltypes.FieldUUID:
		return m.OldUUID(ctx)
	case alltypes.FieldTime:
		return m.OldTime(ctx)
	case alltypes.FieldText:
		return m.OldText(ctx)
	case alltypes.FieldState:
		return m.OldState(ctx)
	case alltypes.FieldBytes:
		return m.OldBytes(ctx)
	case alltypes.FieldNilable:
		return m.OldNilable(ctx)
	}
	return nil, fmt.Errorf("unknown AllTypes 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 *AllTypesMutation) SetField(name string, value ent.Value) error {
	switch name {
	case alltypes.FieldInt:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInt(v)
		return nil
	case alltypes.FieldInt8:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInt8(v)
		return nil
	case alltypes.FieldInt16:
		v, ok := value.(int16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInt16(v)
		return nil
	case alltypes.FieldInt32:
		v, ok := value.(int32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInt32(v)
		return nil
	case alltypes.FieldInt64:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInt64(v)
		return nil
	case alltypes.FieldUint:
		v, ok := value.(uint)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUint(v)
		return nil
	case alltypes.FieldUint8:
		v, ok := value.(uint8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUint8(v)
		return nil
	case alltypes.FieldUint16:
		v, ok := value.(uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUint16(v)
		return nil
	case alltypes.FieldUint32:
		v, ok := value.(uint32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUint32(v)
		return nil
	case alltypes.FieldUint64:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUint64(v)
		return nil
	case alltypes.FieldFloat32:
		v, ok := value.(float32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFloat32(v)
		return nil
	case alltypes.FieldFloat64:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFloat64(v)
		return nil
	case alltypes.FieldStringType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStringType(v)
		return nil
	case alltypes.FieldBool:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBool(v)
		return nil
	case alltypes.FieldUUID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUUID(v)
		return nil
	case alltypes.FieldTime:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTime(v)
		return nil
	case alltypes.FieldText:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetText(v)
		return nil
	case alltypes.FieldState:
		v, ok := value.(alltypes.State)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetState(v)
		return nil
	case alltypes.FieldBytes:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBytes(v)
		return nil
	case alltypes.FieldNilable:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNilable(v)
		return nil
	}
	return fmt.Errorf("unknown AllTypes field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AllTypesMutation) AddedFields() []string {
	var fields []string
	if m.addint != nil {
		fields = append(fields, alltypes.FieldInt)
	}
	if m.addint8 != nil {
		fields = append(fields, alltypes.FieldInt8)
	}
	if m.addint16 != nil {
		fields = append(fields, alltypes.FieldInt16)
	}
	if m.addint32 != nil {
		fields = append(fields, alltypes.FieldInt32)
	}
	if m.addint64 != nil {
		fields = append(fields, alltypes.FieldInt64)
	}
	if m.adduint != nil {
		fields = append(fields, alltypes.FieldUint)
	}
	if m.adduint8 != nil {
		fields = append(fields, alltypes.FieldUint8)
	}
	if m.adduint16 != nil {
		fields = append(fields, alltypes.FieldUint16)
	}
	if m.adduint32 != nil {
		fields = append(fields, alltypes.FieldUint32)
	}
	if m.adduint64 != nil {
		fields = append(fields, alltypes.FieldUint64)
	}
	if m.addfloat32 != nil {
		fields = append(fields, alltypes.FieldFloat32)
	}
	if m.addfloat64 != nil {
		fields = append(fields, alltypes.FieldFloat64)
	}
	return fields
}

// 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 *AllTypesMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case alltypes.FieldInt:
		return m.AddedInt()
	case alltypes.FieldInt8:
		return m.AddedInt8()
	case alltypes.FieldInt16:
		return m.AddedInt16()
	case alltypes.FieldInt32:
		return m.AddedInt32()
	case alltypes.FieldInt64:
		return m.AddedInt64()
	case alltypes.FieldUint:
		return m.AddedUint()
	case alltypes.FieldUint8:
		return m.AddedUint8()
	case alltypes.FieldUint16:
		return m.AddedUint16()
	case alltypes.FieldUint32:
		return m.AddedUint32()
	case alltypes.FieldUint64:
		return m.AddedUint64()
	case alltypes.FieldFloat32:
		return m.AddedFloat32()
	case alltypes.FieldFloat64:
		return m.AddedFloat64()
	}
	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 *AllTypesMutation) AddField(name string, value ent.Value) error {
	switch name {
	case alltypes.FieldInt:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInt(v)
		return nil
	case alltypes.FieldInt8:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInt8(v)
		return nil
	case alltypes.FieldInt16:
		v, ok := value.(int16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInt16(v)
		return nil
	case alltypes.FieldInt32:
		v, ok := value.(int32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInt32(v)
		return nil
	case alltypes.FieldInt64:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInt64(v)
		return nil
	case alltypes.FieldUint:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUint(v)
		return nil
	case alltypes.FieldUint8:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUint8(v)
		return nil
	case alltypes.FieldUint16:
		v, ok := value.(int16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUint16(v)
		return nil
	case alltypes.FieldUint32:
		v, ok := value.(int32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUint32(v)
		return nil
	case alltypes.FieldUint64:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUint64(v)
		return nil
	case alltypes.FieldFloat32:
		v, ok := value.(float32)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFloat32(v)
		return nil
	case alltypes.FieldFloat64:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFloat64(v)
		return nil
	}
	return fmt.Errorf("unknown AllTypes numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AllTypesMutation) 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 *AllTypesMutation) ClearField(name string) error {
	return fmt.Errorf("unknown AllTypes 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 *AllTypesMutation) ResetField(name string) error {
	switch name {
	case alltypes.FieldInt:
		m.ResetInt()
		return nil
	case alltypes.FieldInt8:
		m.ResetInt8()
		return nil
	case alltypes.FieldInt16:
		m.ResetInt16()
		return nil
	case alltypes.FieldInt32:
		m.ResetInt32()
		return nil
	case alltypes.FieldInt64:
		m.ResetInt64()
		return nil
	case alltypes.FieldUint:
		m.ResetUint()
		return nil
	case alltypes.FieldUint8:
		m.ResetUint8()
		return nil
	case alltypes.FieldUint16:
		m.ResetUint16()
		return nil
	case alltypes.FieldUint32:
		m.ResetUint32()
		return nil
	case alltypes.FieldUint64:
		m.ResetUint64()
		return nil
	case alltypes.FieldFloat32:
		m.ResetFloat32()
		return nil
	case alltypes.FieldFloat64:
		m.ResetFloat64()
		return nil
	case alltypes.FieldStringType:
		m.ResetStringType()
		return nil
	case alltypes.FieldBool:
		m.ResetBool()
		return nil
	case alltypes.FieldUUID:
		m.ResetUUID()
		return nil
	case alltypes.FieldTime:
		m.ResetTime()
		return nil
	case alltypes.FieldText:
		m.ResetText()
		return nil
	case alltypes.FieldState:
		m.ResetState()
		return nil
	case alltypes.FieldBytes:
		m.ResetBytes()
		return nil
	case alltypes.FieldNilable:
		m.ResetNilable()
		return nil
	}
	return fmt.Errorf("unknown AllTypes field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AllTypesMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AllTypesMutation) EdgeCleared(name string) bool {
	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 *AllTypesMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown AllTypes 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 *AllTypesMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown AllTypes edge %s", name)
}

// CategoryMutation represents an operation that mutates the Category nodes in the graph.
type CategoryMutation struct {
	config
	op            Op
	typ           string
	id            *int
	name          *string
	readonly      *string
	clearedFields map[string]struct{}
	pets          map[int]struct{}
	removedpets   map[int]struct{}
	clearedpets   bool
	done          bool
	oldValue      func(context.Context) (*Category, error)
	predicates    []predicate.Category
}

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

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

// newCategoryMutation creates new mutation for the Category entity.
func newCategoryMutation(c config, op Op, opts ...categoryOption) *CategoryMutation {
	m := &CategoryMutation{
		config:        c,
		op:            op,
		typ:           TypeCategory,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withCategory sets the old Category of the mutation.
func withCategory(node *Category) categoryOption {
	return func(m *CategoryMutation) {
		m.oldValue = func(context.Context) (*Category, 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 CategoryMutation) 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 CategoryMutation) 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 *CategoryMutation) 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 *CategoryMutation) 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().Category.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *CategoryMutation) SetName(s string) {
	m.name = &s
}

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

// OldName returns the old "name" field's value of the Category entity.
// If the Category 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 *CategoryMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *CategoryMutation) ResetName() {
	m.name = nil
}

// SetReadonly sets the "readonly" field.
func (m *CategoryMutation) SetReadonly(s string) {
	m.readonly = &s
}

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

// OldReadonly returns the old "readonly" field's value of the Category entity.
// If the Category 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 *CategoryMutation) OldReadonly(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldReadonly is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldReadonly requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldReadonly: %w", err)
	}
	return oldValue.Readonly, nil
}

// ClearReadonly clears the value of the "readonly" field.
func (m *CategoryMutation) ClearReadonly() {
	m.readonly = nil
	m.clearedFields[category.FieldReadonly] = struct{}{}
}

// ReadonlyCleared returns if the "readonly" field was cleared in this mutation.
func (m *CategoryMutation) ReadonlyCleared() bool {
	_, ok := m.clearedFields[category.FieldReadonly]
	return ok
}

// ResetReadonly resets all changes to the "readonly" field.
func (m *CategoryMutation) ResetReadonly() {
	m.readonly = nil
	delete(m.clearedFields, category.FieldReadonly)
}

// AddPetIDs adds the "pets" edge to the Pet entity by ids.
func (m *CategoryMutation) AddPetIDs(ids ...int) {
	if m.pets == nil {
		m.pets = make(map[int]struct{})
	}
	for i := range ids {
		m.pets[ids[i]] = struct{}{}
	}
}

// ClearPets clears the "pets" edge to the Pet entity.
func (m *CategoryMutation) ClearPets() {
	m.clearedpets = true
}

// PetsCleared reports if the "pets" edge to the Pet entity was cleared.
func (m *CategoryMutation) PetsCleared() bool {
	return m.clearedpets
}

// RemovePetIDs removes the "pets" edge to the Pet entity by IDs.
func (m *CategoryMutation) RemovePetIDs(ids ...int) {
	if m.removedpets == nil {
		m.removedpets = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.pets, ids[i])
		m.removedpets[ids[i]] = struct{}{}
	}
}

// RemovedPets returns the removed IDs of the "pets" edge to the Pet entity.
func (m *CategoryMutation) RemovedPetsIDs() (ids []int) {
	for id := range m.removedpets {
		ids = append(ids, id)
	}
	return
}

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

// ResetPets resets all changes to the "pets" edge.
func (m *CategoryMutation) ResetPets() {
	m.pets = nil
	m.clearedpets = false
	m.removedpets = nil
}

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

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

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

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

// Type returns the node type of this mutation (Category).
func (m *CategoryMutation) 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 *CategoryMutation) Fields() []string {
	fields := make([]string, 0, 2)
	if m.name != nil {
		fields = append(fields, category.FieldName)
	}
	if m.readonly != nil {
		fields = append(fields, category.FieldReadonly)
	}
	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 *CategoryMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case category.FieldName:
		return m.Name()
	case category.FieldReadonly:
		return m.Readonly()
	}
	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 *CategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case category.FieldName:
		return m.OldName(ctx)
	case category.FieldReadonly:
		return m.OldReadonly(ctx)
	}
	return nil, fmt.Errorf("unknown Category 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 *CategoryMutation) SetField(name string, value ent.Value) error {
	switch name {
	case category.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case category.FieldReadonly:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReadonly(v)
		return nil
	}
	return fmt.Errorf("unknown Category field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CategoryMutation) 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 *CategoryMutation) 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 *CategoryMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Category numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CategoryMutation) 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 *CategoryMutation) ClearField(name string) error {
	switch name {
	case category.FieldReadonly:
		m.ClearReadonly()
		return nil
	}
	return fmt.Errorf("unknown Category 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 *CategoryMutation) ResetField(name string) error {
	switch name {
	case category.FieldName:
		m.ResetName()
		return nil
	case category.FieldReadonly:
		m.ResetReadonly()
		return nil
	}
	return fmt.Errorf("unknown Category field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CategoryMutation) EdgeCleared(name string) bool {
	switch name {
	case category.EdgePets:
		return m.clearedpets
	}
	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 *CategoryMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Category 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 *CategoryMutation) ResetEdge(name string) error {
	switch name {
	case category.EdgePets:
		m.ResetPets()
		return nil
	}
	return fmt.Errorf("unknown Category edge %s", name)
}

// HatMutation represents an operation that mutates the Hat nodes in the graph.
type HatMutation struct {
	config
	op            Op
	typ           string
	id            *int
	name          *string
	_type         *hat.Type
	clearedFields map[string]struct{}
	wearer        *int
	clearedwearer bool
	done          bool
	oldValue      func(context.Context) (*Hat, error)
	predicates    []predicate.Hat
}

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

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

// newHatMutation creates new mutation for the Hat entity.
func newHatMutation(c config, op Op, opts ...hatOption) *HatMutation {
	m := &HatMutation{
		config:        c,
		op:            op,
		typ:           TypeHat,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withHat sets the old Hat of the mutation.
func withHat(node *Hat) hatOption {
	return func(m *HatMutation) {
		m.oldValue = func(context.Context) (*Hat, 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 HatMutation) 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 HatMutation) 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 *HatMutation) 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 *HatMutation) 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().Hat.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *HatMutation) SetName(s string) {
	m.name = &s
}

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

// OldName returns the old "name" field's value of the Hat entity.
// If the Hat 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 *HatMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *HatMutation) ResetName() {
	m.name = nil
}

// SetType sets the "type" field.
func (m *HatMutation) SetType(h hat.Type) {
	m._type = &h
}

// GetType returns the value of the "type" field in the mutation.
func (m *HatMutation) GetType() (r hat.Type, exists bool) {
	v := m._type
	if v == nil {
		return
	}
	return *v, true
}

// OldType returns the old "type" field's value of the Hat entity.
// If the Hat 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 *HatMutation) OldType(ctx context.Context) (v hat.Type, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldType: %w", err)
	}
	return oldValue.Type, nil
}

// ResetType resets all changes to the "type" field.
func (m *HatMutation) ResetType() {
	m._type = nil
}

// SetWearerID sets the "wearer" edge to the User entity by id.
func (m *HatMutation) SetWearerID(id int) {
	m.wearer = &id
}

// ClearWearer clears the "wearer" edge to the User entity.
func (m *HatMutation) ClearWearer() {
	m.clearedwearer = true
}

// WearerCleared reports if the "wearer" edge to the User entity was cleared.
func (m *HatMutation) WearerCleared() bool {
	return m.clearedwearer
}

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

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

// ResetWearer resets all changes to the "wearer" edge.
func (m *HatMutation) ResetWearer() {
	m.wearer = nil
	m.clearedwearer = false
}

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

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

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

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

// Type returns the node type of this mutation (Hat).
func (m *HatMutation) 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 *HatMutation) Fields() []string {
	fields := make([]string, 0, 2)
	if m.name != nil {
		fields = append(fields, hat.FieldName)
	}
	if m._type != nil {
		fields = append(fields, hat.FieldType)
	}
	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 *HatMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case hat.FieldName:
		return m.Name()
	case hat.FieldType:
		return m.GetType()
	}
	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 *HatMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case hat.FieldName:
		return m.OldName(ctx)
	case hat.FieldType:
		return m.OldType(ctx)
	}
	return nil, fmt.Errorf("unknown Hat 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 *HatMutation) SetField(name string, value ent.Value) error {
	switch name {
	case hat.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case hat.FieldType:
		v, ok := value.(hat.Type)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	}
	return fmt.Errorf("unknown Hat field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *HatMutation) 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 *HatMutation) 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 *HatMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Hat numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *HatMutation) 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 *HatMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Hat 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 *HatMutation) ResetField(name string) error {
	switch name {
	case hat.FieldName:
		m.ResetName()
		return nil
	case hat.FieldType:
		m.ResetType()
		return nil
	}
	return fmt.Errorf("unknown Hat field %s", name)
}

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

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

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *HatMutation) 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 *HatMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *HatMutation) EdgeCleared(name string) bool {
	switch name {
	case hat.EdgeWearer:
		return m.clearedwearer
	}
	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 *HatMutation) ClearEdge(name string) error {
	switch name {
	case hat.EdgeWearer:
		m.ClearWearer()
		return nil
	}
	return fmt.Errorf("unknown Hat 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 *HatMutation) ResetEdge(name string) error {
	switch name {
	case hat.EdgeWearer:
		m.ResetWearer()
		return nil
	}
	return fmt.Errorf("unknown Hat edge %s", name)
}

// PetMutation represents an operation that mutates the Pet nodes in the graph.
type PetMutation struct {
	config
	op                Op
	typ               string
	id                *int
	name              *string
	weight            *int
	addweight         *int
	birthday          *time.Time
	tag_id            *[]byte
	height            *int
	addheight         *int
	clearedFields     map[string]struct{}
	categories        map[int]struct{}
	removedcategories map[int]struct{}
	clearedcategories bool
	owner             *int
	clearedowner      bool
	rescuer           map[int]struct{}
	removedrescuer    map[int]struct{}
	clearedrescuer    bool
	friends           map[int]struct{}
	removedfriends    map[int]struct{}
	clearedfriends    bool
	done              bool
	oldValue          func(context.Context) (*Pet, error)
	predicates        []predicate.Pet
}

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

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

// newPetMutation creates new mutation for the Pet entity.
func newPetMutation(c config, op Op, opts ...petOption) *PetMutation {
	m := &PetMutation{
		config:        c,
		op:            op,
		typ:           TypePet,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withPet sets the old Pet of the mutation.
func withPet(node *Pet) petOption {
	return func(m *PetMutation) {
		m.oldValue = func(context.Context) (*Pet, 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 PetMutation) 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 PetMutation) 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 *PetMutation) 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 *PetMutation) 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().Pet.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *PetMutation) SetName(s string) {
	m.name = &s
}

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

// OldName returns the old "name" field's value of the Pet entity.
// If the Pet 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 *PetMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *PetMutation) ResetName() {
	m.name = nil
}

// SetWeight sets the "weight" field.
func (m *PetMutation) SetWeight(i int) {
	m.weight = &i
	m.addweight = nil
}

// Weight returns the value of the "weight" field in the mutation.
func (m *PetMutation) Weight() (r int, exists bool) {
	v := m.weight
	if v == nil {
		return
	}
	return *v, true
}

// OldWeight returns the old "weight" field's value of the Pet entity.
// If the Pet 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 *PetMutation) OldWeight(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeight is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeight requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeight: %w", err)
	}
	return oldValue.Weight, nil
}

// AddWeight adds i to the "weight" field.
func (m *PetMutation) AddWeight(i int) {
	if m.addweight != nil {
		*m.addweight += i
	} else {
		m.addweight = &i
	}
}

// AddedWeight returns the value that was added to the "weight" field in this mutation.
func (m *PetMutation) AddedWeight() (r int, exists bool) {
	v := m.addweight
	if v == nil {
		return
	}
	return *v, true
}

// ClearWeight clears the value of the "weight" field.
func (m *PetMutation) ClearWeight() {
	m.weight = nil
	m.addweight = nil
	m.clearedFields[pet.FieldWeight] = struct{}{}
}

// WeightCleared returns if the "weight" field was cleared in this mutation.
func (m *PetMutation) WeightCleared() bool {
	_, ok := m.clearedFields[pet.FieldWeight]
	return ok
}

// ResetWeight resets all changes to the "weight" field.
func (m *PetMutation) ResetWeight() {
	m.weight = nil
	m.addweight = nil
	delete(m.clearedFields, pet.FieldWeight)
}

// SetBirthday sets the "birthday" field.
func (m *PetMutation) SetBirthday(t time.Time) {
	m.birthday = &t
}

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

// OldBirthday returns the old "birthday" field's value of the Pet entity.
// If the Pet 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 *PetMutation) OldBirthday(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBirthday is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBirthday requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBirthday: %w", err)
	}
	return oldValue.Birthday, nil
}

// ClearBirthday clears the value of the "birthday" field.
func (m *PetMutation) ClearBirthday() {
	m.birthday = nil
	m.clearedFields[pet.FieldBirthday] = struct{}{}
}

// BirthdayCleared returns if the "birthday" field was cleared in this mutation.
func (m *PetMutation) BirthdayCleared() bool {
	_, ok := m.clearedFields[pet.FieldBirthday]
	return ok
}

// ResetBirthday resets all changes to the "birthday" field.
func (m *PetMutation) ResetBirthday() {
	m.birthday = nil
	delete(m.clearedFields, pet.FieldBirthday)
}

// SetTagID sets the "tag_id" field.
func (m *PetMutation) SetTagID(b []byte) {
	m.tag_id = &b
}

// TagID returns the value of the "tag_id" field in the mutation.
func (m *PetMutation) TagID() (r []byte, exists bool) {
	v := m.tag_id
	if v == nil {
		return
	}
	return *v, true
}

// OldTagID returns the old "tag_id" field's value of the Pet entity.
// If the Pet 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 *PetMutation) OldTagID(ctx context.Context) (v []byte, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTagID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTagID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTagID: %w", err)
	}
	return oldValue.TagID, nil
}

// ClearTagID clears the value of the "tag_id" field.
func (m *PetMutation) ClearTagID() {
	m.tag_id = nil
	m.clearedFields[pet.FieldTagID] = struct{}{}
}

// TagIDCleared returns if the "tag_id" field was cleared in this mutation.
func (m *PetMutation) TagIDCleared() bool {
	_, ok := m.clearedFields[pet.FieldTagID]
	return ok
}

// ResetTagID resets all changes to the "tag_id" field.
func (m *PetMutation) ResetTagID() {
	m.tag_id = nil
	delete(m.clearedFields, pet.FieldTagID)
}

// SetHeight sets the "height" field.
func (m *PetMutation) SetHeight(i int) {
	m.height = &i
	m.addheight = nil
}

// Height returns the value of the "height" field in the mutation.
func (m *PetMutation) Height() (r int, exists bool) {
	v := m.height
	if v == nil {
		return
	}
	return *v, true
}

// OldHeight returns the old "height" field's value of the Pet entity.
// If the Pet 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 *PetMutation) OldHeight(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldHeight is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldHeight requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldHeight: %w", err)
	}
	return oldValue.Height, nil
}

// AddHeight adds i to the "height" field.
func (m *PetMutation) AddHeight(i int) {
	if m.addheight != nil {
		*m.addheight += i
	} else {
		m.addheight = &i
	}
}

// AddedHeight returns the value that was added to the "height" field in this mutation.
func (m *PetMutation) AddedHeight() (r int, exists bool) {
	v := m.addheight
	if v == nil {
		return
	}
	return *v, true
}

// ClearHeight clears the value of the "height" field.
func (m *PetMutation) ClearHeight() {
	m.height = nil
	m.addheight = nil
	m.clearedFields[pet.FieldHeight] = struct{}{}
}

// HeightCleared returns if the "height" field was cleared in this mutation.
func (m *PetMutation) HeightCleared() bool {
	_, ok := m.clearedFields[pet.FieldHeight]
	return ok
}

// ResetHeight resets all changes to the "height" field.
func (m *PetMutation) ResetHeight() {
	m.height = nil
	m.addheight = nil
	delete(m.clearedFields, pet.FieldHeight)
}

// AddCategoryIDs adds the "categories" edge to the Category entity by ids.
func (m *PetMutation) AddCategoryIDs(ids ...int) {
	if m.categories == nil {
		m.categories = make(map[int]struct{})
	}
	for i := range ids {
		m.categories[ids[i]] = struct{}{}
	}
}

// ClearCategories clears the "categories" edge to the Category entity.
func (m *PetMutation) ClearCategories() {
	m.clearedcategories = true
}

// CategoriesCleared reports if the "categories" edge to the Category entity was cleared.
func (m *PetMutation) CategoriesCleared() bool {
	return m.clearedcategories
}

// RemoveCategoryIDs removes the "categories" edge to the Category entity by IDs.
func (m *PetMutation) RemoveCategoryIDs(ids ...int) {
	if m.removedcategories == nil {
		m.removedcategories = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.categories, ids[i])
		m.removedcategories[ids[i]] = struct{}{}
	}
}

// RemovedCategories returns the removed IDs of the "categories" edge to the Category entity.
func (m *PetMutation) RemovedCategoriesIDs() (ids []int) {
	for id := range m.removedcategories {
		ids = append(ids, id)
	}
	return
}

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

// ResetCategories resets all changes to the "categories" edge.
func (m *PetMutation) ResetCategories() {
	m.categories = nil
	m.clearedcategories = false
	m.removedcategories = nil
}

// SetOwnerID sets the "owner" edge to the User entity by id.
func (m *PetMutation) SetOwnerID(id int) {
	m.owner = &id
}

// ClearOwner clears the "owner" edge to the User entity.
func (m *PetMutation) ClearOwner() {
	m.clearedowner = true
}

// OwnerCleared reports if the "owner" edge to the User entity was cleared.
func (m *PetMutation) OwnerCleared() bool {
	return m.clearedowner
}

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

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

// ResetOwner resets all changes to the "owner" edge.
func (m *PetMutation) ResetOwner() {
	m.owner = nil
	m.clearedowner = false
}

// AddRescuerIDs adds the "rescuer" edge to the User entity by ids.
func (m *PetMutation) AddRescuerIDs(ids ...int) {
	if m.rescuer == nil {
		m.rescuer = make(map[int]struct{})
	}
	for i := range ids {
		m.rescuer[ids[i]] = struct{}{}
	}
}

// ClearRescuer clears the "rescuer" edge to the User entity.
func (m *PetMutation) ClearRescuer() {
	m.clearedrescuer = true
}

// RescuerCleared reports if the "rescuer" edge to the User entity was cleared.
func (m *PetMutation) RescuerCleared() bool {
	return m.clearedrescuer
}

// RemoveRescuerIDs removes the "rescuer" edge to the User entity by IDs.
func (m *PetMutation) RemoveRescuerIDs(ids ...int) {
	if m.removedrescuer == nil {
		m.removedrescuer = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.rescuer, ids[i])
		m.removedrescuer[ids[i]] = struct{}{}
	}
}

// RemovedRescuer returns the removed IDs of the "rescuer" edge to the User entity.
func (m *PetMutation) RemovedRescuerIDs() (ids []int) {
	for id := range m.removedrescuer {
		ids = append(ids, id)
	}
	return
}

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

// ResetRescuer resets all changes to the "rescuer" edge.
func (m *PetMutation) ResetRescuer() {
	m.rescuer = nil
	m.clearedrescuer = false
	m.removedrescuer = nil
}

// AddFriendIDs adds the "friends" edge to the Pet entity by ids.
func (m *PetMutation) AddFriendIDs(ids ...int) {
	if m.friends == nil {
		m.friends = make(map[int]struct{})
	}
	for i := range ids {
		m.friends[ids[i]] = struct{}{}
	}
}

// ClearFriends clears the "friends" edge to the Pet entity.
func (m *PetMutation) ClearFriends() {
	m.clearedfriends = true
}

// FriendsCleared reports if the "friends" edge to the Pet entity was cleared.
func (m *PetMutation) FriendsCleared() bool {
	return m.clearedfriends
}

// RemoveFriendIDs removes the "friends" edge to the Pet entity by IDs.
func (m *PetMutation) RemoveFriendIDs(ids ...int) {
	if m.removedfriends == nil {
		m.removedfriends = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.friends, ids[i])
		m.removedfriends[ids[i]] = struct{}{}
	}
}

// RemovedFriends returns the removed IDs of the "friends" edge to the Pet entity.
func (m *PetMutation) RemovedFriendsIDs() (ids []int) {
	for id := range m.removedfriends {
		ids = append(ids, id)
	}
	return
}

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

// ResetFriends resets all changes to the "friends" edge.
func (m *PetMutation) ResetFriends() {
	m.friends = nil
	m.clearedfriends = false
	m.removedfriends = nil
}

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

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

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

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

// Type returns the node type of this mutation (Pet).
func (m *PetMutation) 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 *PetMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.name != nil {
		fields = append(fields, pet.FieldName)
	}
	if m.weight != nil {
		fields = append(fields, pet.FieldWeight)
	}
	if m.birthday != nil {
		fields = append(fields, pet.FieldBirthday)
	}
	if m.tag_id != nil {
		fields = append(fields, pet.FieldTagID)
	}
	if m.height != nil {
		fields = append(fields, pet.FieldHeight)
	}
	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 *PetMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case pet.FieldName:
		return m.Name()
	case pet.FieldWeight:
		return m.Weight()
	case pet.FieldBirthday:
		return m.Birthday()
	case pet.FieldTagID:
		return m.TagID()
	case pet.FieldHeight:
		return m.Height()
	}
	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 *PetMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case pet.FieldName:
		return m.OldName(ctx)
	case pet.FieldWeight:
		return m.OldWeight(ctx)
	case pet.FieldBirthday:
		return m.OldBirthday(ctx)
	case pet.FieldTagID:
		return m.OldTagID(ctx)
	case pet.FieldHeight:
		return m.OldHeight(ctx)
	}
	return nil, fmt.Errorf("unknown Pet 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 *PetMutation) SetField(name string, value ent.Value) error {
	switch name {
	case pet.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case pet.FieldWeight:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeight(v)
		return nil
	case pet.FieldBirthday:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBirthday(v)
		return nil
	case pet.FieldTagID:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTagID(v)
		return nil
	case pet.FieldHeight:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHeight(v)
		return nil
	}
	return fmt.Errorf("unknown Pet field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PetMutation) AddedFields() []string {
	var fields []string
	if m.addweight != nil {
		fields = append(fields, pet.FieldWeight)
	}
	if m.addheight != nil {
		fields = append(fields, pet.FieldHeight)
	}
	return fields
}

// 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 *PetMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case pet.FieldWeight:
		return m.AddedWeight()
	case pet.FieldHeight:
		return m.AddedHeight()
	}
	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 *PetMutation) AddField(name string, value ent.Value) error {
	switch name {
	case pet.FieldWeight:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddWeight(v)
		return nil
	case pet.FieldHeight:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddHeight(v)
		return nil
	}
	return fmt.Errorf("unknown Pet numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PetMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(pet.FieldWeight) {
		fields = append(fields, pet.FieldWeight)
	}
	if m.FieldCleared(pet.FieldBirthday) {
		fields = append(fields, pet.FieldBirthday)
	}
	if m.FieldCleared(pet.FieldTagID) {
		fields = append(fields, pet.FieldTagID)
	}
	if m.FieldCleared(pet.FieldHeight) {
		fields = append(fields, pet.FieldHeight)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PetMutation) 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 *PetMutation) ClearField(name string) error {
	switch name {
	case pet.FieldWeight:
		m.ClearWeight()
		return nil
	case pet.FieldBirthday:
		m.ClearBirthday()
		return nil
	case pet.FieldTagID:
		m.ClearTagID()
		return nil
	case pet.FieldHeight:
		m.ClearHeight()
		return nil
	}
	return fmt.Errorf("unknown Pet 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 *PetMutation) ResetField(name string) error {
	switch name {
	case pet.FieldName:
		m.ResetName()
		return nil
	case pet.FieldWeight:
		m.ResetWeight()
		return nil
	case pet.FieldBirthday:
		m.ResetBirthday()
		return nil
	case pet.FieldTagID:
		m.ResetTagID()
		return nil
	case pet.FieldHeight:
		m.ResetHeight()
		return nil
	}
	return fmt.Errorf("unknown Pet field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PetMutation) AddedEdges() []string {
	edges := make([]string, 0, 4)
	if m.categories != nil {
		edges = append(edges, pet.EdgeCategories)
	}
	if m.owner != nil {
		edges = append(edges, pet.EdgeOwner)
	}
	if m.rescuer != nil {
		edges = append(edges, pet.EdgeRescuer)
	}
	if m.friends != nil {
		edges = append(edges, pet.EdgeFriends)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PetMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case pet.EdgeCategories:
		ids := make([]ent.Value, 0, len(m.categories))
		for id := range m.categories {
			ids = append(ids, id)
		}
		return ids
	case pet.EdgeOwner:
		if id := m.owner; id != nil {
			return []ent.Value{*id}
		}
	case pet.EdgeRescuer:
		ids := make([]ent.Value, 0, len(m.rescuer))
		for id := range m.rescuer {
			ids = append(ids, id)
		}
		return ids
	case pet.EdgeFriends:
		ids := make([]ent.Value, 0, len(m.friends))
		for id := range m.friends {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PetMutation) RemovedEdges() []string {
	edges := make([]string, 0, 4)
	if m.removedcategories != nil {
		edges = append(edges, pet.EdgeCategories)
	}
	if m.removedrescuer != nil {
		edges = append(edges, pet.EdgeRescuer)
	}
	if m.removedfriends != nil {
		edges = append(edges, pet.EdgeFriends)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PetMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case pet.EdgeCategories:
		ids := make([]ent.Value, 0, len(m.removedcategories))
		for id := range m.removedcategories {
			ids = append(ids, id)
		}
		return ids
	case pet.EdgeRescuer:
		ids := make([]ent.Value, 0, len(m.removedrescuer))
		for id := range m.removedrescuer {
			ids = append(ids, id)
		}
		return ids
	case pet.EdgeFriends:
		ids := make([]ent.Value, 0, len(m.removedfriends))
		for id := range m.removedfriends {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PetMutation) ClearedEdges() []string {
	edges := make([]string, 0, 4)
	if m.clearedcategories {
		edges = append(edges, pet.EdgeCategories)
	}
	if m.clearedowner {
		edges = append(edges, pet.EdgeOwner)
	}
	if m.clearedrescuer {
		edges = append(edges, pet.EdgeRescuer)
	}
	if m.clearedfriends {
		edges = append(edges, pet.EdgeFriends)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PetMutation) EdgeCleared(name string) bool {
	switch name {
	case pet.EdgeCategories:
		return m.clearedcategories
	case pet.EdgeOwner:
		return m.clearedowner
	case pet.EdgeRescuer:
		return m.clearedrescuer
	case pet.EdgeFriends:
		return m.clearedfriends
	}
	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 *PetMutation) ClearEdge(name string) error {
	switch name {
	case pet.EdgeOwner:
		m.ClearOwner()
		return nil
	}
	return fmt.Errorf("unknown Pet 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 *PetMutation) ResetEdge(name string) error {
	switch name {
	case pet.EdgeCategories:
		m.ResetCategories()
		return nil
	case pet.EdgeOwner:
		m.ResetOwner()
		return nil
	case pet.EdgeRescuer:
		m.ResetRescuer()
		return nil
	case pet.EdgeFriends:
		m.ResetFriends()
		return nil
	}
	return fmt.Errorf("unknown Pet edge %s", name)
}

// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
	config
	op                   Op
	typ                  string
	id                   *int
	name                 *string
	age                  *uint
	addage               *int
	height               *uint
	addheight            *int
	favorite_cat_breed   *user.FavoriteCatBreed
	favorite_color       *user.FavoriteColor
	favorite_dog_breed   *user.FavoriteDogBreed
	favorite_fish_breed  *schema.FishBreed
	clearedFields        map[string]struct{}
	pets                 map[int]struct{}
	removedpets          map[int]struct{}
	clearedpets          bool
	animals_saved        map[int]struct{}
	removedanimals_saved map[int]struct{}
	clearedanimals_saved bool
	best_friend          *int
	clearedbest_friend   bool
	favorite_hat         *int
	clearedfavorite_hat  bool
	done                 bool
	oldValue             func(context.Context) (*User, error)
	predicates           []predicate.User
}

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

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

// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
	m := &UserMutation{
		config:        c,
		op:            op,
		typ:           TypeUser,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
	return func(m *UserMutation) {
		m.oldValue = func(context.Context) (*User, 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 UserMutation) 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 UserMutation) 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 *UserMutation) 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 *UserMutation) 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().User.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *UserMutation) SetName(s string) {
	m.name = &s
}

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

// OldName returns the old "name" field's value of the User entity.
// If the User 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 *UserMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *UserMutation) ResetName() {
	m.name = nil
}

// SetAge sets the "age" field.
func (m *UserMutation) SetAge(u uint) {
	m.age = &u
	m.addage = nil
}

// Age returns the value of the "age" field in the mutation.
func (m *UserMutation) Age() (r uint, exists bool) {
	v := m.age
	if v == nil {
		return
	}
	return *v, true
}

// OldAge returns the old "age" field's value of the User entity.
// If the User 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 *UserMutation) OldAge(ctx context.Context) (v uint, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAge is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAge requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAge: %w", err)
	}
	return oldValue.Age, nil
}

// AddAge adds u to the "age" field.
func (m *UserMutation) AddAge(u int) {
	if m.addage != nil {
		*m.addage += u
	} else {
		m.addage = &u
	}
}

// AddedAge returns the value that was added to the "age" field in this mutation.
func (m *UserMutation) AddedAge() (r int, exists bool) {
	v := m.addage
	if v == nil {
		return
	}
	return *v, true
}

// ResetAge resets all changes to the "age" field.
func (m *UserMutation) ResetAge() {
	m.age = nil
	m.addage = nil
}

// SetHeight sets the "height" field.
func (m *UserMutation) SetHeight(u uint) {
	m.height = &u
	m.addheight = nil
}

// Height returns the value of the "height" field in the mutation.
func (m *UserMutation) Height() (r uint, exists bool) {
	v := m.height
	if v == nil {
		return
	}
	return *v, true
}

// OldHeight returns the old "height" field's value of the User entity.
// If the User 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 *UserMutation) OldHeight(ctx context.Context) (v uint, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldHeight is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldHeight requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldHeight: %w", err)
	}
	return oldValue.Height, nil
}

// AddHeight adds u to the "height" field.
func (m *UserMutation) AddHeight(u int) {
	if m.addheight != nil {
		*m.addheight += u
	} else {
		m.addheight = &u
	}
}

// AddedHeight returns the value that was added to the "height" field in this mutation.
func (m *UserMutation) AddedHeight() (r int, exists bool) {
	v := m.addheight
	if v == nil {
		return
	}
	return *v, true
}

// ClearHeight clears the value of the "height" field.
func (m *UserMutation) ClearHeight() {
	m.height = nil
	m.addheight = nil
	m.clearedFields[user.FieldHeight] = struct{}{}
}

// HeightCleared returns if the "height" field was cleared in this mutation.
func (m *UserMutation) HeightCleared() bool {
	_, ok := m.clearedFields[user.FieldHeight]
	return ok
}

// ResetHeight resets all changes to the "height" field.
func (m *UserMutation) ResetHeight() {
	m.height = nil
	m.addheight = nil
	delete(m.clearedFields, user.FieldHeight)
}

// SetFavoriteCatBreed sets the "favorite_cat_breed" field.
func (m *UserMutation) SetFavoriteCatBreed(ucb user.FavoriteCatBreed) {
	m.favorite_cat_breed = &ucb
}

// FavoriteCatBreed returns the value of the "favorite_cat_breed" field in the mutation.
func (m *UserMutation) FavoriteCatBreed() (r user.FavoriteCatBreed, exists bool) {
	v := m.favorite_cat_breed
	if v == nil {
		return
	}
	return *v, true
}

// OldFavoriteCatBreed returns the old "favorite_cat_breed" field's value of the User entity.
// If the User 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 *UserMutation) OldFavoriteCatBreed(ctx context.Context) (v user.FavoriteCatBreed, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFavoriteCatBreed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFavoriteCatBreed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFavoriteCatBreed: %w", err)
	}
	return oldValue.FavoriteCatBreed, nil
}

// ResetFavoriteCatBreed resets all changes to the "favorite_cat_breed" field.
func (m *UserMutation) ResetFavoriteCatBreed() {
	m.favorite_cat_breed = nil
}

// SetFavoriteColor sets the "favorite_color" field.
func (m *UserMutation) SetFavoriteColor(uc user.FavoriteColor) {
	m.favorite_color = &uc
}

// FavoriteColor returns the value of the "favorite_color" field in the mutation.
func (m *UserMutation) FavoriteColor() (r user.FavoriteColor, exists bool) {
	v := m.favorite_color
	if v == nil {
		return
	}
	return *v, true
}

// OldFavoriteColor returns the old "favorite_color" field's value of the User entity.
// If the User 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 *UserMutation) OldFavoriteColor(ctx context.Context) (v user.FavoriteColor, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFavoriteColor is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFavoriteColor requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFavoriteColor: %w", err)
	}
	return oldValue.FavoriteColor, nil
}

// ResetFavoriteColor resets all changes to the "favorite_color" field.
func (m *UserMutation) ResetFavoriteColor() {
	m.favorite_color = nil
}

// SetFavoriteDogBreed sets the "favorite_dog_breed" field.
func (m *UserMutation) SetFavoriteDogBreed(udb user.FavoriteDogBreed) {
	m.favorite_dog_breed = &udb
}

// FavoriteDogBreed returns the value of the "favorite_dog_breed" field in the mutation.
func (m *UserMutation) FavoriteDogBreed() (r user.FavoriteDogBreed, exists bool) {
	v := m.favorite_dog_breed
	if v == nil {
		return
	}
	return *v, true
}

// OldFavoriteDogBreed returns the old "favorite_dog_breed" field's value of the User entity.
// If the User 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 *UserMutation) OldFavoriteDogBreed(ctx context.Context) (v user.FavoriteDogBreed, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFavoriteDogBreed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFavoriteDogBreed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFavoriteDogBreed: %w", err)
	}
	return oldValue.FavoriteDogBreed, nil
}

// ClearFavoriteDogBreed clears the value of the "favorite_dog_breed" field.
func (m *UserMutation) ClearFavoriteDogBreed() {
	m.favorite_dog_breed = nil
	m.clearedFields[user.FieldFavoriteDogBreed] = struct{}{}
}

// FavoriteDogBreedCleared returns if the "favorite_dog_breed" field was cleared in this mutation.
func (m *UserMutation) FavoriteDogBreedCleared() bool {
	_, ok := m.clearedFields[user.FieldFavoriteDogBreed]
	return ok
}

// ResetFavoriteDogBreed resets all changes to the "favorite_dog_breed" field.
func (m *UserMutation) ResetFavoriteDogBreed() {
	m.favorite_dog_breed = nil
	delete(m.clearedFields, user.FieldFavoriteDogBreed)
}

// SetFavoriteFishBreed sets the "favorite_fish_breed" field.
func (m *UserMutation) SetFavoriteFishBreed(sb schema.FishBreed) {
	m.favorite_fish_breed = &sb
}

// FavoriteFishBreed returns the value of the "favorite_fish_breed" field in the mutation.
func (m *UserMutation) FavoriteFishBreed() (r schema.FishBreed, exists bool) {
	v := m.favorite_fish_breed
	if v == nil {
		return
	}
	return *v, true
}

// OldFavoriteFishBreed returns the old "favorite_fish_breed" field's value of the User entity.
// If the User 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 *UserMutation) OldFavoriteFishBreed(ctx context.Context) (v schema.FishBreed, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFavoriteFishBreed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFavoriteFishBreed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFavoriteFishBreed: %w", err)
	}
	return oldValue.FavoriteFishBreed, nil
}

// ClearFavoriteFishBreed clears the value of the "favorite_fish_breed" field.
func (m *UserMutation) ClearFavoriteFishBreed() {
	m.favorite_fish_breed = nil
	m.clearedFields[user.FieldFavoriteFishBreed] = struct{}{}
}

// FavoriteFishBreedCleared returns if the "favorite_fish_breed" field was cleared in this mutation.
func (m *UserMutation) FavoriteFishBreedCleared() bool {
	_, ok := m.clearedFields[user.FieldFavoriteFishBreed]
	return ok
}

// ResetFavoriteFishBreed resets all changes to the "favorite_fish_breed" field.
func (m *UserMutation) ResetFavoriteFishBreed() {
	m.favorite_fish_breed = nil
	delete(m.clearedFields, user.FieldFavoriteFishBreed)
}

// AddPetIDs adds the "pets" edge to the Pet entity by ids.
func (m *UserMutation) AddPetIDs(ids ...int) {
	if m.pets == nil {
		m.pets = make(map[int]struct{})
	}
	for i := range ids {
		m.pets[ids[i]] = struct{}{}
	}
}

// ClearPets clears the "pets" edge to the Pet entity.
func (m *UserMutation) ClearPets() {
	m.clearedpets = true
}

// PetsCleared reports if the "pets" edge to the Pet entity was cleared.
func (m *UserMutation) PetsCleared() bool {
	return m.clearedpets
}

// RemovePetIDs removes the "pets" edge to the Pet entity by IDs.
func (m *UserMutation) RemovePetIDs(ids ...int) {
	if m.removedpets == nil {
		m.removedpets = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.pets, ids[i])
		m.removedpets[ids[i]] = struct{}{}
	}
}

// RemovedPets returns the removed IDs of the "pets" edge to the Pet entity.
func (m *UserMutation) RemovedPetsIDs() (ids []int) {
	for id := range m.removedpets {
		ids = append(ids, id)
	}
	return
}

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

// ResetPets resets all changes to the "pets" edge.
func (m *UserMutation) ResetPets() {
	m.pets = nil
	m.clearedpets = false
	m.removedpets = nil
}

// AddAnimalsSavedIDs adds the "animals_saved" edge to the Pet entity by ids.
func (m *UserMutation) AddAnimalsSavedIDs(ids ...int) {
	if m.animals_saved == nil {
		m.animals_saved = make(map[int]struct{})
	}
	for i := range ids {
		m.animals_saved[ids[i]] = struct{}{}
	}
}

// ClearAnimalsSaved clears the "animals_saved" edge to the Pet entity.
func (m *UserMutation) ClearAnimalsSaved() {
	m.clearedanimals_saved = true
}

// AnimalsSavedCleared reports if the "animals_saved" edge to the Pet entity was cleared.
func (m *UserMutation) AnimalsSavedCleared() bool {
	return m.clearedanimals_saved
}

// RemoveAnimalsSavedIDs removes the "animals_saved" edge to the Pet entity by IDs.
func (m *UserMutation) RemoveAnimalsSavedIDs(ids ...int) {
	if m.removedanimals_saved == nil {
		m.removedanimals_saved = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.animals_saved, ids[i])
		m.removedanimals_saved[ids[i]] = struct{}{}
	}
}

// RemovedAnimalsSaved returns the removed IDs of the "animals_saved" edge to the Pet entity.
func (m *UserMutation) RemovedAnimalsSavedIDs() (ids []int) {
	for id := range m.removedanimals_saved {
		ids = append(ids, id)
	}
	return
}

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

// ResetAnimalsSaved resets all changes to the "animals_saved" edge.
func (m *UserMutation) ResetAnimalsSaved() {
	m.animals_saved = nil
	m.clearedanimals_saved = false
	m.removedanimals_saved = nil
}

// SetBestFriendID sets the "best_friend" edge to the User entity by id.
func (m *UserMutation) SetBestFriendID(id int) {
	m.best_friend = &id
}

// ClearBestFriend clears the "best_friend" edge to the User entity.
func (m *UserMutation) ClearBestFriend() {
	m.clearedbest_friend = true
}

// BestFriendCleared reports if the "best_friend" edge to the User entity was cleared.
func (m *UserMutation) BestFriendCleared() bool {
	return m.clearedbest_friend
}

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

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

// ResetBestFriend resets all changes to the "best_friend" edge.
func (m *UserMutation) ResetBestFriend() {
	m.best_friend = nil
	m.clearedbest_friend = false
}

// SetFavoriteHatID sets the "favorite_hat" edge to the Hat entity by id.
func (m *UserMutation) SetFavoriteHatID(id int) {
	m.favorite_hat = &id
}

// ClearFavoriteHat clears the "favorite_hat" edge to the Hat entity.
func (m *UserMutation) ClearFavoriteHat() {
	m.clearedfavorite_hat = true
}

// FavoriteHatCleared reports if the "favorite_hat" edge to the Hat entity was cleared.
func (m *UserMutation) FavoriteHatCleared() bool {
	return m.clearedfavorite_hat
}

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

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

// ResetFavoriteHat resets all changes to the "favorite_hat" edge.
func (m *UserMutation) ResetFavoriteHat() {
	m.favorite_hat = nil
	m.clearedfavorite_hat = false
}

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

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

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

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

// Type returns the node type of this mutation (User).
func (m *UserMutation) 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 *UserMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, user.FieldName)
	}
	if m.age != nil {
		fields = append(fields, user.FieldAge)
	}
	if m.height != nil {
		fields = append(fields, user.FieldHeight)
	}
	if m.favorite_cat_breed != nil {
		fields = append(fields, user.FieldFavoriteCatBreed)
	}
	if m.favorite_color != nil {
		fields = append(fields, user.FieldFavoriteColor)
	}
	if m.favorite_dog_breed != nil {
		fields = append(fields, user.FieldFavoriteDogBreed)
	}
	if m.favorite_fish_breed != nil {
		fields = append(fields, user.FieldFavoriteFishBreed)
	}
	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 *UserMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case user.FieldName:
		return m.Name()
	case user.FieldAge:
		return m.Age()
	case user.FieldHeight:
		return m.Height()
	case user.FieldFavoriteCatBreed:
		return m.FavoriteCatBreed()
	case user.FieldFavoriteColor:
		return m.FavoriteColor()
	case user.FieldFavoriteDogBreed:
		return m.FavoriteDogBreed()
	case user.FieldFavoriteFishBreed:
		return m.FavoriteFishBreed()
	}
	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 *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case user.FieldName:
		return m.OldName(ctx)
	case user.FieldAge:
		return m.OldAge(ctx)
	case user.FieldHeight:
		return m.OldHeight(ctx)
	case user.FieldFavoriteCatBreed:
		return m.OldFavoriteCatBreed(ctx)
	case user.FieldFavoriteColor:
		return m.OldFavoriteColor(ctx)
	case user.FieldFavoriteDogBreed:
		return m.OldFavoriteDogBreed(ctx)
	case user.FieldFavoriteFishBreed:
		return m.OldFavoriteFishBreed(ctx)
	}
	return nil, fmt.Errorf("unknown User 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 *UserMutation) SetField(name string, value ent.Value) error {
	switch name {
	case user.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case user.FieldAge:
		v, ok := value.(uint)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAge(v)
		return nil
	case user.FieldHeight:
		v, ok := value.(uint)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHeight(v)
		return nil
	case user.FieldFavoriteCatBreed:
		v, ok := value.(user.FavoriteCatBreed)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFavoriteCatBreed(v)
		return nil
	case user.FieldFavoriteColor:
		v, ok := value.(user.FavoriteColor)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFavoriteColor(v)
		return nil
	case user.FieldFavoriteDogBreed:
		v, ok := value.(user.FavoriteDogBreed)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFavoriteDogBreed(v)
		return nil
	case user.FieldFavoriteFishBreed:
		v, ok := value.(schema.FishBreed)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFavoriteFishBreed(v)
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
	var fields []string
	if m.addage != nil {
		fields = append(fields, user.FieldAge)
	}
	if m.addheight != nil {
		fields = append(fields, user.FieldHeight)
	}
	return fields
}

// 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 *UserMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case user.FieldAge:
		return m.AddedAge()
	case user.FieldHeight:
		return m.AddedHeight()
	}
	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 *UserMutation) AddField(name string, value ent.Value) error {
	switch name {
	case user.FieldAge:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddAge(v)
		return nil
	case user.FieldHeight:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddHeight(v)
		return nil
	}
	return fmt.Errorf("unknown User numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(user.FieldHeight) {
		fields = append(fields, user.FieldHeight)
	}
	if m.FieldCleared(user.FieldFavoriteDogBreed) {
		fields = append(fields, user.FieldFavoriteDogBreed)
	}
	if m.FieldCleared(user.FieldFavoriteFishBreed) {
		fields = append(fields, user.FieldFavoriteFishBreed)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) 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 *UserMutation) ClearField(name string) error {
	switch name {
	case user.FieldHeight:
		m.ClearHeight()
		return nil
	case user.FieldFavoriteDogBreed:
		m.ClearFavoriteDogBreed()
		return nil
	case user.FieldFavoriteFishBreed:
		m.ClearFavoriteFishBreed()
		return nil
	}
	return fmt.Errorf("unknown User 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 *UserMutation) ResetField(name string) error {
	switch name {
	case user.FieldName:
		m.ResetName()
		return nil
	case user.FieldAge:
		m.ResetAge()
		return nil
	case user.FieldHeight:
		m.ResetHeight()
		return nil
	case user.FieldFavoriteCatBreed:
		m.ResetFavoriteCatBreed()
		return nil
	case user.FieldFavoriteColor:
		m.ResetFavoriteColor()
		return nil
	case user.FieldFavoriteDogBreed:
		m.ResetFavoriteDogBreed()
		return nil
	case user.FieldFavoriteFishBreed:
		m.ResetFavoriteFishBreed()
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
	edges := make([]string, 0, 4)
	if m.pets != nil {
		edges = append(edges, user.EdgePets)
	}
	if m.animals_saved != nil {
		edges = append(edges, user.EdgeAnimalsSaved)
	}
	if m.best_friend != nil {
		edges = append(edges, user.EdgeBestFriend)
	}
	if m.favorite_hat != nil {
		edges = append(edges, user.EdgeFavoriteHat)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case user.EdgePets:
		ids := make([]ent.Value, 0, len(m.pets))
		for id := range m.pets {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAnimalsSaved:
		ids := make([]ent.Value, 0, len(m.animals_saved))
		for id := range m.animals_saved {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeBestFriend:
		if id := m.best_friend; id != nil {
			return []ent.Value{*id}
		}
	case user.EdgeFavoriteHat:
		if id := m.favorite_hat; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
	edges := make([]string, 0, 4)
	if m.removedpets != nil {
		edges = append(edges, user.EdgePets)
	}
	if m.removedanimals_saved != nil {
		edges = append(edges, user.EdgeAnimalsSaved)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
	edges := make([]string, 0, 4)
	if m.clearedpets {
		edges = append(edges, user.EdgePets)
	}
	if m.clearedanimals_saved {
		edges = append(edges, user.EdgeAnimalsSaved)
	}
	if m.clearedbest_friend {
		edges = append(edges, user.EdgeBestFriend)
	}
	if m.clearedfavorite_hat {
		edges = append(edges, user.EdgeFavoriteHat)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
	switch name {
	case user.EdgePets:
		return m.clearedpets
	case user.EdgeAnimalsSaved:
		return m.clearedanimals_saved
	case user.EdgeBestFriend:
		return m.clearedbest_friend
	case user.EdgeFavoriteHat:
		return m.clearedfavorite_hat
	}
	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 *UserMutation) ClearEdge(name string) error {
	switch name {
	case user.EdgeBestFriend:
		m.ClearBestFriend()
		return nil
	case user.EdgeFavoriteHat:
		m.ClearFavoriteHat()
		return nil
	}
	return fmt.Errorf("unknown User 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 *UserMutation) ResetEdge(name string) error {
	switch name {
	case user.EdgePets:
		m.ResetPets()
		return nil
	case user.EdgeAnimalsSaved:
		m.ResetAnimalsSaved()
		return nil
	case user.EdgeBestFriend:
		m.ResetBestFriend()
		return nil
	case user.EdgeFavoriteHat:
		m.ResetFavoriteHat()
		return nil
	}
	return fmt.Errorf("unknown User edge %s", name)
}
