// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/TSELab/astra/internal/store/ent/artifact"
	"github.com/TSELab/astra/internal/store/ent/edge"
	"github.com/TSELab/astra/internal/store/ent/predicate"
	"github.com/TSELab/astra/internal/store/ent/principal"
	"github.com/TSELab/astra/internal/store/ent/resource"
	"github.com/TSELab/astra/internal/store/ent/step"
)

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

	// Node types.
	TypeArtifact  = "Artifact"
	TypeEdge      = "Edge"
	TypePrincipal = "Principal"
	TypeResource  = "Resource"
	TypeStep      = "Step"
)

// ArtifactMutation represents an operation that mutates the Artifact nodes in the graph.
type ArtifactMutation struct {
	config
	op            Op
	typ           string
	id            *int
	astra_id      *string
	name          *string
	kind          *string
	uri           *string
	version       *string
	hash          *string
	size          *int64
	addsize       *int64
	metadata      *map[string]string
	completeness  *artifact.Completeness
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Artifact, error)
	predicates    []predicate.Artifact
}

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

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

// newArtifactMutation creates new mutation for the Artifact entity.
func newArtifactMutation(c config, op Op, opts ...artifactOption) *ArtifactMutation {
	m := &ArtifactMutation{
		config:        c,
		op:            op,
		typ:           TypeArtifact,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withArtifact sets the old Artifact of the mutation.
func withArtifact(node *Artifact) artifactOption {
	return func(m *ArtifactMutation) {
		m.oldValue = func(context.Context) (*Artifact, 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 ArtifactMutation) 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 ArtifactMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

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

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

// SetAstraID sets the "astra_id" field.
func (m *ArtifactMutation) SetAstraID(s string) {
	m.astra_id = &s
}

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

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

// ResetAstraID resets all changes to the "astra_id" field.
func (m *ArtifactMutation) ResetAstraID() {
	m.astra_id = nil
}

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

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

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

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

// SetKind sets the "kind" field.
func (m *ArtifactMutation) SetKind(s string) {
	m.kind = &s
}

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

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

// ResetKind resets all changes to the "kind" field.
func (m *ArtifactMutation) ResetKind() {
	m.kind = nil
}

// SetURI sets the "uri" field.
func (m *ArtifactMutation) SetURI(s string) {
	m.uri = &s
}

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

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

// ResetURI resets all changes to the "uri" field.
func (m *ArtifactMutation) ResetURI() {
	m.uri = nil
}

// SetVersion sets the "version" field.
func (m *ArtifactMutation) SetVersion(s string) {
	m.version = &s
}

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

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

// ResetVersion resets all changes to the "version" field.
func (m *ArtifactMutation) ResetVersion() {
	m.version = nil
}

// SetHash sets the "hash" field.
func (m *ArtifactMutation) SetHash(s string) {
	m.hash = &s
}

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

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

// ResetHash resets all changes to the "hash" field.
func (m *ArtifactMutation) ResetHash() {
	m.hash = nil
}

// SetSize sets the "size" field.
func (m *ArtifactMutation) SetSize(i int64) {
	m.size = &i
	m.addsize = nil
}

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

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

// AddSize adds i to the "size" field.
func (m *ArtifactMutation) AddSize(i int64) {
	if m.addsize != nil {
		*m.addsize += i
	} else {
		m.addsize = &i
	}
}

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

// ResetSize resets all changes to the "size" field.
func (m *ArtifactMutation) ResetSize() {
	m.size = nil
	m.addsize = nil
}

// SetMetadata sets the "metadata" field.
func (m *ArtifactMutation) SetMetadata(value map[string]string) {
	m.metadata = &value
}

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

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

// ClearMetadata clears the value of the "metadata" field.
func (m *ArtifactMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[artifact.FieldMetadata] = struct{}{}
}

// MetadataCleared returns if the "metadata" field was cleared in this mutation.
func (m *ArtifactMutation) MetadataCleared() bool {
	_, ok := m.clearedFields[artifact.FieldMetadata]
	return ok
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *ArtifactMutation) ResetMetadata() {
	m.metadata = nil
	delete(m.clearedFields, artifact.FieldMetadata)
}

// SetCompleteness sets the "completeness" field.
func (m *ArtifactMutation) SetCompleteness(a artifact.Completeness) {
	m.completeness = &a
}

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

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

// ResetCompleteness resets all changes to the "completeness" field.
func (m *ArtifactMutation) ResetCompleteness() {
	m.completeness = nil
}

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

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ArtifactMutation) 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 Artifact entity.
// If the Artifact 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 *ArtifactMutation) 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 *ArtifactMutation) ResetCreatedAt() {
	m.created_at = nil
}

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

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

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

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

// Type returns the node type of this mutation (Artifact).
func (m *ArtifactMutation) 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 *ArtifactMutation) Fields() []string {
	fields := make([]string, 0, 10)
	if m.astra_id != nil {
		fields = append(fields, artifact.FieldAstraID)
	}
	if m.name != nil {
		fields = append(fields, artifact.FieldName)
	}
	if m.kind != nil {
		fields = append(fields, artifact.FieldKind)
	}
	if m.uri != nil {
		fields = append(fields, artifact.FieldURI)
	}
	if m.version != nil {
		fields = append(fields, artifact.FieldVersion)
	}
	if m.hash != nil {
		fields = append(fields, artifact.FieldHash)
	}
	if m.size != nil {
		fields = append(fields, artifact.FieldSize)
	}
	if m.metadata != nil {
		fields = append(fields, artifact.FieldMetadata)
	}
	if m.completeness != nil {
		fields = append(fields, artifact.FieldCompleteness)
	}
	if m.created_at != nil {
		fields = append(fields, artifact.FieldCreatedAt)
	}
	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 *ArtifactMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case artifact.FieldAstraID:
		return m.AstraID()
	case artifact.FieldName:
		return m.Name()
	case artifact.FieldKind:
		return m.Kind()
	case artifact.FieldURI:
		return m.URI()
	case artifact.FieldVersion:
		return m.Version()
	case artifact.FieldHash:
		return m.Hash()
	case artifact.FieldSize:
		return m.Size()
	case artifact.FieldMetadata:
		return m.Metadata()
	case artifact.FieldCompleteness:
		return m.Completeness()
	case artifact.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *ArtifactMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case artifact.FieldAstraID:
		return m.OldAstraID(ctx)
	case artifact.FieldName:
		return m.OldName(ctx)
	case artifact.FieldKind:
		return m.OldKind(ctx)
	case artifact.FieldURI:
		return m.OldURI(ctx)
	case artifact.FieldVersion:
		return m.OldVersion(ctx)
	case artifact.FieldHash:
		return m.OldHash(ctx)
	case artifact.FieldSize:
		return m.OldSize(ctx)
	case artifact.FieldMetadata:
		return m.OldMetadata(ctx)
	case artifact.FieldCompleteness:
		return m.OldCompleteness(ctx)
	case artifact.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Artifact 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 *ArtifactMutation) SetField(name string, value ent.Value) error {
	switch name {
	case artifact.FieldAstraID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAstraID(v)
		return nil
	case artifact.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case artifact.FieldKind:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKind(v)
		return nil
	case artifact.FieldURI:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetURI(v)
		return nil
	case artifact.FieldVersion:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetVersion(v)
		return nil
	case artifact.FieldHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHash(v)
		return nil
	case artifact.FieldSize:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSize(v)
		return nil
	case artifact.FieldMetadata:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	case artifact.FieldCompleteness:
		v, ok := value.(artifact.Completeness)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompleteness(v)
		return nil
	case artifact.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Artifact field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ArtifactMutation) AddedFields() []string {
	var fields []string
	if m.addsize != nil {
		fields = append(fields, artifact.FieldSize)
	}
	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 *ArtifactMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case artifact.FieldSize:
		return m.AddedSize()
	}
	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 *ArtifactMutation) AddField(name string, value ent.Value) error {
	switch name {
	case artifact.FieldSize:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSize(v)
		return nil
	}
	return fmt.Errorf("unknown Artifact numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ArtifactMutation) 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 *ArtifactMutation) ClearField(name string) error {
	switch name {
	case artifact.FieldMetadata:
		m.ClearMetadata()
		return nil
	}
	return fmt.Errorf("unknown Artifact 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 *ArtifactMutation) ResetField(name string) error {
	switch name {
	case artifact.FieldAstraID:
		m.ResetAstraID()
		return nil
	case artifact.FieldName:
		m.ResetName()
		return nil
	case artifact.FieldKind:
		m.ResetKind()
		return nil
	case artifact.FieldURI:
		m.ResetURI()
		return nil
	case artifact.FieldVersion:
		m.ResetVersion()
		return nil
	case artifact.FieldHash:
		m.ResetHash()
		return nil
	case artifact.FieldSize:
		m.ResetSize()
		return nil
	case artifact.FieldMetadata:
		m.ResetMetadata()
		return nil
	case artifact.FieldCompleteness:
		m.ResetCompleteness()
		return nil
	case artifact.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Artifact field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ArtifactMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *ArtifactMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Artifact 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 *ArtifactMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Artifact edge %s", name)
}

// EdgeMutation represents an operation that mutates the Edge nodes in the graph.
type EdgeMutation struct {
	config
	op            Op
	typ           string
	id            *int
	source        *string
	target        *string
	relation      *string
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Edge, error)
	predicates    []predicate.Edge
}

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

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

// newEdgeMutation creates new mutation for the Edge entity.
func newEdgeMutation(c config, op Op, opts ...edgeOption) *EdgeMutation {
	m := &EdgeMutation{
		config:        c,
		op:            op,
		typ:           TypeEdge,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withEdge sets the old Edge of the mutation.
func withEdge(node *Edge) edgeOption {
	return func(m *EdgeMutation) {
		m.oldValue = func(context.Context) (*Edge, 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 EdgeMutation) 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 EdgeMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

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

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

// SetSource sets the "source" field.
func (m *EdgeMutation) SetSource(s string) {
	m.source = &s
}

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

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

// ResetSource resets all changes to the "source" field.
func (m *EdgeMutation) ResetSource() {
	m.source = nil
}

// SetTarget sets the "target" field.
func (m *EdgeMutation) SetTarget(s string) {
	m.target = &s
}

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

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

// ResetTarget resets all changes to the "target" field.
func (m *EdgeMutation) ResetTarget() {
	m.target = nil
}

// SetRelation sets the "relation" field.
func (m *EdgeMutation) SetRelation(s string) {
	m.relation = &s
}

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

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

// ResetRelation resets all changes to the "relation" field.
func (m *EdgeMutation) ResetRelation() {
	m.relation = nil
}

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

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

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

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

// Type returns the node type of this mutation (Edge).
func (m *EdgeMutation) 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 *EdgeMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.source != nil {
		fields = append(fields, edge.FieldSource)
	}
	if m.target != nil {
		fields = append(fields, edge.FieldTarget)
	}
	if m.relation != nil {
		fields = append(fields, edge.FieldRelation)
	}
	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 *EdgeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case edge.FieldSource:
		return m.Source()
	case edge.FieldTarget:
		return m.Target()
	case edge.FieldRelation:
		return m.Relation()
	}
	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 *EdgeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case edge.FieldSource:
		return m.OldSource(ctx)
	case edge.FieldTarget:
		return m.OldTarget(ctx)
	case edge.FieldRelation:
		return m.OldRelation(ctx)
	}
	return nil, fmt.Errorf("unknown Edge 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 *EdgeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case edge.FieldSource:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSource(v)
		return nil
	case edge.FieldTarget:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTarget(v)
		return nil
	case edge.FieldRelation:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRelation(v)
		return nil
	}
	return fmt.Errorf("unknown Edge field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *EdgeMutation) 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 *EdgeMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Edge 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 *EdgeMutation) ResetField(name string) error {
	switch name {
	case edge.FieldSource:
		m.ResetSource()
		return nil
	case edge.FieldTarget:
		m.ResetTarget()
		return nil
	case edge.FieldRelation:
		m.ResetRelation()
		return nil
	}
	return fmt.Errorf("unknown Edge field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *EdgeMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *EdgeMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Edge 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 *EdgeMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Edge edge %s", name)
}

// PrincipalMutation represents an operation that mutates the Principal nodes in the graph.
type PrincipalMutation struct {
	config
	op            Op
	typ           string
	id            *int
	astra_id      *string
	name          *string
	trust         *string
	builder       *string
	metadata      *map[string]string
	completeness  *principal.Completeness
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Principal, error)
	predicates    []predicate.Principal
}

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

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

// newPrincipalMutation creates new mutation for the Principal entity.
func newPrincipalMutation(c config, op Op, opts ...principalOption) *PrincipalMutation {
	m := &PrincipalMutation{
		config:        c,
		op:            op,
		typ:           TypePrincipal,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withPrincipal sets the old Principal of the mutation.
func withPrincipal(node *Principal) principalOption {
	return func(m *PrincipalMutation) {
		m.oldValue = func(context.Context) (*Principal, 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 PrincipalMutation) 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 PrincipalMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

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

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

// SetAstraID sets the "astra_id" field.
func (m *PrincipalMutation) SetAstraID(s string) {
	m.astra_id = &s
}

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

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

// ResetAstraID resets all changes to the "astra_id" field.
func (m *PrincipalMutation) ResetAstraID() {
	m.astra_id = nil
}

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

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

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

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

// SetTrust sets the "trust" field.
func (m *PrincipalMutation) SetTrust(s string) {
	m.trust = &s
}

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

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

// ResetTrust resets all changes to the "trust" field.
func (m *PrincipalMutation) ResetTrust() {
	m.trust = nil
}

// SetBuilder sets the "builder" field.
func (m *PrincipalMutation) SetBuilder(s string) {
	m.builder = &s
}

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

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

// ResetBuilder resets all changes to the "builder" field.
func (m *PrincipalMutation) ResetBuilder() {
	m.builder = nil
}

// SetMetadata sets the "metadata" field.
func (m *PrincipalMutation) SetMetadata(value map[string]string) {
	m.metadata = &value
}

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

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

// ClearMetadata clears the value of the "metadata" field.
func (m *PrincipalMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[principal.FieldMetadata] = struct{}{}
}

// MetadataCleared returns if the "metadata" field was cleared in this mutation.
func (m *PrincipalMutation) MetadataCleared() bool {
	_, ok := m.clearedFields[principal.FieldMetadata]
	return ok
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *PrincipalMutation) ResetMetadata() {
	m.metadata = nil
	delete(m.clearedFields, principal.FieldMetadata)
}

// SetCompleteness sets the "completeness" field.
func (m *PrincipalMutation) SetCompleteness(pr principal.Completeness) {
	m.completeness = &pr
}

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

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

// ResetCompleteness resets all changes to the "completeness" field.
func (m *PrincipalMutation) ResetCompleteness() {
	m.completeness = nil
}

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

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PrincipalMutation) 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 Principal entity.
// If the Principal 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 *PrincipalMutation) 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 *PrincipalMutation) ResetCreatedAt() {
	m.created_at = nil
}

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

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

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

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

// Type returns the node type of this mutation (Principal).
func (m *PrincipalMutation) 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 *PrincipalMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.astra_id != nil {
		fields = append(fields, principal.FieldAstraID)
	}
	if m.name != nil {
		fields = append(fields, principal.FieldName)
	}
	if m.trust != nil {
		fields = append(fields, principal.FieldTrust)
	}
	if m.builder != nil {
		fields = append(fields, principal.FieldBuilder)
	}
	if m.metadata != nil {
		fields = append(fields, principal.FieldMetadata)
	}
	if m.completeness != nil {
		fields = append(fields, principal.FieldCompleteness)
	}
	if m.created_at != nil {
		fields = append(fields, principal.FieldCreatedAt)
	}
	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 *PrincipalMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case principal.FieldAstraID:
		return m.AstraID()
	case principal.FieldName:
		return m.Name()
	case principal.FieldTrust:
		return m.Trust()
	case principal.FieldBuilder:
		return m.Builder()
	case principal.FieldMetadata:
		return m.Metadata()
	case principal.FieldCompleteness:
		return m.Completeness()
	case principal.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *PrincipalMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case principal.FieldAstraID:
		return m.OldAstraID(ctx)
	case principal.FieldName:
		return m.OldName(ctx)
	case principal.FieldTrust:
		return m.OldTrust(ctx)
	case principal.FieldBuilder:
		return m.OldBuilder(ctx)
	case principal.FieldMetadata:
		return m.OldMetadata(ctx)
	case principal.FieldCompleteness:
		return m.OldCompleteness(ctx)
	case principal.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Principal 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 *PrincipalMutation) SetField(name string, value ent.Value) error {
	switch name {
	case principal.FieldAstraID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAstraID(v)
		return nil
	case principal.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case principal.FieldTrust:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTrust(v)
		return nil
	case principal.FieldBuilder:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBuilder(v)
		return nil
	case principal.FieldMetadata:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	case principal.FieldCompleteness:
		v, ok := value.(principal.Completeness)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompleteness(v)
		return nil
	case principal.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Principal field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PrincipalMutation) 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 *PrincipalMutation) ClearField(name string) error {
	switch name {
	case principal.FieldMetadata:
		m.ClearMetadata()
		return nil
	}
	return fmt.Errorf("unknown Principal 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 *PrincipalMutation) ResetField(name string) error {
	switch name {
	case principal.FieldAstraID:
		m.ResetAstraID()
		return nil
	case principal.FieldName:
		m.ResetName()
		return nil
	case principal.FieldTrust:
		m.ResetTrust()
		return nil
	case principal.FieldBuilder:
		m.ResetBuilder()
		return nil
	case principal.FieldMetadata:
		m.ResetMetadata()
		return nil
	case principal.FieldCompleteness:
		m.ResetCompleteness()
		return nil
	case principal.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Principal field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PrincipalMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PrincipalMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Principal 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 *PrincipalMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Principal edge %s", name)
}

// ResourceMutation represents an operation that mutates the Resource nodes in the graph.
type ResourceMutation struct {
	config
	op            Op
	typ           string
	id            *int
	astra_id      *string
	_type         *string
	uri           *string
	format        *string
	metadata      *map[string]string
	completeness  *resource.Completeness
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Resource, error)
	predicates    []predicate.Resource
}

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

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

// newResourceMutation creates new mutation for the Resource entity.
func newResourceMutation(c config, op Op, opts ...resourceOption) *ResourceMutation {
	m := &ResourceMutation{
		config:        c,
		op:            op,
		typ:           TypeResource,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withResource sets the old Resource of the mutation.
func withResource(node *Resource) resourceOption {
	return func(m *ResourceMutation) {
		m.oldValue = func(context.Context) (*Resource, 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 ResourceMutation) 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 ResourceMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

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

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

// SetAstraID sets the "astra_id" field.
func (m *ResourceMutation) SetAstraID(s string) {
	m.astra_id = &s
}

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

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

// ResetAstraID resets all changes to the "astra_id" field.
func (m *ResourceMutation) ResetAstraID() {
	m.astra_id = nil
}

// SetType sets the "type" field.
func (m *ResourceMutation) SetType(s string) {
	m._type = &s
}

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

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

// SetURI sets the "uri" field.
func (m *ResourceMutation) SetURI(s string) {
	m.uri = &s
}

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

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

// ResetURI resets all changes to the "uri" field.
func (m *ResourceMutation) ResetURI() {
	m.uri = nil
}

// SetFormat sets the "format" field.
func (m *ResourceMutation) SetFormat(s string) {
	m.format = &s
}

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

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

// ResetFormat resets all changes to the "format" field.
func (m *ResourceMutation) ResetFormat() {
	m.format = nil
}

// SetMetadata sets the "metadata" field.
func (m *ResourceMutation) SetMetadata(value map[string]string) {
	m.metadata = &value
}

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

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

// ClearMetadata clears the value of the "metadata" field.
func (m *ResourceMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[resource.FieldMetadata] = struct{}{}
}

// MetadataCleared returns if the "metadata" field was cleared in this mutation.
func (m *ResourceMutation) MetadataCleared() bool {
	_, ok := m.clearedFields[resource.FieldMetadata]
	return ok
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *ResourceMutation) ResetMetadata() {
	m.metadata = nil
	delete(m.clearedFields, resource.FieldMetadata)
}

// SetCompleteness sets the "completeness" field.
func (m *ResourceMutation) SetCompleteness(r resource.Completeness) {
	m.completeness = &r
}

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

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

// ResetCompleteness resets all changes to the "completeness" field.
func (m *ResourceMutation) ResetCompleteness() {
	m.completeness = nil
}

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

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ResourceMutation) 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 Resource entity.
// If the Resource 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 *ResourceMutation) 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 *ResourceMutation) ResetCreatedAt() {
	m.created_at = nil
}

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

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

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

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

// Type returns the node type of this mutation (Resource).
func (m *ResourceMutation) 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 *ResourceMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.astra_id != nil {
		fields = append(fields, resource.FieldAstraID)
	}
	if m._type != nil {
		fields = append(fields, resource.FieldType)
	}
	if m.uri != nil {
		fields = append(fields, resource.FieldURI)
	}
	if m.format != nil {
		fields = append(fields, resource.FieldFormat)
	}
	if m.metadata != nil {
		fields = append(fields, resource.FieldMetadata)
	}
	if m.completeness != nil {
		fields = append(fields, resource.FieldCompleteness)
	}
	if m.created_at != nil {
		fields = append(fields, resource.FieldCreatedAt)
	}
	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 *ResourceMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case resource.FieldAstraID:
		return m.AstraID()
	case resource.FieldType:
		return m.GetType()
	case resource.FieldURI:
		return m.URI()
	case resource.FieldFormat:
		return m.Format()
	case resource.FieldMetadata:
		return m.Metadata()
	case resource.FieldCompleteness:
		return m.Completeness()
	case resource.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *ResourceMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case resource.FieldAstraID:
		return m.OldAstraID(ctx)
	case resource.FieldType:
		return m.OldType(ctx)
	case resource.FieldURI:
		return m.OldURI(ctx)
	case resource.FieldFormat:
		return m.OldFormat(ctx)
	case resource.FieldMetadata:
		return m.OldMetadata(ctx)
	case resource.FieldCompleteness:
		return m.OldCompleteness(ctx)
	case resource.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Resource 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 *ResourceMutation) SetField(name string, value ent.Value) error {
	switch name {
	case resource.FieldAstraID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAstraID(v)
		return nil
	case resource.FieldType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case resource.FieldURI:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetURI(v)
		return nil
	case resource.FieldFormat:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFormat(v)
		return nil
	case resource.FieldMetadata:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	case resource.FieldCompleteness:
		v, ok := value.(resource.Completeness)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompleteness(v)
		return nil
	case resource.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Resource field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ResourceMutation) 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 *ResourceMutation) ClearField(name string) error {
	switch name {
	case resource.FieldMetadata:
		m.ClearMetadata()
		return nil
	}
	return fmt.Errorf("unknown Resource 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 *ResourceMutation) ResetField(name string) error {
	switch name {
	case resource.FieldAstraID:
		m.ResetAstraID()
		return nil
	case resource.FieldType:
		m.ResetType()
		return nil
	case resource.FieldURI:
		m.ResetURI()
		return nil
	case resource.FieldFormat:
		m.ResetFormat()
		return nil
	case resource.FieldMetadata:
		m.ResetMetadata()
		return nil
	case resource.FieldCompleteness:
		m.ResetCompleteness()
		return nil
	case resource.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Resource field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ResourceMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *ResourceMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Resource 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 *ResourceMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Resource edge %s", name)
}

// StepMutation represents an operation that mutates the Step nodes in the graph.
type StepMutation struct {
	config
	op            Op
	typ           string
	id            *int
	astra_id      *string
	command       *string
	environment   *map[string]string
	_Arch         *string
	timestamp     *string
	metadata      *map[string]string
	completeness  *step.Completeness
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Step, error)
	predicates    []predicate.Step
}

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

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

// newStepMutation creates new mutation for the Step entity.
func newStepMutation(c config, op Op, opts ...stepOption) *StepMutation {
	m := &StepMutation{
		config:        c,
		op:            op,
		typ:           TypeStep,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withStep sets the old Step of the mutation.
func withStep(node *Step) stepOption {
	return func(m *StepMutation) {
		m.oldValue = func(context.Context) (*Step, 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 StepMutation) 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 StepMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

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

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

// SetAstraID sets the "astra_id" field.
func (m *StepMutation) SetAstraID(s string) {
	m.astra_id = &s
}

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

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

// ResetAstraID resets all changes to the "astra_id" field.
func (m *StepMutation) ResetAstraID() {
	m.astra_id = nil
}

// SetCommand sets the "command" field.
func (m *StepMutation) SetCommand(s string) {
	m.command = &s
}

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

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

// ResetCommand resets all changes to the "command" field.
func (m *StepMutation) ResetCommand() {
	m.command = nil
}

// SetEnvironment sets the "environment" field.
func (m *StepMutation) SetEnvironment(value map[string]string) {
	m.environment = &value
}

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

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

// ResetEnvironment resets all changes to the "environment" field.
func (m *StepMutation) ResetEnvironment() {
	m.environment = nil
}

// SetArch sets the "Arch" field.
func (m *StepMutation) SetArch(s string) {
	m._Arch = &s
}

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

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

// ResetArch resets all changes to the "Arch" field.
func (m *StepMutation) ResetArch() {
	m._Arch = nil
}

// SetTimestamp sets the "timestamp" field.
func (m *StepMutation) SetTimestamp(s string) {
	m.timestamp = &s
}

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

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

// ResetTimestamp resets all changes to the "timestamp" field.
func (m *StepMutation) ResetTimestamp() {
	m.timestamp = nil
}

// SetMetadata sets the "metadata" field.
func (m *StepMutation) SetMetadata(value map[string]string) {
	m.metadata = &value
}

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

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

// ClearMetadata clears the value of the "metadata" field.
func (m *StepMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[step.FieldMetadata] = struct{}{}
}

// MetadataCleared returns if the "metadata" field was cleared in this mutation.
func (m *StepMutation) MetadataCleared() bool {
	_, ok := m.clearedFields[step.FieldMetadata]
	return ok
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *StepMutation) ResetMetadata() {
	m.metadata = nil
	delete(m.clearedFields, step.FieldMetadata)
}

// SetCompleteness sets the "completeness" field.
func (m *StepMutation) SetCompleteness(s step.Completeness) {
	m.completeness = &s
}

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

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

// ResetCompleteness resets all changes to the "completeness" field.
func (m *StepMutation) ResetCompleteness() {
	m.completeness = nil
}

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

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *StepMutation) 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 Step entity.
// If the Step 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 *StepMutation) 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 *StepMutation) ResetCreatedAt() {
	m.created_at = nil
}

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

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

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

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

// Type returns the node type of this mutation (Step).
func (m *StepMutation) 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 *StepMutation) Fields() []string {
	fields := make([]string, 0, 8)
	if m.astra_id != nil {
		fields = append(fields, step.FieldAstraID)
	}
	if m.command != nil {
		fields = append(fields, step.FieldCommand)
	}
	if m.environment != nil {
		fields = append(fields, step.FieldEnvironment)
	}
	if m._Arch != nil {
		fields = append(fields, step.FieldArch)
	}
	if m.timestamp != nil {
		fields = append(fields, step.FieldTimestamp)
	}
	if m.metadata != nil {
		fields = append(fields, step.FieldMetadata)
	}
	if m.completeness != nil {
		fields = append(fields, step.FieldCompleteness)
	}
	if m.created_at != nil {
		fields = append(fields, step.FieldCreatedAt)
	}
	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 *StepMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case step.FieldAstraID:
		return m.AstraID()
	case step.FieldCommand:
		return m.Command()
	case step.FieldEnvironment:
		return m.Environment()
	case step.FieldArch:
		return m.Arch()
	case step.FieldTimestamp:
		return m.Timestamp()
	case step.FieldMetadata:
		return m.Metadata()
	case step.FieldCompleteness:
		return m.Completeness()
	case step.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *StepMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case step.FieldAstraID:
		return m.OldAstraID(ctx)
	case step.FieldCommand:
		return m.OldCommand(ctx)
	case step.FieldEnvironment:
		return m.OldEnvironment(ctx)
	case step.FieldArch:
		return m.OldArch(ctx)
	case step.FieldTimestamp:
		return m.OldTimestamp(ctx)
	case step.FieldMetadata:
		return m.OldMetadata(ctx)
	case step.FieldCompleteness:
		return m.OldCompleteness(ctx)
	case step.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Step 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 *StepMutation) SetField(name string, value ent.Value) error {
	switch name {
	case step.FieldAstraID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAstraID(v)
		return nil
	case step.FieldCommand:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCommand(v)
		return nil
	case step.FieldEnvironment:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEnvironment(v)
		return nil
	case step.FieldArch:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetArch(v)
		return nil
	case step.FieldTimestamp:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTimestamp(v)
		return nil
	case step.FieldMetadata:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	case step.FieldCompleteness:
		v, ok := value.(step.Completeness)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompleteness(v)
		return nil
	case step.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Step field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *StepMutation) 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 *StepMutation) ClearField(name string) error {
	switch name {
	case step.FieldMetadata:
		m.ClearMetadata()
		return nil
	}
	return fmt.Errorf("unknown Step 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 *StepMutation) ResetField(name string) error {
	switch name {
	case step.FieldAstraID:
		m.ResetAstraID()
		return nil
	case step.FieldCommand:
		m.ResetCommand()
		return nil
	case step.FieldEnvironment:
		m.ResetEnvironment()
		return nil
	case step.FieldArch:
		m.ResetArch()
		return nil
	case step.FieldTimestamp:
		m.ResetTimestamp()
		return nil
	case step.FieldMetadata:
		m.ResetMetadata()
		return nil
	case step.FieldCompleteness:
		m.ResetCompleteness()
		return nil
	case step.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Step field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *StepMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *StepMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Step 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 *StepMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Step edge %s", name)
}
