// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/categorie"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/champpersonnalise"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/piecejointe"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/predicate"
	"github.com/google/uuid"
)

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

	// Node types.
	TypeCategorie            = "Categorie"
	TypeChampPersonnalise    = "ChampPersonnalise"
	TypeEmplacement          = "Emplacement"
	TypeLienObjetEmplacement = "LienObjetEmplacement"
	TypeObjet                = "Objet"
	TypePieceJointe          = "PieceJointe"
)

// CategorieMutation represents an operation that mutates the Categorie nodes in the graph.
type CategorieMutation struct {
	config
	op             Op
	typ            string
	id             *uuid.UUID
	nom            *string
	slug           *string
	icone          *string
	created_at     *time.Time
	updated_at     *time.Time
	clearedFields  map[string]struct{}
	parent         *uuid.UUID
	clearedparent  bool
	enfants        map[uuid.UUID]struct{}
	removedenfants map[uuid.UUID]struct{}
	clearedenfants bool
	done           bool
	oldValue       func(context.Context) (*Categorie, error)
	predicates     []predicate.Categorie
}

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

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

// newCategorieMutation creates new mutation for the Categorie entity.
func newCategorieMutation(c config, op Op, opts ...categorieOption) *CategorieMutation {
	m := &CategorieMutation{
		config:        c,
		op:            op,
		typ:           TypeCategorie,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withCategorie sets the old Categorie of the mutation.
func withCategorie(node *Categorie) categorieOption {
	return func(m *CategorieMutation) {
		m.oldValue = func(context.Context) (*Categorie, 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 CategorieMutation) 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 CategorieMutation) 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 Categorie entities.
func (m *CategorieMutation) SetID(id uuid.UUID) {
	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 *CategorieMutation) ID() (id uuid.UUID, 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 *CategorieMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Categorie.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetNom sets the "nom" field.
func (m *CategorieMutation) SetNom(s string) {
	m.nom = &s
}

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

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

// ResetNom resets all changes to the "nom" field.
func (m *CategorieMutation) ResetNom() {
	m.nom = nil
}

// SetParentID sets the "parent_id" field.
func (m *CategorieMutation) SetParentID(u uuid.UUID) {
	m.parent = &u
}

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

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

// ClearParentID clears the value of the "parent_id" field.
func (m *CategorieMutation) ClearParentID() {
	m.parent = nil
	m.clearedFields[categorie.FieldParentID] = struct{}{}
}

// ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
func (m *CategorieMutation) ParentIDCleared() bool {
	_, ok := m.clearedFields[categorie.FieldParentID]
	return ok
}

// ResetParentID resets all changes to the "parent_id" field.
func (m *CategorieMutation) ResetParentID() {
	m.parent = nil
	delete(m.clearedFields, categorie.FieldParentID)
}

// SetSlug sets the "slug" field.
func (m *CategorieMutation) SetSlug(s string) {
	m.slug = &s
}

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

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

// ClearSlug clears the value of the "slug" field.
func (m *CategorieMutation) ClearSlug() {
	m.slug = nil
	m.clearedFields[categorie.FieldSlug] = struct{}{}
}

// SlugCleared returns if the "slug" field was cleared in this mutation.
func (m *CategorieMutation) SlugCleared() bool {
	_, ok := m.clearedFields[categorie.FieldSlug]
	return ok
}

// ResetSlug resets all changes to the "slug" field.
func (m *CategorieMutation) ResetSlug() {
	m.slug = nil
	delete(m.clearedFields, categorie.FieldSlug)
}

// SetIcone sets the "icone" field.
func (m *CategorieMutation) SetIcone(s string) {
	m.icone = &s
}

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

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

// ClearIcone clears the value of the "icone" field.
func (m *CategorieMutation) ClearIcone() {
	m.icone = nil
	m.clearedFields[categorie.FieldIcone] = struct{}{}
}

// IconeCleared returns if the "icone" field was cleared in this mutation.
func (m *CategorieMutation) IconeCleared() bool {
	_, ok := m.clearedFields[categorie.FieldIcone]
	return ok
}

// ResetIcone resets all changes to the "icone" field.
func (m *CategorieMutation) ResetIcone() {
	m.icone = nil
	delete(m.clearedFields, categorie.FieldIcone)
}

// SetCreatedAt sets the "created_at" field.
func (m *CategorieMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *CategorieMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *CategorieMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *CategorieMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearParent clears the "parent" edge to the Categorie entity.
func (m *CategorieMutation) ClearParent() {
	m.clearedparent = true
	m.clearedFields[categorie.FieldParentID] = struct{}{}
}

// ParentCleared reports if the "parent" edge to the Categorie entity was cleared.
func (m *CategorieMutation) ParentCleared() bool {
	return m.ParentIDCleared() || m.clearedparent
}

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

// ResetParent resets all changes to the "parent" edge.
func (m *CategorieMutation) ResetParent() {
	m.parent = nil
	m.clearedparent = false
}

// AddEnfantIDs adds the "enfants" edge to the Categorie entity by ids.
func (m *CategorieMutation) AddEnfantIDs(ids ...uuid.UUID) {
	if m.enfants == nil {
		m.enfants = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.enfants[ids[i]] = struct{}{}
	}
}

// ClearEnfants clears the "enfants" edge to the Categorie entity.
func (m *CategorieMutation) ClearEnfants() {
	m.clearedenfants = true
}

// EnfantsCleared reports if the "enfants" edge to the Categorie entity was cleared.
func (m *CategorieMutation) EnfantsCleared() bool {
	return m.clearedenfants
}

// RemoveEnfantIDs removes the "enfants" edge to the Categorie entity by IDs.
func (m *CategorieMutation) RemoveEnfantIDs(ids ...uuid.UUID) {
	if m.removedenfants == nil {
		m.removedenfants = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.enfants, ids[i])
		m.removedenfants[ids[i]] = struct{}{}
	}
}

// RemovedEnfants returns the removed IDs of the "enfants" edge to the Categorie entity.
func (m *CategorieMutation) RemovedEnfantsIDs() (ids []uuid.UUID) {
	for id := range m.removedenfants {
		ids = append(ids, id)
	}
	return
}

// EnfantsIDs returns the "enfants" edge IDs in the mutation.
func (m *CategorieMutation) EnfantsIDs() (ids []uuid.UUID) {
	for id := range m.enfants {
		ids = append(ids, id)
	}
	return
}

// ResetEnfants resets all changes to the "enfants" edge.
func (m *CategorieMutation) ResetEnfants() {
	m.enfants = nil
	m.clearedenfants = false
	m.removedenfants = nil
}

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

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

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

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

// Type returns the node type of this mutation (Categorie).
func (m *CategorieMutation) 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 *CategorieMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.nom != nil {
		fields = append(fields, categorie.FieldNom)
	}
	if m.parent != nil {
		fields = append(fields, categorie.FieldParentID)
	}
	if m.slug != nil {
		fields = append(fields, categorie.FieldSlug)
	}
	if m.icone != nil {
		fields = append(fields, categorie.FieldIcone)
	}
	if m.created_at != nil {
		fields = append(fields, categorie.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, categorie.FieldUpdatedAt)
	}
	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 *CategorieMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case categorie.FieldNom:
		return m.Nom()
	case categorie.FieldParentID:
		return m.ParentID()
	case categorie.FieldSlug:
		return m.Slug()
	case categorie.FieldIcone:
		return m.Icone()
	case categorie.FieldCreatedAt:
		return m.CreatedAt()
	case categorie.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *CategorieMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case categorie.FieldNom:
		return m.OldNom(ctx)
	case categorie.FieldParentID:
		return m.OldParentID(ctx)
	case categorie.FieldSlug:
		return m.OldSlug(ctx)
	case categorie.FieldIcone:
		return m.OldIcone(ctx)
	case categorie.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case categorie.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Categorie 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 *CategorieMutation) SetField(name string, value ent.Value) error {
	switch name {
	case categorie.FieldNom:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNom(v)
		return nil
	case categorie.FieldParentID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetParentID(v)
		return nil
	case categorie.FieldSlug:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSlug(v)
		return nil
	case categorie.FieldIcone:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIcone(v)
		return nil
	case categorie.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case categorie.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Categorie field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CategorieMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(categorie.FieldParentID) {
		fields = append(fields, categorie.FieldParentID)
	}
	if m.FieldCleared(categorie.FieldSlug) {
		fields = append(fields, categorie.FieldSlug)
	}
	if m.FieldCleared(categorie.FieldIcone) {
		fields = append(fields, categorie.FieldIcone)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CategorieMutation) 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 *CategorieMutation) ClearField(name string) error {
	switch name {
	case categorie.FieldParentID:
		m.ClearParentID()
		return nil
	case categorie.FieldSlug:
		m.ClearSlug()
		return nil
	case categorie.FieldIcone:
		m.ClearIcone()
		return nil
	}
	return fmt.Errorf("unknown Categorie 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 *CategorieMutation) ResetField(name string) error {
	switch name {
	case categorie.FieldNom:
		m.ResetNom()
		return nil
	case categorie.FieldParentID:
		m.ResetParentID()
		return nil
	case categorie.FieldSlug:
		m.ResetSlug()
		return nil
	case categorie.FieldIcone:
		m.ResetIcone()
		return nil
	case categorie.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case categorie.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Categorie field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CategorieMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.parent != nil {
		edges = append(edges, categorie.EdgeParent)
	}
	if m.enfants != nil {
		edges = append(edges, categorie.EdgeEnfants)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CategorieMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case categorie.EdgeParent:
		if id := m.parent; id != nil {
			return []ent.Value{*id}
		}
	case categorie.EdgeEnfants:
		ids := make([]ent.Value, 0, len(m.enfants))
		for id := range m.enfants {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CategorieMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	if m.removedenfants != nil {
		edges = append(edges, categorie.EdgeEnfants)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CategorieMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedparent {
		edges = append(edges, categorie.EdgeParent)
	}
	if m.clearedenfants {
		edges = append(edges, categorie.EdgeEnfants)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CategorieMutation) EdgeCleared(name string) bool {
	switch name {
	case categorie.EdgeParent:
		return m.clearedparent
	case categorie.EdgeEnfants:
		return m.clearedenfants
	}
	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 *CategorieMutation) ClearEdge(name string) error {
	switch name {
	case categorie.EdgeParent:
		m.ClearParent()
		return nil
	}
	return fmt.Errorf("unknown Categorie 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 *CategorieMutation) ResetEdge(name string) error {
	switch name {
	case categorie.EdgeParent:
		m.ResetParent()
		return nil
	case categorie.EdgeEnfants:
		m.ResetEnfants()
		return nil
	}
	return fmt.Errorf("unknown Categorie edge %s", name)
}

// ChampPersonnaliseMutation represents an operation that mutates the ChampPersonnalise nodes in the graph.
type ChampPersonnaliseMutation struct {
	config
	op            Op
	typ           string
	id            *uuid.UUID
	nom_champ     *string
	type_champ    *champpersonnalise.TypeChamp
	valeur        *string
	unite         *string
	created_at    *time.Time
	updated_at    *time.Time
	clearedFields map[string]struct{}
	objet         *uuid.UUID
	clearedobjet  bool
	done          bool
	oldValue      func(context.Context) (*ChampPersonnalise, error)
	predicates    []predicate.ChampPersonnalise
}

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

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

// newChampPersonnaliseMutation creates new mutation for the ChampPersonnalise entity.
func newChampPersonnaliseMutation(c config, op Op, opts ...champpersonnaliseOption) *ChampPersonnaliseMutation {
	m := &ChampPersonnaliseMutation{
		config:        c,
		op:            op,
		typ:           TypeChampPersonnalise,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withChampPersonnalise sets the old ChampPersonnalise of the mutation.
func withChampPersonnalise(node *ChampPersonnalise) champpersonnaliseOption {
	return func(m *ChampPersonnaliseMutation) {
		m.oldValue = func(context.Context) (*ChampPersonnalise, 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 ChampPersonnaliseMutation) 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 ChampPersonnaliseMutation) 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 ChampPersonnalise entities.
func (m *ChampPersonnaliseMutation) SetID(id uuid.UUID) {
	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 *ChampPersonnaliseMutation) ID() (id uuid.UUID, 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 *ChampPersonnaliseMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().ChampPersonnalise.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetObjetID sets the "objet_id" field.
func (m *ChampPersonnaliseMutation) SetObjetID(u uuid.UUID) {
	m.objet = &u
}

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

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

// ResetObjetID resets all changes to the "objet_id" field.
func (m *ChampPersonnaliseMutation) ResetObjetID() {
	m.objet = nil
}

// SetNomChamp sets the "nom_champ" field.
func (m *ChampPersonnaliseMutation) SetNomChamp(s string) {
	m.nom_champ = &s
}

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

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

// ResetNomChamp resets all changes to the "nom_champ" field.
func (m *ChampPersonnaliseMutation) ResetNomChamp() {
	m.nom_champ = nil
}

// SetTypeChamp sets the "type_champ" field.
func (m *ChampPersonnaliseMutation) SetTypeChamp(cc champpersonnalise.TypeChamp) {
	m.type_champ = &cc
}

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

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

// ResetTypeChamp resets all changes to the "type_champ" field.
func (m *ChampPersonnaliseMutation) ResetTypeChamp() {
	m.type_champ = nil
}

// SetValeur sets the "valeur" field.
func (m *ChampPersonnaliseMutation) SetValeur(s string) {
	m.valeur = &s
}

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

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

// ClearValeur clears the value of the "valeur" field.
func (m *ChampPersonnaliseMutation) ClearValeur() {
	m.valeur = nil
	m.clearedFields[champpersonnalise.FieldValeur] = struct{}{}
}

// ValeurCleared returns if the "valeur" field was cleared in this mutation.
func (m *ChampPersonnaliseMutation) ValeurCleared() bool {
	_, ok := m.clearedFields[champpersonnalise.FieldValeur]
	return ok
}

// ResetValeur resets all changes to the "valeur" field.
func (m *ChampPersonnaliseMutation) ResetValeur() {
	m.valeur = nil
	delete(m.clearedFields, champpersonnalise.FieldValeur)
}

// SetUnite sets the "unite" field.
func (m *ChampPersonnaliseMutation) SetUnite(s string) {
	m.unite = &s
}

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

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

// ClearUnite clears the value of the "unite" field.
func (m *ChampPersonnaliseMutation) ClearUnite() {
	m.unite = nil
	m.clearedFields[champpersonnalise.FieldUnite] = struct{}{}
}

// UniteCleared returns if the "unite" field was cleared in this mutation.
func (m *ChampPersonnaliseMutation) UniteCleared() bool {
	_, ok := m.clearedFields[champpersonnalise.FieldUnite]
	return ok
}

// ResetUnite resets all changes to the "unite" field.
func (m *ChampPersonnaliseMutation) ResetUnite() {
	m.unite = nil
	delete(m.clearedFields, champpersonnalise.FieldUnite)
}

// SetCreatedAt sets the "created_at" field.
func (m *ChampPersonnaliseMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *ChampPersonnaliseMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *ChampPersonnaliseMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *ChampPersonnaliseMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearObjet clears the "objet" edge to the Objet entity.
func (m *ChampPersonnaliseMutation) ClearObjet() {
	m.clearedobjet = true
	m.clearedFields[champpersonnalise.FieldObjetID] = struct{}{}
}

// ObjetCleared reports if the "objet" edge to the Objet entity was cleared.
func (m *ChampPersonnaliseMutation) ObjetCleared() bool {
	return m.clearedobjet
}

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

// ResetObjet resets all changes to the "objet" edge.
func (m *ChampPersonnaliseMutation) ResetObjet() {
	m.objet = nil
	m.clearedobjet = false
}

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

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

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

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

// Type returns the node type of this mutation (ChampPersonnalise).
func (m *ChampPersonnaliseMutation) 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 *ChampPersonnaliseMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.objet != nil {
		fields = append(fields, champpersonnalise.FieldObjetID)
	}
	if m.nom_champ != nil {
		fields = append(fields, champpersonnalise.FieldNomChamp)
	}
	if m.type_champ != nil {
		fields = append(fields, champpersonnalise.FieldTypeChamp)
	}
	if m.valeur != nil {
		fields = append(fields, champpersonnalise.FieldValeur)
	}
	if m.unite != nil {
		fields = append(fields, champpersonnalise.FieldUnite)
	}
	if m.created_at != nil {
		fields = append(fields, champpersonnalise.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, champpersonnalise.FieldUpdatedAt)
	}
	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 *ChampPersonnaliseMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case champpersonnalise.FieldObjetID:
		return m.ObjetID()
	case champpersonnalise.FieldNomChamp:
		return m.NomChamp()
	case champpersonnalise.FieldTypeChamp:
		return m.TypeChamp()
	case champpersonnalise.FieldValeur:
		return m.Valeur()
	case champpersonnalise.FieldUnite:
		return m.Unite()
	case champpersonnalise.FieldCreatedAt:
		return m.CreatedAt()
	case champpersonnalise.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *ChampPersonnaliseMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case champpersonnalise.FieldObjetID:
		return m.OldObjetID(ctx)
	case champpersonnalise.FieldNomChamp:
		return m.OldNomChamp(ctx)
	case champpersonnalise.FieldTypeChamp:
		return m.OldTypeChamp(ctx)
	case champpersonnalise.FieldValeur:
		return m.OldValeur(ctx)
	case champpersonnalise.FieldUnite:
		return m.OldUnite(ctx)
	case champpersonnalise.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case champpersonnalise.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown ChampPersonnalise 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 *ChampPersonnaliseMutation) SetField(name string, value ent.Value) error {
	switch name {
	case champpersonnalise.FieldObjetID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetObjetID(v)
		return nil
	case champpersonnalise.FieldNomChamp:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNomChamp(v)
		return nil
	case champpersonnalise.FieldTypeChamp:
		v, ok := value.(champpersonnalise.TypeChamp)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTypeChamp(v)
		return nil
	case champpersonnalise.FieldValeur:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValeur(v)
		return nil
	case champpersonnalise.FieldUnite:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUnite(v)
		return nil
	case champpersonnalise.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case champpersonnalise.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown ChampPersonnalise field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ChampPersonnaliseMutation) 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 *ChampPersonnaliseMutation) ClearField(name string) error {
	switch name {
	case champpersonnalise.FieldValeur:
		m.ClearValeur()
		return nil
	case champpersonnalise.FieldUnite:
		m.ClearUnite()
		return nil
	}
	return fmt.Errorf("unknown ChampPersonnalise 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 *ChampPersonnaliseMutation) ResetField(name string) error {
	switch name {
	case champpersonnalise.FieldObjetID:
		m.ResetObjetID()
		return nil
	case champpersonnalise.FieldNomChamp:
		m.ResetNomChamp()
		return nil
	case champpersonnalise.FieldTypeChamp:
		m.ResetTypeChamp()
		return nil
	case champpersonnalise.FieldValeur:
		m.ResetValeur()
		return nil
	case champpersonnalise.FieldUnite:
		m.ResetUnite()
		return nil
	case champpersonnalise.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case champpersonnalise.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown ChampPersonnalise field %s", name)
}

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ChampPersonnaliseMutation) EdgeCleared(name string) bool {
	switch name {
	case champpersonnalise.EdgeObjet:
		return m.clearedobjet
	}
	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 *ChampPersonnaliseMutation) ClearEdge(name string) error {
	switch name {
	case champpersonnalise.EdgeObjet:
		m.ClearObjet()
		return nil
	}
	return fmt.Errorf("unknown ChampPersonnalise 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 *ChampPersonnaliseMutation) ResetEdge(name string) error {
	switch name {
	case champpersonnalise.EdgeObjet:
		m.ResetObjet()
		return nil
	}
	return fmt.Errorf("unknown ChampPersonnalise edge %s", name)
}

// EmplacementMutation represents an operation that mutates the Emplacement nodes in the graph.
type EmplacementMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	nom                 *string
	slug                *string
	piece               *string
	meuble              *string
	numero_boite        *string
	icone               *string
	created_at          *time.Time
	updated_at          *time.Time
	clearedFields       map[string]struct{}
	parent              *uuid.UUID
	clearedparent       bool
	enfants             map[uuid.UUID]struct{}
	removedenfants      map[uuid.UUID]struct{}
	clearedenfants      bool
	liens_objets        map[uuid.UUID]struct{}
	removedliens_objets map[uuid.UUID]struct{}
	clearedliens_objets bool
	done                bool
	oldValue            func(context.Context) (*Emplacement, error)
	predicates          []predicate.Emplacement
}

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

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

// newEmplacementMutation creates new mutation for the Emplacement entity.
func newEmplacementMutation(c config, op Op, opts ...emplacementOption) *EmplacementMutation {
	m := &EmplacementMutation{
		config:        c,
		op:            op,
		typ:           TypeEmplacement,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withEmplacement sets the old Emplacement of the mutation.
func withEmplacement(node *Emplacement) emplacementOption {
	return func(m *EmplacementMutation) {
		m.oldValue = func(context.Context) (*Emplacement, 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 EmplacementMutation) 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 EmplacementMutation) 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 Emplacement entities.
func (m *EmplacementMutation) SetID(id uuid.UUID) {
	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 *EmplacementMutation) ID() (id uuid.UUID, 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 *EmplacementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Emplacement.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetNom sets the "nom" field.
func (m *EmplacementMutation) SetNom(s string) {
	m.nom = &s
}

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

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

// ResetNom resets all changes to the "nom" field.
func (m *EmplacementMutation) ResetNom() {
	m.nom = nil
}

// SetParentID sets the "parent_id" field.
func (m *EmplacementMutation) SetParentID(u uuid.UUID) {
	m.parent = &u
}

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

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

// ClearParentID clears the value of the "parent_id" field.
func (m *EmplacementMutation) ClearParentID() {
	m.parent = nil
	m.clearedFields[emplacement.FieldParentID] = struct{}{}
}

// ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
func (m *EmplacementMutation) ParentIDCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldParentID]
	return ok
}

// ResetParentID resets all changes to the "parent_id" field.
func (m *EmplacementMutation) ResetParentID() {
	m.parent = nil
	delete(m.clearedFields, emplacement.FieldParentID)
}

// SetSlug sets the "slug" field.
func (m *EmplacementMutation) SetSlug(s string) {
	m.slug = &s
}

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

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

// ClearSlug clears the value of the "slug" field.
func (m *EmplacementMutation) ClearSlug() {
	m.slug = nil
	m.clearedFields[emplacement.FieldSlug] = struct{}{}
}

// SlugCleared returns if the "slug" field was cleared in this mutation.
func (m *EmplacementMutation) SlugCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldSlug]
	return ok
}

// ResetSlug resets all changes to the "slug" field.
func (m *EmplacementMutation) ResetSlug() {
	m.slug = nil
	delete(m.clearedFields, emplacement.FieldSlug)
}

// SetPiece sets the "piece" field.
func (m *EmplacementMutation) SetPiece(s string) {
	m.piece = &s
}

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

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

// ClearPiece clears the value of the "piece" field.
func (m *EmplacementMutation) ClearPiece() {
	m.piece = nil
	m.clearedFields[emplacement.FieldPiece] = struct{}{}
}

// PieceCleared returns if the "piece" field was cleared in this mutation.
func (m *EmplacementMutation) PieceCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldPiece]
	return ok
}

// ResetPiece resets all changes to the "piece" field.
func (m *EmplacementMutation) ResetPiece() {
	m.piece = nil
	delete(m.clearedFields, emplacement.FieldPiece)
}

// SetMeuble sets the "meuble" field.
func (m *EmplacementMutation) SetMeuble(s string) {
	m.meuble = &s
}

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

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

// ClearMeuble clears the value of the "meuble" field.
func (m *EmplacementMutation) ClearMeuble() {
	m.meuble = nil
	m.clearedFields[emplacement.FieldMeuble] = struct{}{}
}

// MeubleCleared returns if the "meuble" field was cleared in this mutation.
func (m *EmplacementMutation) MeubleCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldMeuble]
	return ok
}

// ResetMeuble resets all changes to the "meuble" field.
func (m *EmplacementMutation) ResetMeuble() {
	m.meuble = nil
	delete(m.clearedFields, emplacement.FieldMeuble)
}

// SetNumeroBoite sets the "numero_boite" field.
func (m *EmplacementMutation) SetNumeroBoite(s string) {
	m.numero_boite = &s
}

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

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

// ClearNumeroBoite clears the value of the "numero_boite" field.
func (m *EmplacementMutation) ClearNumeroBoite() {
	m.numero_boite = nil
	m.clearedFields[emplacement.FieldNumeroBoite] = struct{}{}
}

// NumeroBoiteCleared returns if the "numero_boite" field was cleared in this mutation.
func (m *EmplacementMutation) NumeroBoiteCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldNumeroBoite]
	return ok
}

// ResetNumeroBoite resets all changes to the "numero_boite" field.
func (m *EmplacementMutation) ResetNumeroBoite() {
	m.numero_boite = nil
	delete(m.clearedFields, emplacement.FieldNumeroBoite)
}

// SetIcone sets the "icone" field.
func (m *EmplacementMutation) SetIcone(s string) {
	m.icone = &s
}

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

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

// ClearIcone clears the value of the "icone" field.
func (m *EmplacementMutation) ClearIcone() {
	m.icone = nil
	m.clearedFields[emplacement.FieldIcone] = struct{}{}
}

// IconeCleared returns if the "icone" field was cleared in this mutation.
func (m *EmplacementMutation) IconeCleared() bool {
	_, ok := m.clearedFields[emplacement.FieldIcone]
	return ok
}

// ResetIcone resets all changes to the "icone" field.
func (m *EmplacementMutation) ResetIcone() {
	m.icone = nil
	delete(m.clearedFields, emplacement.FieldIcone)
}

// SetCreatedAt sets the "created_at" field.
func (m *EmplacementMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *EmplacementMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *EmplacementMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *EmplacementMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearParent clears the "parent" edge to the Emplacement entity.
func (m *EmplacementMutation) ClearParent() {
	m.clearedparent = true
	m.clearedFields[emplacement.FieldParentID] = struct{}{}
}

// ParentCleared reports if the "parent" edge to the Emplacement entity was cleared.
func (m *EmplacementMutation) ParentCleared() bool {
	return m.ParentIDCleared() || m.clearedparent
}

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

// ResetParent resets all changes to the "parent" edge.
func (m *EmplacementMutation) ResetParent() {
	m.parent = nil
	m.clearedparent = false
}

// AddEnfantIDs adds the "enfants" edge to the Emplacement entity by ids.
func (m *EmplacementMutation) AddEnfantIDs(ids ...uuid.UUID) {
	if m.enfants == nil {
		m.enfants = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.enfants[ids[i]] = struct{}{}
	}
}

// ClearEnfants clears the "enfants" edge to the Emplacement entity.
func (m *EmplacementMutation) ClearEnfants() {
	m.clearedenfants = true
}

// EnfantsCleared reports if the "enfants" edge to the Emplacement entity was cleared.
func (m *EmplacementMutation) EnfantsCleared() bool {
	return m.clearedenfants
}

// RemoveEnfantIDs removes the "enfants" edge to the Emplacement entity by IDs.
func (m *EmplacementMutation) RemoveEnfantIDs(ids ...uuid.UUID) {
	if m.removedenfants == nil {
		m.removedenfants = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.enfants, ids[i])
		m.removedenfants[ids[i]] = struct{}{}
	}
}

// RemovedEnfants returns the removed IDs of the "enfants" edge to the Emplacement entity.
func (m *EmplacementMutation) RemovedEnfantsIDs() (ids []uuid.UUID) {
	for id := range m.removedenfants {
		ids = append(ids, id)
	}
	return
}

// EnfantsIDs returns the "enfants" edge IDs in the mutation.
func (m *EmplacementMutation) EnfantsIDs() (ids []uuid.UUID) {
	for id := range m.enfants {
		ids = append(ids, id)
	}
	return
}

// ResetEnfants resets all changes to the "enfants" edge.
func (m *EmplacementMutation) ResetEnfants() {
	m.enfants = nil
	m.clearedenfants = false
	m.removedenfants = nil
}

// AddLiensObjetIDs adds the "liens_objets" edge to the LienObjetEmplacement entity by ids.
func (m *EmplacementMutation) AddLiensObjetIDs(ids ...uuid.UUID) {
	if m.liens_objets == nil {
		m.liens_objets = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.liens_objets[ids[i]] = struct{}{}
	}
}

// ClearLiensObjets clears the "liens_objets" edge to the LienObjetEmplacement entity.
func (m *EmplacementMutation) ClearLiensObjets() {
	m.clearedliens_objets = true
}

// LiensObjetsCleared reports if the "liens_objets" edge to the LienObjetEmplacement entity was cleared.
func (m *EmplacementMutation) LiensObjetsCleared() bool {
	return m.clearedliens_objets
}

// RemoveLiensObjetIDs removes the "liens_objets" edge to the LienObjetEmplacement entity by IDs.
func (m *EmplacementMutation) RemoveLiensObjetIDs(ids ...uuid.UUID) {
	if m.removedliens_objets == nil {
		m.removedliens_objets = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.liens_objets, ids[i])
		m.removedliens_objets[ids[i]] = struct{}{}
	}
}

// RemovedLiensObjets returns the removed IDs of the "liens_objets" edge to the LienObjetEmplacement entity.
func (m *EmplacementMutation) RemovedLiensObjetsIDs() (ids []uuid.UUID) {
	for id := range m.removedliens_objets {
		ids = append(ids, id)
	}
	return
}

// LiensObjetsIDs returns the "liens_objets" edge IDs in the mutation.
func (m *EmplacementMutation) LiensObjetsIDs() (ids []uuid.UUID) {
	for id := range m.liens_objets {
		ids = append(ids, id)
	}
	return
}

// ResetLiensObjets resets all changes to the "liens_objets" edge.
func (m *EmplacementMutation) ResetLiensObjets() {
	m.liens_objets = nil
	m.clearedliens_objets = false
	m.removedliens_objets = nil
}

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

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

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

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

// Type returns the node type of this mutation (Emplacement).
func (m *EmplacementMutation) 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 *EmplacementMutation) Fields() []string {
	fields := make([]string, 0, 9)
	if m.nom != nil {
		fields = append(fields, emplacement.FieldNom)
	}
	if m.parent != nil {
		fields = append(fields, emplacement.FieldParentID)
	}
	if m.slug != nil {
		fields = append(fields, emplacement.FieldSlug)
	}
	if m.piece != nil {
		fields = append(fields, emplacement.FieldPiece)
	}
	if m.meuble != nil {
		fields = append(fields, emplacement.FieldMeuble)
	}
	if m.numero_boite != nil {
		fields = append(fields, emplacement.FieldNumeroBoite)
	}
	if m.icone != nil {
		fields = append(fields, emplacement.FieldIcone)
	}
	if m.created_at != nil {
		fields = append(fields, emplacement.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, emplacement.FieldUpdatedAt)
	}
	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 *EmplacementMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case emplacement.FieldNom:
		return m.Nom()
	case emplacement.FieldParentID:
		return m.ParentID()
	case emplacement.FieldSlug:
		return m.Slug()
	case emplacement.FieldPiece:
		return m.Piece()
	case emplacement.FieldMeuble:
		return m.Meuble()
	case emplacement.FieldNumeroBoite:
		return m.NumeroBoite()
	case emplacement.FieldIcone:
		return m.Icone()
	case emplacement.FieldCreatedAt:
		return m.CreatedAt()
	case emplacement.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *EmplacementMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case emplacement.FieldNom:
		return m.OldNom(ctx)
	case emplacement.FieldParentID:
		return m.OldParentID(ctx)
	case emplacement.FieldSlug:
		return m.OldSlug(ctx)
	case emplacement.FieldPiece:
		return m.OldPiece(ctx)
	case emplacement.FieldMeuble:
		return m.OldMeuble(ctx)
	case emplacement.FieldNumeroBoite:
		return m.OldNumeroBoite(ctx)
	case emplacement.FieldIcone:
		return m.OldIcone(ctx)
	case emplacement.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case emplacement.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Emplacement 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 *EmplacementMutation) SetField(name string, value ent.Value) error {
	switch name {
	case emplacement.FieldNom:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNom(v)
		return nil
	case emplacement.FieldParentID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetParentID(v)
		return nil
	case emplacement.FieldSlug:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSlug(v)
		return nil
	case emplacement.FieldPiece:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPiece(v)
		return nil
	case emplacement.FieldMeuble:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMeuble(v)
		return nil
	case emplacement.FieldNumeroBoite:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNumeroBoite(v)
		return nil
	case emplacement.FieldIcone:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIcone(v)
		return nil
	case emplacement.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case emplacement.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Emplacement field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *EmplacementMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(emplacement.FieldParentID) {
		fields = append(fields, emplacement.FieldParentID)
	}
	if m.FieldCleared(emplacement.FieldSlug) {
		fields = append(fields, emplacement.FieldSlug)
	}
	if m.FieldCleared(emplacement.FieldPiece) {
		fields = append(fields, emplacement.FieldPiece)
	}
	if m.FieldCleared(emplacement.FieldMeuble) {
		fields = append(fields, emplacement.FieldMeuble)
	}
	if m.FieldCleared(emplacement.FieldNumeroBoite) {
		fields = append(fields, emplacement.FieldNumeroBoite)
	}
	if m.FieldCleared(emplacement.FieldIcone) {
		fields = append(fields, emplacement.FieldIcone)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *EmplacementMutation) 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 *EmplacementMutation) ClearField(name string) error {
	switch name {
	case emplacement.FieldParentID:
		m.ClearParentID()
		return nil
	case emplacement.FieldSlug:
		m.ClearSlug()
		return nil
	case emplacement.FieldPiece:
		m.ClearPiece()
		return nil
	case emplacement.FieldMeuble:
		m.ClearMeuble()
		return nil
	case emplacement.FieldNumeroBoite:
		m.ClearNumeroBoite()
		return nil
	case emplacement.FieldIcone:
		m.ClearIcone()
		return nil
	}
	return fmt.Errorf("unknown Emplacement 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 *EmplacementMutation) ResetField(name string) error {
	switch name {
	case emplacement.FieldNom:
		m.ResetNom()
		return nil
	case emplacement.FieldParentID:
		m.ResetParentID()
		return nil
	case emplacement.FieldSlug:
		m.ResetSlug()
		return nil
	case emplacement.FieldPiece:
		m.ResetPiece()
		return nil
	case emplacement.FieldMeuble:
		m.ResetMeuble()
		return nil
	case emplacement.FieldNumeroBoite:
		m.ResetNumeroBoite()
		return nil
	case emplacement.FieldIcone:
		m.ResetIcone()
		return nil
	case emplacement.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case emplacement.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Emplacement field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *EmplacementMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.parent != nil {
		edges = append(edges, emplacement.EdgeParent)
	}
	if m.enfants != nil {
		edges = append(edges, emplacement.EdgeEnfants)
	}
	if m.liens_objets != nil {
		edges = append(edges, emplacement.EdgeLiensObjets)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *EmplacementMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case emplacement.EdgeParent:
		if id := m.parent; id != nil {
			return []ent.Value{*id}
		}
	case emplacement.EdgeEnfants:
		ids := make([]ent.Value, 0, len(m.enfants))
		for id := range m.enfants {
			ids = append(ids, id)
		}
		return ids
	case emplacement.EdgeLiensObjets:
		ids := make([]ent.Value, 0, len(m.liens_objets))
		for id := range m.liens_objets {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *EmplacementMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedenfants != nil {
		edges = append(edges, emplacement.EdgeEnfants)
	}
	if m.removedliens_objets != nil {
		edges = append(edges, emplacement.EdgeLiensObjets)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *EmplacementMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedparent {
		edges = append(edges, emplacement.EdgeParent)
	}
	if m.clearedenfants {
		edges = append(edges, emplacement.EdgeEnfants)
	}
	if m.clearedliens_objets {
		edges = append(edges, emplacement.EdgeLiensObjets)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *EmplacementMutation) EdgeCleared(name string) bool {
	switch name {
	case emplacement.EdgeParent:
		return m.clearedparent
	case emplacement.EdgeEnfants:
		return m.clearedenfants
	case emplacement.EdgeLiensObjets:
		return m.clearedliens_objets
	}
	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 *EmplacementMutation) ClearEdge(name string) error {
	switch name {
	case emplacement.EdgeParent:
		m.ClearParent()
		return nil
	}
	return fmt.Errorf("unknown Emplacement 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 *EmplacementMutation) ResetEdge(name string) error {
	switch name {
	case emplacement.EdgeParent:
		m.ResetParent()
		return nil
	case emplacement.EdgeEnfants:
		m.ResetEnfants()
		return nil
	case emplacement.EdgeLiensObjets:
		m.ResetLiensObjets()
		return nil
	}
	return fmt.Errorf("unknown Emplacement edge %s", name)
}

// LienObjetEmplacementMutation represents an operation that mutates the LienObjetEmplacement nodes in the graph.
type LienObjetEmplacementMutation struct {
	config
	op                 Op
	typ                string
	id                 *uuid.UUID
	_type              *lienobjetemplacement.Type
	created_at         *time.Time
	updated_at         *time.Time
	clearedFields      map[string]struct{}
	objet              *uuid.UUID
	clearedobjet       bool
	emplacement        *uuid.UUID
	clearedemplacement bool
	done               bool
	oldValue           func(context.Context) (*LienObjetEmplacement, error)
	predicates         []predicate.LienObjetEmplacement
}

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

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

// newLienObjetEmplacementMutation creates new mutation for the LienObjetEmplacement entity.
func newLienObjetEmplacementMutation(c config, op Op, opts ...lienobjetemplacementOption) *LienObjetEmplacementMutation {
	m := &LienObjetEmplacementMutation{
		config:        c,
		op:            op,
		typ:           TypeLienObjetEmplacement,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withLienObjetEmplacement sets the old LienObjetEmplacement of the mutation.
func withLienObjetEmplacement(node *LienObjetEmplacement) lienobjetemplacementOption {
	return func(m *LienObjetEmplacementMutation) {
		m.oldValue = func(context.Context) (*LienObjetEmplacement, 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 LienObjetEmplacementMutation) 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 LienObjetEmplacementMutation) 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 LienObjetEmplacement entities.
func (m *LienObjetEmplacementMutation) SetID(id uuid.UUID) {
	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 *LienObjetEmplacementMutation) ID() (id uuid.UUID, 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 *LienObjetEmplacementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().LienObjetEmplacement.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetObjetID sets the "objet_id" field.
func (m *LienObjetEmplacementMutation) SetObjetID(u uuid.UUID) {
	m.objet = &u
}

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

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

// ResetObjetID resets all changes to the "objet_id" field.
func (m *LienObjetEmplacementMutation) ResetObjetID() {
	m.objet = nil
}

// SetEmplacementID sets the "emplacement_id" field.
func (m *LienObjetEmplacementMutation) SetEmplacementID(u uuid.UUID) {
	m.emplacement = &u
}

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

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

// ResetEmplacementID resets all changes to the "emplacement_id" field.
func (m *LienObjetEmplacementMutation) ResetEmplacementID() {
	m.emplacement = nil
}

// SetType sets the "type" field.
func (m *LienObjetEmplacementMutation) SetType(l lienobjetemplacement.Type) {
	m._type = &l
}

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

// OldType returns the old "type" field's value of the LienObjetEmplacement entity.
// If the LienObjetEmplacement 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 *LienObjetEmplacementMutation) OldType(ctx context.Context) (v lienobjetemplacement.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 *LienObjetEmplacementMutation) ResetType() {
	m._type = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *LienObjetEmplacementMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *LienObjetEmplacementMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *LienObjetEmplacementMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *LienObjetEmplacementMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearObjet clears the "objet" edge to the Objet entity.
func (m *LienObjetEmplacementMutation) ClearObjet() {
	m.clearedobjet = true
	m.clearedFields[lienobjetemplacement.FieldObjetID] = struct{}{}
}

// ObjetCleared reports if the "objet" edge to the Objet entity was cleared.
func (m *LienObjetEmplacementMutation) ObjetCleared() bool {
	return m.clearedobjet
}

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

// ResetObjet resets all changes to the "objet" edge.
func (m *LienObjetEmplacementMutation) ResetObjet() {
	m.objet = nil
	m.clearedobjet = false
}

// ClearEmplacement clears the "emplacement" edge to the Emplacement entity.
func (m *LienObjetEmplacementMutation) ClearEmplacement() {
	m.clearedemplacement = true
	m.clearedFields[lienobjetemplacement.FieldEmplacementID] = struct{}{}
}

// EmplacementCleared reports if the "emplacement" edge to the Emplacement entity was cleared.
func (m *LienObjetEmplacementMutation) EmplacementCleared() bool {
	return m.clearedemplacement
}

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

// ResetEmplacement resets all changes to the "emplacement" edge.
func (m *LienObjetEmplacementMutation) ResetEmplacement() {
	m.emplacement = nil
	m.clearedemplacement = false
}

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

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

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

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

// Type returns the node type of this mutation (LienObjetEmplacement).
func (m *LienObjetEmplacementMutation) 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 *LienObjetEmplacementMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.objet != nil {
		fields = append(fields, lienobjetemplacement.FieldObjetID)
	}
	if m.emplacement != nil {
		fields = append(fields, lienobjetemplacement.FieldEmplacementID)
	}
	if m._type != nil {
		fields = append(fields, lienobjetemplacement.FieldType)
	}
	if m.created_at != nil {
		fields = append(fields, lienobjetemplacement.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, lienobjetemplacement.FieldUpdatedAt)
	}
	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 *LienObjetEmplacementMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case lienobjetemplacement.FieldObjetID:
		return m.ObjetID()
	case lienobjetemplacement.FieldEmplacementID:
		return m.EmplacementID()
	case lienobjetemplacement.FieldType:
		return m.GetType()
	case lienobjetemplacement.FieldCreatedAt:
		return m.CreatedAt()
	case lienobjetemplacement.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *LienObjetEmplacementMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case lienobjetemplacement.FieldObjetID:
		return m.OldObjetID(ctx)
	case lienobjetemplacement.FieldEmplacementID:
		return m.OldEmplacementID(ctx)
	case lienobjetemplacement.FieldType:
		return m.OldType(ctx)
	case lienobjetemplacement.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case lienobjetemplacement.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown LienObjetEmplacement 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 *LienObjetEmplacementMutation) SetField(name string, value ent.Value) error {
	switch name {
	case lienobjetemplacement.FieldObjetID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetObjetID(v)
		return nil
	case lienobjetemplacement.FieldEmplacementID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEmplacementID(v)
		return nil
	case lienobjetemplacement.FieldType:
		v, ok := value.(lienobjetemplacement.Type)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case lienobjetemplacement.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case lienobjetemplacement.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown LienObjetEmplacement field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *LienObjetEmplacementMutation) 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 *LienObjetEmplacementMutation) ClearField(name string) error {
	return fmt.Errorf("unknown LienObjetEmplacement 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 *LienObjetEmplacementMutation) ResetField(name string) error {
	switch name {
	case lienobjetemplacement.FieldObjetID:
		m.ResetObjetID()
		return nil
	case lienobjetemplacement.FieldEmplacementID:
		m.ResetEmplacementID()
		return nil
	case lienobjetemplacement.FieldType:
		m.ResetType()
		return nil
	case lienobjetemplacement.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case lienobjetemplacement.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown LienObjetEmplacement field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *LienObjetEmplacementMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.objet != nil {
		edges = append(edges, lienobjetemplacement.EdgeObjet)
	}
	if m.emplacement != nil {
		edges = append(edges, lienobjetemplacement.EdgeEmplacement)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *LienObjetEmplacementMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedobjet {
		edges = append(edges, lienobjetemplacement.EdgeObjet)
	}
	if m.clearedemplacement {
		edges = append(edges, lienobjetemplacement.EdgeEmplacement)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *LienObjetEmplacementMutation) EdgeCleared(name string) bool {
	switch name {
	case lienobjetemplacement.EdgeObjet:
		return m.clearedobjet
	case lienobjetemplacement.EdgeEmplacement:
		return m.clearedemplacement
	}
	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 *LienObjetEmplacementMutation) ClearEdge(name string) error {
	switch name {
	case lienobjetemplacement.EdgeObjet:
		m.ClearObjet()
		return nil
	case lienobjetemplacement.EdgeEmplacement:
		m.ClearEmplacement()
		return nil
	}
	return fmt.Errorf("unknown LienObjetEmplacement 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 *LienObjetEmplacementMutation) ResetEdge(name string) error {
	switch name {
	case lienobjetemplacement.EdgeObjet:
		m.ResetObjet()
		return nil
	case lienobjetemplacement.EdgeEmplacement:
		m.ResetEmplacement()
		return nil
	}
	return fmt.Errorf("unknown LienObjetEmplacement edge %s", name)
}

// ObjetMutation represents an operation that mutates the Objet nodes in the graph.
type ObjetMutation struct {
	config
	op                          Op
	typ                         string
	id                          *uuid.UUID
	nom                         *string
	description                 *string
	quantite                    *int
	addquantite                 *int
	prix_achat                  *float64
	addprix_achat               *float64
	date_achat                  *time.Time
	boutique                    *string
	numero_serie                *string
	numero_modele               *string
	fabricant                   *string
	statut                      *objet.Statut
	caracteristiques            *map[string]interface{}
	created_at                  *time.Time
	updated_at                  *time.Time
	clearedFields               map[string]struct{}
	liens_emplacements          map[uuid.UUID]struct{}
	removedliens_emplacements   map[uuid.UUID]struct{}
	clearedliens_emplacements   bool
	champs_personnalises        map[uuid.UUID]struct{}
	removedchamps_personnalises map[uuid.UUID]struct{}
	clearedchamps_personnalises bool
	pieces_jointes              map[uuid.UUID]struct{}
	removedpieces_jointes       map[uuid.UUID]struct{}
	clearedpieces_jointes       bool
	done                        bool
	oldValue                    func(context.Context) (*Objet, error)
	predicates                  []predicate.Objet
}

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

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

// newObjetMutation creates new mutation for the Objet entity.
func newObjetMutation(c config, op Op, opts ...objetOption) *ObjetMutation {
	m := &ObjetMutation{
		config:        c,
		op:            op,
		typ:           TypeObjet,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withObjet sets the old Objet of the mutation.
func withObjet(node *Objet) objetOption {
	return func(m *ObjetMutation) {
		m.oldValue = func(context.Context) (*Objet, 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 ObjetMutation) 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 ObjetMutation) 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 Objet entities.
func (m *ObjetMutation) SetID(id uuid.UUID) {
	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 *ObjetMutation) ID() (id uuid.UUID, 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 *ObjetMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Objet.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetNom sets the "nom" field.
func (m *ObjetMutation) SetNom(s string) {
	m.nom = &s
}

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

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

// ResetNom resets all changes to the "nom" field.
func (m *ObjetMutation) ResetNom() {
	m.nom = nil
}

// SetDescription sets the "description" field.
func (m *ObjetMutation) SetDescription(s string) {
	m.description = &s
}

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

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

// ClearDescription clears the value of the "description" field.
func (m *ObjetMutation) ClearDescription() {
	m.description = nil
	m.clearedFields[objet.FieldDescription] = struct{}{}
}

// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *ObjetMutation) DescriptionCleared() bool {
	_, ok := m.clearedFields[objet.FieldDescription]
	return ok
}

// ResetDescription resets all changes to the "description" field.
func (m *ObjetMutation) ResetDescription() {
	m.description = nil
	delete(m.clearedFields, objet.FieldDescription)
}

// SetQuantite sets the "quantite" field.
func (m *ObjetMutation) SetQuantite(i int) {
	m.quantite = &i
	m.addquantite = nil
}

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

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

// AddQuantite adds i to the "quantite" field.
func (m *ObjetMutation) AddQuantite(i int) {
	if m.addquantite != nil {
		*m.addquantite += i
	} else {
		m.addquantite = &i
	}
}

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

// ResetQuantite resets all changes to the "quantite" field.
func (m *ObjetMutation) ResetQuantite() {
	m.quantite = nil
	m.addquantite = nil
}

// SetPrixAchat sets the "prix_achat" field.
func (m *ObjetMutation) SetPrixAchat(f float64) {
	m.prix_achat = &f
	m.addprix_achat = nil
}

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

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

// AddPrixAchat adds f to the "prix_achat" field.
func (m *ObjetMutation) AddPrixAchat(f float64) {
	if m.addprix_achat != nil {
		*m.addprix_achat += f
	} else {
		m.addprix_achat = &f
	}
}

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

// ClearPrixAchat clears the value of the "prix_achat" field.
func (m *ObjetMutation) ClearPrixAchat() {
	m.prix_achat = nil
	m.addprix_achat = nil
	m.clearedFields[objet.FieldPrixAchat] = struct{}{}
}

// PrixAchatCleared returns if the "prix_achat" field was cleared in this mutation.
func (m *ObjetMutation) PrixAchatCleared() bool {
	_, ok := m.clearedFields[objet.FieldPrixAchat]
	return ok
}

// ResetPrixAchat resets all changes to the "prix_achat" field.
func (m *ObjetMutation) ResetPrixAchat() {
	m.prix_achat = nil
	m.addprix_achat = nil
	delete(m.clearedFields, objet.FieldPrixAchat)
}

// SetDateAchat sets the "date_achat" field.
func (m *ObjetMutation) SetDateAchat(t time.Time) {
	m.date_achat = &t
}

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

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

// ClearDateAchat clears the value of the "date_achat" field.
func (m *ObjetMutation) ClearDateAchat() {
	m.date_achat = nil
	m.clearedFields[objet.FieldDateAchat] = struct{}{}
}

// DateAchatCleared returns if the "date_achat" field was cleared in this mutation.
func (m *ObjetMutation) DateAchatCleared() bool {
	_, ok := m.clearedFields[objet.FieldDateAchat]
	return ok
}

// ResetDateAchat resets all changes to the "date_achat" field.
func (m *ObjetMutation) ResetDateAchat() {
	m.date_achat = nil
	delete(m.clearedFields, objet.FieldDateAchat)
}

// SetBoutique sets the "boutique" field.
func (m *ObjetMutation) SetBoutique(s string) {
	m.boutique = &s
}

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

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

// ClearBoutique clears the value of the "boutique" field.
func (m *ObjetMutation) ClearBoutique() {
	m.boutique = nil
	m.clearedFields[objet.FieldBoutique] = struct{}{}
}

// BoutiqueCleared returns if the "boutique" field was cleared in this mutation.
func (m *ObjetMutation) BoutiqueCleared() bool {
	_, ok := m.clearedFields[objet.FieldBoutique]
	return ok
}

// ResetBoutique resets all changes to the "boutique" field.
func (m *ObjetMutation) ResetBoutique() {
	m.boutique = nil
	delete(m.clearedFields, objet.FieldBoutique)
}

// SetNumeroSerie sets the "numero_serie" field.
func (m *ObjetMutation) SetNumeroSerie(s string) {
	m.numero_serie = &s
}

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

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

// ClearNumeroSerie clears the value of the "numero_serie" field.
func (m *ObjetMutation) ClearNumeroSerie() {
	m.numero_serie = nil
	m.clearedFields[objet.FieldNumeroSerie] = struct{}{}
}

// NumeroSerieCleared returns if the "numero_serie" field was cleared in this mutation.
func (m *ObjetMutation) NumeroSerieCleared() bool {
	_, ok := m.clearedFields[objet.FieldNumeroSerie]
	return ok
}

// ResetNumeroSerie resets all changes to the "numero_serie" field.
func (m *ObjetMutation) ResetNumeroSerie() {
	m.numero_serie = nil
	delete(m.clearedFields, objet.FieldNumeroSerie)
}

// SetNumeroModele sets the "numero_modele" field.
func (m *ObjetMutation) SetNumeroModele(s string) {
	m.numero_modele = &s
}

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

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

// ClearNumeroModele clears the value of the "numero_modele" field.
func (m *ObjetMutation) ClearNumeroModele() {
	m.numero_modele = nil
	m.clearedFields[objet.FieldNumeroModele] = struct{}{}
}

// NumeroModeleCleared returns if the "numero_modele" field was cleared in this mutation.
func (m *ObjetMutation) NumeroModeleCleared() bool {
	_, ok := m.clearedFields[objet.FieldNumeroModele]
	return ok
}

// ResetNumeroModele resets all changes to the "numero_modele" field.
func (m *ObjetMutation) ResetNumeroModele() {
	m.numero_modele = nil
	delete(m.clearedFields, objet.FieldNumeroModele)
}

// SetFabricant sets the "fabricant" field.
func (m *ObjetMutation) SetFabricant(s string) {
	m.fabricant = &s
}

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

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

// ClearFabricant clears the value of the "fabricant" field.
func (m *ObjetMutation) ClearFabricant() {
	m.fabricant = nil
	m.clearedFields[objet.FieldFabricant] = struct{}{}
}

// FabricantCleared returns if the "fabricant" field was cleared in this mutation.
func (m *ObjetMutation) FabricantCleared() bool {
	_, ok := m.clearedFields[objet.FieldFabricant]
	return ok
}

// ResetFabricant resets all changes to the "fabricant" field.
func (m *ObjetMutation) ResetFabricant() {
	m.fabricant = nil
	delete(m.clearedFields, objet.FieldFabricant)
}

// SetStatut sets the "statut" field.
func (m *ObjetMutation) SetStatut(o objet.Statut) {
	m.statut = &o
}

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

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

// ResetStatut resets all changes to the "statut" field.
func (m *ObjetMutation) ResetStatut() {
	m.statut = nil
}

// SetCaracteristiques sets the "caracteristiques" field.
func (m *ObjetMutation) SetCaracteristiques(value map[string]interface{}) {
	m.caracteristiques = &value
}

// Caracteristiques returns the value of the "caracteristiques" field in the mutation.
func (m *ObjetMutation) Caracteristiques() (r map[string]interface{}, exists bool) {
	v := m.caracteristiques
	if v == nil {
		return
	}
	return *v, true
}

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

// ClearCaracteristiques clears the value of the "caracteristiques" field.
func (m *ObjetMutation) ClearCaracteristiques() {
	m.caracteristiques = nil
	m.clearedFields[objet.FieldCaracteristiques] = struct{}{}
}

// CaracteristiquesCleared returns if the "caracteristiques" field was cleared in this mutation.
func (m *ObjetMutation) CaracteristiquesCleared() bool {
	_, ok := m.clearedFields[objet.FieldCaracteristiques]
	return ok
}

// ResetCaracteristiques resets all changes to the "caracteristiques" field.
func (m *ObjetMutation) ResetCaracteristiques() {
	m.caracteristiques = nil
	delete(m.clearedFields, objet.FieldCaracteristiques)
}

// SetCreatedAt sets the "created_at" field.
func (m *ObjetMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *ObjetMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *ObjetMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *ObjetMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// AddLiensEmplacementIDs adds the "liens_emplacements" edge to the LienObjetEmplacement entity by ids.
func (m *ObjetMutation) AddLiensEmplacementIDs(ids ...uuid.UUID) {
	if m.liens_emplacements == nil {
		m.liens_emplacements = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.liens_emplacements[ids[i]] = struct{}{}
	}
}

// ClearLiensEmplacements clears the "liens_emplacements" edge to the LienObjetEmplacement entity.
func (m *ObjetMutation) ClearLiensEmplacements() {
	m.clearedliens_emplacements = true
}

// LiensEmplacementsCleared reports if the "liens_emplacements" edge to the LienObjetEmplacement entity was cleared.
func (m *ObjetMutation) LiensEmplacementsCleared() bool {
	return m.clearedliens_emplacements
}

// RemoveLiensEmplacementIDs removes the "liens_emplacements" edge to the LienObjetEmplacement entity by IDs.
func (m *ObjetMutation) RemoveLiensEmplacementIDs(ids ...uuid.UUID) {
	if m.removedliens_emplacements == nil {
		m.removedliens_emplacements = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.liens_emplacements, ids[i])
		m.removedliens_emplacements[ids[i]] = struct{}{}
	}
}

// RemovedLiensEmplacements returns the removed IDs of the "liens_emplacements" edge to the LienObjetEmplacement entity.
func (m *ObjetMutation) RemovedLiensEmplacementsIDs() (ids []uuid.UUID) {
	for id := range m.removedliens_emplacements {
		ids = append(ids, id)
	}
	return
}

// LiensEmplacementsIDs returns the "liens_emplacements" edge IDs in the mutation.
func (m *ObjetMutation) LiensEmplacementsIDs() (ids []uuid.UUID) {
	for id := range m.liens_emplacements {
		ids = append(ids, id)
	}
	return
}

// ResetLiensEmplacements resets all changes to the "liens_emplacements" edge.
func (m *ObjetMutation) ResetLiensEmplacements() {
	m.liens_emplacements = nil
	m.clearedliens_emplacements = false
	m.removedliens_emplacements = nil
}

// AddChampsPersonnaliseIDs adds the "champs_personnalises" edge to the ChampPersonnalise entity by ids.
func (m *ObjetMutation) AddChampsPersonnaliseIDs(ids ...uuid.UUID) {
	if m.champs_personnalises == nil {
		m.champs_personnalises = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.champs_personnalises[ids[i]] = struct{}{}
	}
}

// ClearChampsPersonnalises clears the "champs_personnalises" edge to the ChampPersonnalise entity.
func (m *ObjetMutation) ClearChampsPersonnalises() {
	m.clearedchamps_personnalises = true
}

// ChampsPersonnalisesCleared reports if the "champs_personnalises" edge to the ChampPersonnalise entity was cleared.
func (m *ObjetMutation) ChampsPersonnalisesCleared() bool {
	return m.clearedchamps_personnalises
}

// RemoveChampsPersonnaliseIDs removes the "champs_personnalises" edge to the ChampPersonnalise entity by IDs.
func (m *ObjetMutation) RemoveChampsPersonnaliseIDs(ids ...uuid.UUID) {
	if m.removedchamps_personnalises == nil {
		m.removedchamps_personnalises = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.champs_personnalises, ids[i])
		m.removedchamps_personnalises[ids[i]] = struct{}{}
	}
}

// RemovedChampsPersonnalises returns the removed IDs of the "champs_personnalises" edge to the ChampPersonnalise entity.
func (m *ObjetMutation) RemovedChampsPersonnalisesIDs() (ids []uuid.UUID) {
	for id := range m.removedchamps_personnalises {
		ids = append(ids, id)
	}
	return
}

// ChampsPersonnalisesIDs returns the "champs_personnalises" edge IDs in the mutation.
func (m *ObjetMutation) ChampsPersonnalisesIDs() (ids []uuid.UUID) {
	for id := range m.champs_personnalises {
		ids = append(ids, id)
	}
	return
}

// ResetChampsPersonnalises resets all changes to the "champs_personnalises" edge.
func (m *ObjetMutation) ResetChampsPersonnalises() {
	m.champs_personnalises = nil
	m.clearedchamps_personnalises = false
	m.removedchamps_personnalises = nil
}

// AddPiecesJointeIDs adds the "pieces_jointes" edge to the PieceJointe entity by ids.
func (m *ObjetMutation) AddPiecesJointeIDs(ids ...uuid.UUID) {
	if m.pieces_jointes == nil {
		m.pieces_jointes = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.pieces_jointes[ids[i]] = struct{}{}
	}
}

// ClearPiecesJointes clears the "pieces_jointes" edge to the PieceJointe entity.
func (m *ObjetMutation) ClearPiecesJointes() {
	m.clearedpieces_jointes = true
}

// PiecesJointesCleared reports if the "pieces_jointes" edge to the PieceJointe entity was cleared.
func (m *ObjetMutation) PiecesJointesCleared() bool {
	return m.clearedpieces_jointes
}

// RemovePiecesJointeIDs removes the "pieces_jointes" edge to the PieceJointe entity by IDs.
func (m *ObjetMutation) RemovePiecesJointeIDs(ids ...uuid.UUID) {
	if m.removedpieces_jointes == nil {
		m.removedpieces_jointes = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.pieces_jointes, ids[i])
		m.removedpieces_jointes[ids[i]] = struct{}{}
	}
}

// RemovedPiecesJointes returns the removed IDs of the "pieces_jointes" edge to the PieceJointe entity.
func (m *ObjetMutation) RemovedPiecesJointesIDs() (ids []uuid.UUID) {
	for id := range m.removedpieces_jointes {
		ids = append(ids, id)
	}
	return
}

// PiecesJointesIDs returns the "pieces_jointes" edge IDs in the mutation.
func (m *ObjetMutation) PiecesJointesIDs() (ids []uuid.UUID) {
	for id := range m.pieces_jointes {
		ids = append(ids, id)
	}
	return
}

// ResetPiecesJointes resets all changes to the "pieces_jointes" edge.
func (m *ObjetMutation) ResetPiecesJointes() {
	m.pieces_jointes = nil
	m.clearedpieces_jointes = false
	m.removedpieces_jointes = nil
}

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

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

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

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

// Type returns the node type of this mutation (Objet).
func (m *ObjetMutation) 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 *ObjetMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.nom != nil {
		fields = append(fields, objet.FieldNom)
	}
	if m.description != nil {
		fields = append(fields, objet.FieldDescription)
	}
	if m.quantite != nil {
		fields = append(fields, objet.FieldQuantite)
	}
	if m.prix_achat != nil {
		fields = append(fields, objet.FieldPrixAchat)
	}
	if m.date_achat != nil {
		fields = append(fields, objet.FieldDateAchat)
	}
	if m.boutique != nil {
		fields = append(fields, objet.FieldBoutique)
	}
	if m.numero_serie != nil {
		fields = append(fields, objet.FieldNumeroSerie)
	}
	if m.numero_modele != nil {
		fields = append(fields, objet.FieldNumeroModele)
	}
	if m.fabricant != nil {
		fields = append(fields, objet.FieldFabricant)
	}
	if m.statut != nil {
		fields = append(fields, objet.FieldStatut)
	}
	if m.caracteristiques != nil {
		fields = append(fields, objet.FieldCaracteristiques)
	}
	if m.created_at != nil {
		fields = append(fields, objet.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, objet.FieldUpdatedAt)
	}
	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 *ObjetMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case objet.FieldNom:
		return m.Nom()
	case objet.FieldDescription:
		return m.Description()
	case objet.FieldQuantite:
		return m.Quantite()
	case objet.FieldPrixAchat:
		return m.PrixAchat()
	case objet.FieldDateAchat:
		return m.DateAchat()
	case objet.FieldBoutique:
		return m.Boutique()
	case objet.FieldNumeroSerie:
		return m.NumeroSerie()
	case objet.FieldNumeroModele:
		return m.NumeroModele()
	case objet.FieldFabricant:
		return m.Fabricant()
	case objet.FieldStatut:
		return m.Statut()
	case objet.FieldCaracteristiques:
		return m.Caracteristiques()
	case objet.FieldCreatedAt:
		return m.CreatedAt()
	case objet.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *ObjetMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case objet.FieldNom:
		return m.OldNom(ctx)
	case objet.FieldDescription:
		return m.OldDescription(ctx)
	case objet.FieldQuantite:
		return m.OldQuantite(ctx)
	case objet.FieldPrixAchat:
		return m.OldPrixAchat(ctx)
	case objet.FieldDateAchat:
		return m.OldDateAchat(ctx)
	case objet.FieldBoutique:
		return m.OldBoutique(ctx)
	case objet.FieldNumeroSerie:
		return m.OldNumeroSerie(ctx)
	case objet.FieldNumeroModele:
		return m.OldNumeroModele(ctx)
	case objet.FieldFabricant:
		return m.OldFabricant(ctx)
	case objet.FieldStatut:
		return m.OldStatut(ctx)
	case objet.FieldCaracteristiques:
		return m.OldCaracteristiques(ctx)
	case objet.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case objet.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Objet 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 *ObjetMutation) SetField(name string, value ent.Value) error {
	switch name {
	case objet.FieldNom:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNom(v)
		return nil
	case objet.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case objet.FieldQuantite:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetQuantite(v)
		return nil
	case objet.FieldPrixAchat:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrixAchat(v)
		return nil
	case objet.FieldDateAchat:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDateAchat(v)
		return nil
	case objet.FieldBoutique:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBoutique(v)
		return nil
	case objet.FieldNumeroSerie:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNumeroSerie(v)
		return nil
	case objet.FieldNumeroModele:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNumeroModele(v)
		return nil
	case objet.FieldFabricant:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFabricant(v)
		return nil
	case objet.FieldStatut:
		v, ok := value.(objet.Statut)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatut(v)
		return nil
	case objet.FieldCaracteristiques:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCaracteristiques(v)
		return nil
	case objet.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case objet.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Objet field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ObjetMutation) AddedFields() []string {
	var fields []string
	if m.addquantite != nil {
		fields = append(fields, objet.FieldQuantite)
	}
	if m.addprix_achat != nil {
		fields = append(fields, objet.FieldPrixAchat)
	}
	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 *ObjetMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case objet.FieldQuantite:
		return m.AddedQuantite()
	case objet.FieldPrixAchat:
		return m.AddedPrixAchat()
	}
	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 *ObjetMutation) AddField(name string, value ent.Value) error {
	switch name {
	case objet.FieldQuantite:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddQuantite(v)
		return nil
	case objet.FieldPrixAchat:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPrixAchat(v)
		return nil
	}
	return fmt.Errorf("unknown Objet numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ObjetMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(objet.FieldDescription) {
		fields = append(fields, objet.FieldDescription)
	}
	if m.FieldCleared(objet.FieldPrixAchat) {
		fields = append(fields, objet.FieldPrixAchat)
	}
	if m.FieldCleared(objet.FieldDateAchat) {
		fields = append(fields, objet.FieldDateAchat)
	}
	if m.FieldCleared(objet.FieldBoutique) {
		fields = append(fields, objet.FieldBoutique)
	}
	if m.FieldCleared(objet.FieldNumeroSerie) {
		fields = append(fields, objet.FieldNumeroSerie)
	}
	if m.FieldCleared(objet.FieldNumeroModele) {
		fields = append(fields, objet.FieldNumeroModele)
	}
	if m.FieldCleared(objet.FieldFabricant) {
		fields = append(fields, objet.FieldFabricant)
	}
	if m.FieldCleared(objet.FieldCaracteristiques) {
		fields = append(fields, objet.FieldCaracteristiques)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ObjetMutation) 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 *ObjetMutation) ClearField(name string) error {
	switch name {
	case objet.FieldDescription:
		m.ClearDescription()
		return nil
	case objet.FieldPrixAchat:
		m.ClearPrixAchat()
		return nil
	case objet.FieldDateAchat:
		m.ClearDateAchat()
		return nil
	case objet.FieldBoutique:
		m.ClearBoutique()
		return nil
	case objet.FieldNumeroSerie:
		m.ClearNumeroSerie()
		return nil
	case objet.FieldNumeroModele:
		m.ClearNumeroModele()
		return nil
	case objet.FieldFabricant:
		m.ClearFabricant()
		return nil
	case objet.FieldCaracteristiques:
		m.ClearCaracteristiques()
		return nil
	}
	return fmt.Errorf("unknown Objet 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 *ObjetMutation) ResetField(name string) error {
	switch name {
	case objet.FieldNom:
		m.ResetNom()
		return nil
	case objet.FieldDescription:
		m.ResetDescription()
		return nil
	case objet.FieldQuantite:
		m.ResetQuantite()
		return nil
	case objet.FieldPrixAchat:
		m.ResetPrixAchat()
		return nil
	case objet.FieldDateAchat:
		m.ResetDateAchat()
		return nil
	case objet.FieldBoutique:
		m.ResetBoutique()
		return nil
	case objet.FieldNumeroSerie:
		m.ResetNumeroSerie()
		return nil
	case objet.FieldNumeroModele:
		m.ResetNumeroModele()
		return nil
	case objet.FieldFabricant:
		m.ResetFabricant()
		return nil
	case objet.FieldStatut:
		m.ResetStatut()
		return nil
	case objet.FieldCaracteristiques:
		m.ResetCaracteristiques()
		return nil
	case objet.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case objet.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Objet field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ObjetMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.liens_emplacements != nil {
		edges = append(edges, objet.EdgeLiensEmplacements)
	}
	if m.champs_personnalises != nil {
		edges = append(edges, objet.EdgeChampsPersonnalises)
	}
	if m.pieces_jointes != nil {
		edges = append(edges, objet.EdgePiecesJointes)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ObjetMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case objet.EdgeLiensEmplacements:
		ids := make([]ent.Value, 0, len(m.liens_emplacements))
		for id := range m.liens_emplacements {
			ids = append(ids, id)
		}
		return ids
	case objet.EdgeChampsPersonnalises:
		ids := make([]ent.Value, 0, len(m.champs_personnalises))
		for id := range m.champs_personnalises {
			ids = append(ids, id)
		}
		return ids
	case objet.EdgePiecesJointes:
		ids := make([]ent.Value, 0, len(m.pieces_jointes))
		for id := range m.pieces_jointes {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ObjetMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedliens_emplacements != nil {
		edges = append(edges, objet.EdgeLiensEmplacements)
	}
	if m.removedchamps_personnalises != nil {
		edges = append(edges, objet.EdgeChampsPersonnalises)
	}
	if m.removedpieces_jointes != nil {
		edges = append(edges, objet.EdgePiecesJointes)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ObjetMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case objet.EdgeLiensEmplacements:
		ids := make([]ent.Value, 0, len(m.removedliens_emplacements))
		for id := range m.removedliens_emplacements {
			ids = append(ids, id)
		}
		return ids
	case objet.EdgeChampsPersonnalises:
		ids := make([]ent.Value, 0, len(m.removedchamps_personnalises))
		for id := range m.removedchamps_personnalises {
			ids = append(ids, id)
		}
		return ids
	case objet.EdgePiecesJointes:
		ids := make([]ent.Value, 0, len(m.removedpieces_jointes))
		for id := range m.removedpieces_jointes {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ObjetMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedliens_emplacements {
		edges = append(edges, objet.EdgeLiensEmplacements)
	}
	if m.clearedchamps_personnalises {
		edges = append(edges, objet.EdgeChampsPersonnalises)
	}
	if m.clearedpieces_jointes {
		edges = append(edges, objet.EdgePiecesJointes)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ObjetMutation) EdgeCleared(name string) bool {
	switch name {
	case objet.EdgeLiensEmplacements:
		return m.clearedliens_emplacements
	case objet.EdgeChampsPersonnalises:
		return m.clearedchamps_personnalises
	case objet.EdgePiecesJointes:
		return m.clearedpieces_jointes
	}
	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 *ObjetMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Objet 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 *ObjetMutation) ResetEdge(name string) error {
	switch name {
	case objet.EdgeLiensEmplacements:
		m.ResetLiensEmplacements()
		return nil
	case objet.EdgeChampsPersonnalises:
		m.ResetChampsPersonnalises()
		return nil
	case objet.EdgePiecesJointes:
		m.ResetPiecesJointes()
		return nil
	}
	return fmt.Errorf("unknown Objet edge %s", name)
}

// PieceJointeMutation represents an operation that mutates the PieceJointe nodes in the graph.
type PieceJointeMutation struct {
	config
	op             Op
	typ            string
	id             *uuid.UUID
	nom_fichier    *string
	chemin         *string
	type_mime      *string
	est_principale *bool
	categorie      *piecejointe.Categorie
	created_at     *time.Time
	updated_at     *time.Time
	clearedFields  map[string]struct{}
	objet          *uuid.UUID
	clearedobjet   bool
	done           bool
	oldValue       func(context.Context) (*PieceJointe, error)
	predicates     []predicate.PieceJointe
}

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

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

// newPieceJointeMutation creates new mutation for the PieceJointe entity.
func newPieceJointeMutation(c config, op Op, opts ...piecejointeOption) *PieceJointeMutation {
	m := &PieceJointeMutation{
		config:        c,
		op:            op,
		typ:           TypePieceJointe,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withPieceJointe sets the old PieceJointe of the mutation.
func withPieceJointe(node *PieceJointe) piecejointeOption {
	return func(m *PieceJointeMutation) {
		m.oldValue = func(context.Context) (*PieceJointe, 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 PieceJointeMutation) 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 PieceJointeMutation) 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 PieceJointe entities.
func (m *PieceJointeMutation) SetID(id uuid.UUID) {
	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 *PieceJointeMutation) ID() (id uuid.UUID, 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 *PieceJointeMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PieceJointe.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetObjetID sets the "objet_id" field.
func (m *PieceJointeMutation) SetObjetID(u uuid.UUID) {
	m.objet = &u
}

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

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

// ResetObjetID resets all changes to the "objet_id" field.
func (m *PieceJointeMutation) ResetObjetID() {
	m.objet = nil
}

// SetNomFichier sets the "nom_fichier" field.
func (m *PieceJointeMutation) SetNomFichier(s string) {
	m.nom_fichier = &s
}

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

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

// ResetNomFichier resets all changes to the "nom_fichier" field.
func (m *PieceJointeMutation) ResetNomFichier() {
	m.nom_fichier = nil
}

// SetChemin sets the "chemin" field.
func (m *PieceJointeMutation) SetChemin(s string) {
	m.chemin = &s
}

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

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

// ResetChemin resets all changes to the "chemin" field.
func (m *PieceJointeMutation) ResetChemin() {
	m.chemin = nil
}

// SetTypeMime sets the "type_mime" field.
func (m *PieceJointeMutation) SetTypeMime(s string) {
	m.type_mime = &s
}

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

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

// ResetTypeMime resets all changes to the "type_mime" field.
func (m *PieceJointeMutation) ResetTypeMime() {
	m.type_mime = nil
}

// SetEstPrincipale sets the "est_principale" field.
func (m *PieceJointeMutation) SetEstPrincipale(b bool) {
	m.est_principale = &b
}

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

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

// ResetEstPrincipale resets all changes to the "est_principale" field.
func (m *PieceJointeMutation) ResetEstPrincipale() {
	m.est_principale = nil
}

// SetCategorie sets the "categorie" field.
func (m *PieceJointeMutation) SetCategorie(pi piecejointe.Categorie) {
	m.categorie = &pi
}

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

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

// ResetCategorie resets all changes to the "categorie" field.
func (m *PieceJointeMutation) ResetCategorie() {
	m.categorie = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *PieceJointeMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

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

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

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PieceJointeMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PieceJointeMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

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

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

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PieceJointeMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearObjet clears the "objet" edge to the Objet entity.
func (m *PieceJointeMutation) ClearObjet() {
	m.clearedobjet = true
	m.clearedFields[piecejointe.FieldObjetID] = struct{}{}
}

// ObjetCleared reports if the "objet" edge to the Objet entity was cleared.
func (m *PieceJointeMutation) ObjetCleared() bool {
	return m.clearedobjet
}

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

// ResetObjet resets all changes to the "objet" edge.
func (m *PieceJointeMutation) ResetObjet() {
	m.objet = nil
	m.clearedobjet = false
}

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

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

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

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

// Type returns the node type of this mutation (PieceJointe).
func (m *PieceJointeMutation) 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 *PieceJointeMutation) Fields() []string {
	fields := make([]string, 0, 8)
	if m.objet != nil {
		fields = append(fields, piecejointe.FieldObjetID)
	}
	if m.nom_fichier != nil {
		fields = append(fields, piecejointe.FieldNomFichier)
	}
	if m.chemin != nil {
		fields = append(fields, piecejointe.FieldChemin)
	}
	if m.type_mime != nil {
		fields = append(fields, piecejointe.FieldTypeMime)
	}
	if m.est_principale != nil {
		fields = append(fields, piecejointe.FieldEstPrincipale)
	}
	if m.categorie != nil {
		fields = append(fields, piecejointe.FieldCategorie)
	}
	if m.created_at != nil {
		fields = append(fields, piecejointe.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, piecejointe.FieldUpdatedAt)
	}
	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 *PieceJointeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case piecejointe.FieldObjetID:
		return m.ObjetID()
	case piecejointe.FieldNomFichier:
		return m.NomFichier()
	case piecejointe.FieldChemin:
		return m.Chemin()
	case piecejointe.FieldTypeMime:
		return m.TypeMime()
	case piecejointe.FieldEstPrincipale:
		return m.EstPrincipale()
	case piecejointe.FieldCategorie:
		return m.Categorie()
	case piecejointe.FieldCreatedAt:
		return m.CreatedAt()
	case piecejointe.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *PieceJointeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case piecejointe.FieldObjetID:
		return m.OldObjetID(ctx)
	case piecejointe.FieldNomFichier:
		return m.OldNomFichier(ctx)
	case piecejointe.FieldChemin:
		return m.OldChemin(ctx)
	case piecejointe.FieldTypeMime:
		return m.OldTypeMime(ctx)
	case piecejointe.FieldEstPrincipale:
		return m.OldEstPrincipale(ctx)
	case piecejointe.FieldCategorie:
		return m.OldCategorie(ctx)
	case piecejointe.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case piecejointe.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PieceJointe 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 *PieceJointeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case piecejointe.FieldObjetID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetObjetID(v)
		return nil
	case piecejointe.FieldNomFichier:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNomFichier(v)
		return nil
	case piecejointe.FieldChemin:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChemin(v)
		return nil
	case piecejointe.FieldTypeMime:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTypeMime(v)
		return nil
	case piecejointe.FieldEstPrincipale:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEstPrincipale(v)
		return nil
	case piecejointe.FieldCategorie:
		v, ok := value.(piecejointe.Categorie)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCategorie(v)
		return nil
	case piecejointe.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case piecejointe.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PieceJointe field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PieceJointeMutation) 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 *PieceJointeMutation) ClearField(name string) error {
	return fmt.Errorf("unknown PieceJointe 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 *PieceJointeMutation) ResetField(name string) error {
	switch name {
	case piecejointe.FieldObjetID:
		m.ResetObjetID()
		return nil
	case piecejointe.FieldNomFichier:
		m.ResetNomFichier()
		return nil
	case piecejointe.FieldChemin:
		m.ResetChemin()
		return nil
	case piecejointe.FieldTypeMime:
		m.ResetTypeMime()
		return nil
	case piecejointe.FieldEstPrincipale:
		m.ResetEstPrincipale()
		return nil
	case piecejointe.FieldCategorie:
		m.ResetCategorie()
		return nil
	case piecejointe.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case piecejointe.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown PieceJointe field %s", name)
}

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PieceJointeMutation) EdgeCleared(name string) bool {
	switch name {
	case piecejointe.EdgeObjet:
		return m.clearedobjet
	}
	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 *PieceJointeMutation) ClearEdge(name string) error {
	switch name {
	case piecejointe.EdgeObjet:
		m.ClearObjet()
		return nil
	}
	return fmt.Errorf("unknown PieceJointe 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 *PieceJointeMutation) ResetEdge(name string) error {
	switch name {
	case piecejointe.EdgeObjet:
		m.ResetObjet()
		return nil
	}
	return fmt.Errorf("unknown PieceJointe edge %s", name)
}
