// 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/chainloop-dev/chainloop/app/controlplane/pkg/authz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/apitoken"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/attestation"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casbackend"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casmapping"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/group"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/groupmembership"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/integration"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/integrationattachment"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/membership"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/orginvitation"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/project"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/projectversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/referrer"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/robotaccount"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/user"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflow"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontract"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontractversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowrun"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/unmarshal"
	"github.com/google/uuid"
	"github.com/secure-systems-lab/go-securesystemslib/dsse"
)

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

	// Node types.
	TypeAPIToken                = "APIToken"
	TypeAttestation             = "Attestation"
	TypeCASBackend              = "CASBackend"
	TypeCASMapping              = "CASMapping"
	TypeGroup                   = "Group"
	TypeGroupMembership         = "GroupMembership"
	TypeIntegration             = "Integration"
	TypeIntegrationAttachment   = "IntegrationAttachment"
	TypeMembership              = "Membership"
	TypeOrgInvitation           = "OrgInvitation"
	TypeOrganization            = "Organization"
	TypeProject                 = "Project"
	TypeProjectVersion          = "ProjectVersion"
	TypeReferrer                = "Referrer"
	TypeRobotAccount            = "RobotAccount"
	TypeUser                    = "User"
	TypeWorkflow                = "Workflow"
	TypeWorkflowContract        = "WorkflowContract"
	TypeWorkflowContractVersion = "WorkflowContractVersion"
	TypeWorkflowRun             = "WorkflowRun"
)

// APITokenMutation represents an operation that mutates the APIToken nodes in the graph.
type APITokenMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	name                *string
	description         *string
	created_at          *time.Time
	expires_at          *time.Time
	revoked_at          *time.Time
	last_used_at        *time.Time
	clearedFields       map[string]struct{}
	organization        *uuid.UUID
	clearedorganization bool
	project             *uuid.UUID
	clearedproject      bool
	done                bool
	oldValue            func(context.Context) (*APIToken, error)
	predicates          []predicate.APIToken
}

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

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

// newAPITokenMutation creates new mutation for the APIToken entity.
func newAPITokenMutation(c config, op Op, opts ...apitokenOption) *APITokenMutation {
	m := &APITokenMutation{
		config:        c,
		op:            op,
		typ:           TypeAPIToken,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *APITokenMutation) 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 APIToken entity.
// If the APIToken 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 *APITokenMutation) 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 *APITokenMutation) ResetName() {
	m.name = nil
}

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

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

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

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

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

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

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

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

// SetExpiresAt sets the "expires_at" field.
func (m *APITokenMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

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

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

// ClearExpiresAt clears the value of the "expires_at" field.
func (m *APITokenMutation) ClearExpiresAt() {
	m.expires_at = nil
	m.clearedFields[apitoken.FieldExpiresAt] = struct{}{}
}

// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *APITokenMutation) ExpiresAtCleared() bool {
	_, ok := m.clearedFields[apitoken.FieldExpiresAt]
	return ok
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *APITokenMutation) ResetExpiresAt() {
	m.expires_at = nil
	delete(m.clearedFields, apitoken.FieldExpiresAt)
}

// SetRevokedAt sets the "revoked_at" field.
func (m *APITokenMutation) SetRevokedAt(t time.Time) {
	m.revoked_at = &t
}

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

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

// ClearRevokedAt clears the value of the "revoked_at" field.
func (m *APITokenMutation) ClearRevokedAt() {
	m.revoked_at = nil
	m.clearedFields[apitoken.FieldRevokedAt] = struct{}{}
}

// RevokedAtCleared returns if the "revoked_at" field was cleared in this mutation.
func (m *APITokenMutation) RevokedAtCleared() bool {
	_, ok := m.clearedFields[apitoken.FieldRevokedAt]
	return ok
}

// ResetRevokedAt resets all changes to the "revoked_at" field.
func (m *APITokenMutation) ResetRevokedAt() {
	m.revoked_at = nil
	delete(m.clearedFields, apitoken.FieldRevokedAt)
}

// SetLastUsedAt sets the "last_used_at" field.
func (m *APITokenMutation) SetLastUsedAt(t time.Time) {
	m.last_used_at = &t
}

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

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

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (m *APITokenMutation) ClearLastUsedAt() {
	m.last_used_at = nil
	m.clearedFields[apitoken.FieldLastUsedAt] = struct{}{}
}

// LastUsedAtCleared returns if the "last_used_at" field was cleared in this mutation.
func (m *APITokenMutation) LastUsedAtCleared() bool {
	_, ok := m.clearedFields[apitoken.FieldLastUsedAt]
	return ok
}

// ResetLastUsedAt resets all changes to the "last_used_at" field.
func (m *APITokenMutation) ResetLastUsedAt() {
	m.last_used_at = nil
	delete(m.clearedFields, apitoken.FieldLastUsedAt)
}

// SetOrganizationID sets the "organization_id" field.
func (m *APITokenMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *APITokenMutation) ResetOrganizationID() {
	m.organization = nil
}

// SetProjectID sets the "project_id" field.
func (m *APITokenMutation) SetProjectID(u uuid.UUID) {
	m.project = &u
}

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

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

// ClearProjectID clears the value of the "project_id" field.
func (m *APITokenMutation) ClearProjectID() {
	m.project = nil
	m.clearedFields[apitoken.FieldProjectID] = struct{}{}
}

// ProjectIDCleared returns if the "project_id" field was cleared in this mutation.
func (m *APITokenMutation) ProjectIDCleared() bool {
	_, ok := m.clearedFields[apitoken.FieldProjectID]
	return ok
}

// ResetProjectID resets all changes to the "project_id" field.
func (m *APITokenMutation) ResetProjectID() {
	m.project = nil
	delete(m.clearedFields, apitoken.FieldProjectID)
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *APITokenMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[apitoken.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *APITokenMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *APITokenMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// ClearProject clears the "project" edge to the Project entity.
func (m *APITokenMutation) ClearProject() {
	m.clearedproject = true
	m.clearedFields[apitoken.FieldProjectID] = struct{}{}
}

// ProjectCleared reports if the "project" edge to the Project entity was cleared.
func (m *APITokenMutation) ProjectCleared() bool {
	return m.ProjectIDCleared() || m.clearedproject
}

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

// ResetProject resets all changes to the "project" edge.
func (m *APITokenMutation) ResetProject() {
	m.project = nil
	m.clearedproject = false
}

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

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

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

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

// Type returns the node type of this mutation (APIToken).
func (m *APITokenMutation) 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 *APITokenMutation) Fields() []string {
	fields := make([]string, 0, 8)
	if m.name != nil {
		fields = append(fields, apitoken.FieldName)
	}
	if m.description != nil {
		fields = append(fields, apitoken.FieldDescription)
	}
	if m.created_at != nil {
		fields = append(fields, apitoken.FieldCreatedAt)
	}
	if m.expires_at != nil {
		fields = append(fields, apitoken.FieldExpiresAt)
	}
	if m.revoked_at != nil {
		fields = append(fields, apitoken.FieldRevokedAt)
	}
	if m.last_used_at != nil {
		fields = append(fields, apitoken.FieldLastUsedAt)
	}
	if m.organization != nil {
		fields = append(fields, apitoken.FieldOrganizationID)
	}
	if m.project != nil {
		fields = append(fields, apitoken.FieldProjectID)
	}
	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 *APITokenMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case apitoken.FieldName:
		return m.Name()
	case apitoken.FieldDescription:
		return m.Description()
	case apitoken.FieldCreatedAt:
		return m.CreatedAt()
	case apitoken.FieldExpiresAt:
		return m.ExpiresAt()
	case apitoken.FieldRevokedAt:
		return m.RevokedAt()
	case apitoken.FieldLastUsedAt:
		return m.LastUsedAt()
	case apitoken.FieldOrganizationID:
		return m.OrganizationID()
	case apitoken.FieldProjectID:
		return m.ProjectID()
	}
	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 *APITokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case apitoken.FieldName:
		return m.OldName(ctx)
	case apitoken.FieldDescription:
		return m.OldDescription(ctx)
	case apitoken.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case apitoken.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case apitoken.FieldRevokedAt:
		return m.OldRevokedAt(ctx)
	case apitoken.FieldLastUsedAt:
		return m.OldLastUsedAt(ctx)
	case apitoken.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	case apitoken.FieldProjectID:
		return m.OldProjectID(ctx)
	}
	return nil, fmt.Errorf("unknown APIToken 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 *APITokenMutation) SetField(name string, value ent.Value) error {
	switch name {
	case apitoken.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case apitoken.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case apitoken.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case apitoken.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case apitoken.FieldRevokedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRevokedAt(v)
		return nil
	case apitoken.FieldLastUsedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastUsedAt(v)
		return nil
	case apitoken.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	case apitoken.FieldProjectID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProjectID(v)
		return nil
	}
	return fmt.Errorf("unknown APIToken field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *APITokenMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(apitoken.FieldDescription) {
		fields = append(fields, apitoken.FieldDescription)
	}
	if m.FieldCleared(apitoken.FieldExpiresAt) {
		fields = append(fields, apitoken.FieldExpiresAt)
	}
	if m.FieldCleared(apitoken.FieldRevokedAt) {
		fields = append(fields, apitoken.FieldRevokedAt)
	}
	if m.FieldCleared(apitoken.FieldLastUsedAt) {
		fields = append(fields, apitoken.FieldLastUsedAt)
	}
	if m.FieldCleared(apitoken.FieldProjectID) {
		fields = append(fields, apitoken.FieldProjectID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *APITokenMutation) 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 *APITokenMutation) ClearField(name string) error {
	switch name {
	case apitoken.FieldDescription:
		m.ClearDescription()
		return nil
	case apitoken.FieldExpiresAt:
		m.ClearExpiresAt()
		return nil
	case apitoken.FieldRevokedAt:
		m.ClearRevokedAt()
		return nil
	case apitoken.FieldLastUsedAt:
		m.ClearLastUsedAt()
		return nil
	case apitoken.FieldProjectID:
		m.ClearProjectID()
		return nil
	}
	return fmt.Errorf("unknown APIToken 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 *APITokenMutation) ResetField(name string) error {
	switch name {
	case apitoken.FieldName:
		m.ResetName()
		return nil
	case apitoken.FieldDescription:
		m.ResetDescription()
		return nil
	case apitoken.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case apitoken.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case apitoken.FieldRevokedAt:
		m.ResetRevokedAt()
		return nil
	case apitoken.FieldLastUsedAt:
		m.ResetLastUsedAt()
		return nil
	case apitoken.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	case apitoken.FieldProjectID:
		m.ResetProjectID()
		return nil
	}
	return fmt.Errorf("unknown APIToken field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *APITokenMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.organization != nil {
		edges = append(edges, apitoken.EdgeOrganization)
	}
	if m.project != nil {
		edges = append(edges, apitoken.EdgeProject)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *APITokenMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedorganization {
		edges = append(edges, apitoken.EdgeOrganization)
	}
	if m.clearedproject {
		edges = append(edges, apitoken.EdgeProject)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *APITokenMutation) EdgeCleared(name string) bool {
	switch name {
	case apitoken.EdgeOrganization:
		return m.clearedorganization
	case apitoken.EdgeProject:
		return m.clearedproject
	}
	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 *APITokenMutation) ClearEdge(name string) error {
	switch name {
	case apitoken.EdgeOrganization:
		m.ClearOrganization()
		return nil
	case apitoken.EdgeProject:
		m.ClearProject()
		return nil
	}
	return fmt.Errorf("unknown APIToken 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 *APITokenMutation) ResetEdge(name string) error {
	switch name {
	case apitoken.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case apitoken.EdgeProject:
		m.ResetProject()
		return nil
	}
	return fmt.Errorf("unknown APIToken edge %s", name)
}

// AttestationMutation represents an operation that mutates the Attestation nodes in the graph.
type AttestationMutation struct {
	config
	op                 Op
	typ                string
	id                 *uuid.UUID
	created_at         *time.Time
	bundle             *[]byte
	clearedFields      map[string]struct{}
	workflowrun        *uuid.UUID
	clearedworkflowrun bool
	done               bool
	oldValue           func(context.Context) (*Attestation, error)
	predicates         []predicate.Attestation
}

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

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

// newAttestationMutation creates new mutation for the Attestation entity.
func newAttestationMutation(c config, op Op, opts ...attestationOption) *AttestationMutation {
	m := &AttestationMutation{
		config:        c,
		op:            op,
		typ:           TypeAttestation,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

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

// SetBundle sets the "bundle" field.
func (m *AttestationMutation) SetBundle(b []byte) {
	m.bundle = &b
}

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

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

// ResetBundle resets all changes to the "bundle" field.
func (m *AttestationMutation) ResetBundle() {
	m.bundle = nil
}

// SetWorkflowrunID sets the "workflowrun_id" field.
func (m *AttestationMutation) SetWorkflowrunID(u uuid.UUID) {
	m.workflowrun = &u
}

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

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

// ResetWorkflowrunID resets all changes to the "workflowrun_id" field.
func (m *AttestationMutation) ResetWorkflowrunID() {
	m.workflowrun = nil
}

// ClearWorkflowrun clears the "workflowrun" edge to the WorkflowRun entity.
func (m *AttestationMutation) ClearWorkflowrun() {
	m.clearedworkflowrun = true
	m.clearedFields[attestation.FieldWorkflowrunID] = struct{}{}
}

// WorkflowrunCleared reports if the "workflowrun" edge to the WorkflowRun entity was cleared.
func (m *AttestationMutation) WorkflowrunCleared() bool {
	return m.clearedworkflowrun
}

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

// ResetWorkflowrun resets all changes to the "workflowrun" edge.
func (m *AttestationMutation) ResetWorkflowrun() {
	m.workflowrun = nil
	m.clearedworkflowrun = false
}

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

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

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

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

// Type returns the node type of this mutation (Attestation).
func (m *AttestationMutation) 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 *AttestationMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.created_at != nil {
		fields = append(fields, attestation.FieldCreatedAt)
	}
	if m.bundle != nil {
		fields = append(fields, attestation.FieldBundle)
	}
	if m.workflowrun != nil {
		fields = append(fields, attestation.FieldWorkflowrunID)
	}
	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 *AttestationMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case attestation.FieldCreatedAt:
		return m.CreatedAt()
	case attestation.FieldBundle:
		return m.Bundle()
	case attestation.FieldWorkflowrunID:
		return m.WorkflowrunID()
	}
	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 *AttestationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case attestation.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case attestation.FieldBundle:
		return m.OldBundle(ctx)
	case attestation.FieldWorkflowrunID:
		return m.OldWorkflowrunID(ctx)
	}
	return nil, fmt.Errorf("unknown Attestation 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 *AttestationMutation) SetField(name string, value ent.Value) error {
	switch name {
	case attestation.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case attestation.FieldBundle:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBundle(v)
		return nil
	case attestation.FieldWorkflowrunID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWorkflowrunID(v)
		return nil
	}
	return fmt.Errorf("unknown Attestation field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AttestationMutation) 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 *AttestationMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Attestation 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 *AttestationMutation) ResetField(name string) error {
	switch name {
	case attestation.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case attestation.FieldBundle:
		m.ResetBundle()
		return nil
	case attestation.FieldWorkflowrunID:
		m.ResetWorkflowrunID()
		return nil
	}
	return fmt.Errorf("unknown Attestation field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AttestationMutation) EdgeCleared(name string) bool {
	switch name {
	case attestation.EdgeWorkflowrun:
		return m.clearedworkflowrun
	}
	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 *AttestationMutation) ClearEdge(name string) error {
	switch name {
	case attestation.EdgeWorkflowrun:
		m.ClearWorkflowrun()
		return nil
	}
	return fmt.Errorf("unknown Attestation 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 *AttestationMutation) ResetEdge(name string) error {
	switch name {
	case attestation.EdgeWorkflowrun:
		m.ResetWorkflowrun()
		return nil
	}
	return fmt.Errorf("unknown Attestation edge %s", name)
}

// CASBackendMutation represents an operation that mutates the CASBackend nodes in the graph.
type CASBackendMutation struct {
	config
	op                     Op
	typ                    string
	id                     *uuid.UUID
	location               *string
	name                   *string
	provider               *biz.CASBackendProvider
	description            *string
	secret_name            *string
	created_at             *time.Time
	validation_status      *biz.CASBackendValidationStatus
	validation_error       *string
	validated_at           *time.Time
	_default               *bool
	deleted_at             *time.Time
	fallback               *bool
	max_blob_size_bytes    *int64
	addmax_blob_size_bytes *int64
	clearedFields          map[string]struct{}
	organization           *uuid.UUID
	clearedorganization    bool
	workflow_run           map[uuid.UUID]struct{}
	removedworkflow_run    map[uuid.UUID]struct{}
	clearedworkflow_run    bool
	done                   bool
	oldValue               func(context.Context) (*CASBackend, error)
	predicates             []predicate.CASBackend
}

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

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

// newCASBackendMutation creates new mutation for the CASBackend entity.
func newCASBackendMutation(c config, op Op, opts ...casbackendOption) *CASBackendMutation {
	m := &CASBackendMutation{
		config:        c,
		op:            op,
		typ:           TypeCASBackend,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetLocation sets the "location" field.
func (m *CASBackendMutation) SetLocation(s string) {
	m.location = &s
}

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

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

// ResetLocation resets all changes to the "location" field.
func (m *CASBackendMutation) ResetLocation() {
	m.location = nil
}

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

// Name returns the value of the "name" field in the mutation.
func (m *CASBackendMutation) 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 CASBackend entity.
// If the CASBackend 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 *CASBackendMutation) 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 *CASBackendMutation) ResetName() {
	m.name = nil
}

// SetProvider sets the "provider" field.
func (m *CASBackendMutation) SetProvider(bbp biz.CASBackendProvider) {
	m.provider = &bbp
}

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

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

// ResetProvider resets all changes to the "provider" field.
func (m *CASBackendMutation) ResetProvider() {
	m.provider = nil
}

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

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

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

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

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

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

// SetSecretName sets the "secret_name" field.
func (m *CASBackendMutation) SetSecretName(s string) {
	m.secret_name = &s
}

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

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

// ResetSecretName resets all changes to the "secret_name" field.
func (m *CASBackendMutation) ResetSecretName() {
	m.secret_name = nil
}

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

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

// SetValidationStatus sets the "validation_status" field.
func (m *CASBackendMutation) SetValidationStatus(bbvs biz.CASBackendValidationStatus) {
	m.validation_status = &bbvs
}

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

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

// ResetValidationStatus resets all changes to the "validation_status" field.
func (m *CASBackendMutation) ResetValidationStatus() {
	m.validation_status = nil
}

// SetValidationError sets the "validation_error" field.
func (m *CASBackendMutation) SetValidationError(s string) {
	m.validation_error = &s
}

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

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

// ClearValidationError clears the value of the "validation_error" field.
func (m *CASBackendMutation) ClearValidationError() {
	m.validation_error = nil
	m.clearedFields[casbackend.FieldValidationError] = struct{}{}
}

// ValidationErrorCleared returns if the "validation_error" field was cleared in this mutation.
func (m *CASBackendMutation) ValidationErrorCleared() bool {
	_, ok := m.clearedFields[casbackend.FieldValidationError]
	return ok
}

// ResetValidationError resets all changes to the "validation_error" field.
func (m *CASBackendMutation) ResetValidationError() {
	m.validation_error = nil
	delete(m.clearedFields, casbackend.FieldValidationError)
}

// SetValidatedAt sets the "validated_at" field.
func (m *CASBackendMutation) SetValidatedAt(t time.Time) {
	m.validated_at = &t
}

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

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

// ResetValidatedAt resets all changes to the "validated_at" field.
func (m *CASBackendMutation) ResetValidatedAt() {
	m.validated_at = nil
}

// SetDefault sets the "default" field.
func (m *CASBackendMutation) SetDefault(b bool) {
	m._default = &b
}

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

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

// ResetDefault resets all changes to the "default" field.
func (m *CASBackendMutation) ResetDefault() {
	m._default = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *CASBackendMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *CASBackendMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[casbackend.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *CASBackendMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[casbackend.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *CASBackendMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, casbackend.FieldDeletedAt)
}

// SetFallback sets the "fallback" field.
func (m *CASBackendMutation) SetFallback(b bool) {
	m.fallback = &b
}

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

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

// ResetFallback resets all changes to the "fallback" field.
func (m *CASBackendMutation) ResetFallback() {
	m.fallback = nil
}

// SetMaxBlobSizeBytes sets the "max_blob_size_bytes" field.
func (m *CASBackendMutation) SetMaxBlobSizeBytes(i int64) {
	m.max_blob_size_bytes = &i
	m.addmax_blob_size_bytes = nil
}

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

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

// AddMaxBlobSizeBytes adds i to the "max_blob_size_bytes" field.
func (m *CASBackendMutation) AddMaxBlobSizeBytes(i int64) {
	if m.addmax_blob_size_bytes != nil {
		*m.addmax_blob_size_bytes += i
	} else {
		m.addmax_blob_size_bytes = &i
	}
}

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

// ResetMaxBlobSizeBytes resets all changes to the "max_blob_size_bytes" field.
func (m *CASBackendMutation) ResetMaxBlobSizeBytes() {
	m.max_blob_size_bytes = nil
	m.addmax_blob_size_bytes = nil
}

// SetOrganizationID sets the "organization" edge to the Organization entity by id.
func (m *CASBackendMutation) SetOrganizationID(id uuid.UUID) {
	m.organization = &id
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *CASBackendMutation) ClearOrganization() {
	m.clearedorganization = true
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *CASBackendMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

// OrganizationID returns the "organization" edge ID in the mutation.
func (m *CASBackendMutation) OrganizationID() (id uuid.UUID, exists bool) {
	if m.organization != nil {
		return *m.organization, true
	}
	return
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *CASBackendMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// AddWorkflowRunIDs adds the "workflow_run" edge to the WorkflowRun entity by ids.
func (m *CASBackendMutation) AddWorkflowRunIDs(ids ...uuid.UUID) {
	if m.workflow_run == nil {
		m.workflow_run = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflow_run[ids[i]] = struct{}{}
	}
}

// ClearWorkflowRun clears the "workflow_run" edge to the WorkflowRun entity.
func (m *CASBackendMutation) ClearWorkflowRun() {
	m.clearedworkflow_run = true
}

// WorkflowRunCleared reports if the "workflow_run" edge to the WorkflowRun entity was cleared.
func (m *CASBackendMutation) WorkflowRunCleared() bool {
	return m.clearedworkflow_run
}

// RemoveWorkflowRunIDs removes the "workflow_run" edge to the WorkflowRun entity by IDs.
func (m *CASBackendMutation) RemoveWorkflowRunIDs(ids ...uuid.UUID) {
	if m.removedworkflow_run == nil {
		m.removedworkflow_run = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflow_run, ids[i])
		m.removedworkflow_run[ids[i]] = struct{}{}
	}
}

// RemovedWorkflowRun returns the removed IDs of the "workflow_run" edge to the WorkflowRun entity.
func (m *CASBackendMutation) RemovedWorkflowRunIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflow_run {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflowRun resets all changes to the "workflow_run" edge.
func (m *CASBackendMutation) ResetWorkflowRun() {
	m.workflow_run = nil
	m.clearedworkflow_run = false
	m.removedworkflow_run = nil
}

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

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

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

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

// Type returns the node type of this mutation (CASBackend).
func (m *CASBackendMutation) 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 *CASBackendMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.location != nil {
		fields = append(fields, casbackend.FieldLocation)
	}
	if m.name != nil {
		fields = append(fields, casbackend.FieldName)
	}
	if m.provider != nil {
		fields = append(fields, casbackend.FieldProvider)
	}
	if m.description != nil {
		fields = append(fields, casbackend.FieldDescription)
	}
	if m.secret_name != nil {
		fields = append(fields, casbackend.FieldSecretName)
	}
	if m.created_at != nil {
		fields = append(fields, casbackend.FieldCreatedAt)
	}
	if m.validation_status != nil {
		fields = append(fields, casbackend.FieldValidationStatus)
	}
	if m.validation_error != nil {
		fields = append(fields, casbackend.FieldValidationError)
	}
	if m.validated_at != nil {
		fields = append(fields, casbackend.FieldValidatedAt)
	}
	if m._default != nil {
		fields = append(fields, casbackend.FieldDefault)
	}
	if m.deleted_at != nil {
		fields = append(fields, casbackend.FieldDeletedAt)
	}
	if m.fallback != nil {
		fields = append(fields, casbackend.FieldFallback)
	}
	if m.max_blob_size_bytes != nil {
		fields = append(fields, casbackend.FieldMaxBlobSizeBytes)
	}
	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 *CASBackendMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case casbackend.FieldLocation:
		return m.Location()
	case casbackend.FieldName:
		return m.Name()
	case casbackend.FieldProvider:
		return m.Provider()
	case casbackend.FieldDescription:
		return m.Description()
	case casbackend.FieldSecretName:
		return m.SecretName()
	case casbackend.FieldCreatedAt:
		return m.CreatedAt()
	case casbackend.FieldValidationStatus:
		return m.ValidationStatus()
	case casbackend.FieldValidationError:
		return m.ValidationError()
	case casbackend.FieldValidatedAt:
		return m.ValidatedAt()
	case casbackend.FieldDefault:
		return m.Default()
	case casbackend.FieldDeletedAt:
		return m.DeletedAt()
	case casbackend.FieldFallback:
		return m.Fallback()
	case casbackend.FieldMaxBlobSizeBytes:
		return m.MaxBlobSizeBytes()
	}
	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 *CASBackendMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case casbackend.FieldLocation:
		return m.OldLocation(ctx)
	case casbackend.FieldName:
		return m.OldName(ctx)
	case casbackend.FieldProvider:
		return m.OldProvider(ctx)
	case casbackend.FieldDescription:
		return m.OldDescription(ctx)
	case casbackend.FieldSecretName:
		return m.OldSecretName(ctx)
	case casbackend.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case casbackend.FieldValidationStatus:
		return m.OldValidationStatus(ctx)
	case casbackend.FieldValidationError:
		return m.OldValidationError(ctx)
	case casbackend.FieldValidatedAt:
		return m.OldValidatedAt(ctx)
	case casbackend.FieldDefault:
		return m.OldDefault(ctx)
	case casbackend.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case casbackend.FieldFallback:
		return m.OldFallback(ctx)
	case casbackend.FieldMaxBlobSizeBytes:
		return m.OldMaxBlobSizeBytes(ctx)
	}
	return nil, fmt.Errorf("unknown CASBackend 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 *CASBackendMutation) SetField(name string, value ent.Value) error {
	switch name {
	case casbackend.FieldLocation:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLocation(v)
		return nil
	case casbackend.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case casbackend.FieldProvider:
		v, ok := value.(biz.CASBackendProvider)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProvider(v)
		return nil
	case casbackend.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case casbackend.FieldSecretName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSecretName(v)
		return nil
	case casbackend.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case casbackend.FieldValidationStatus:
		v, ok := value.(biz.CASBackendValidationStatus)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidationStatus(v)
		return nil
	case casbackend.FieldValidationError:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidationError(v)
		return nil
	case casbackend.FieldValidatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidatedAt(v)
		return nil
	case casbackend.FieldDefault:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDefault(v)
		return nil
	case casbackend.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case casbackend.FieldFallback:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFallback(v)
		return nil
	case casbackend.FieldMaxBlobSizeBytes:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMaxBlobSizeBytes(v)
		return nil
	}
	return fmt.Errorf("unknown CASBackend field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CASBackendMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(casbackend.FieldDescription) {
		fields = append(fields, casbackend.FieldDescription)
	}
	if m.FieldCleared(casbackend.FieldValidationError) {
		fields = append(fields, casbackend.FieldValidationError)
	}
	if m.FieldCleared(casbackend.FieldDeletedAt) {
		fields = append(fields, casbackend.FieldDeletedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CASBackendMutation) 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 *CASBackendMutation) ClearField(name string) error {
	switch name {
	case casbackend.FieldDescription:
		m.ClearDescription()
		return nil
	case casbackend.FieldValidationError:
		m.ClearValidationError()
		return nil
	case casbackend.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown CASBackend 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 *CASBackendMutation) ResetField(name string) error {
	switch name {
	case casbackend.FieldLocation:
		m.ResetLocation()
		return nil
	case casbackend.FieldName:
		m.ResetName()
		return nil
	case casbackend.FieldProvider:
		m.ResetProvider()
		return nil
	case casbackend.FieldDescription:
		m.ResetDescription()
		return nil
	case casbackend.FieldSecretName:
		m.ResetSecretName()
		return nil
	case casbackend.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case casbackend.FieldValidationStatus:
		m.ResetValidationStatus()
		return nil
	case casbackend.FieldValidationError:
		m.ResetValidationError()
		return nil
	case casbackend.FieldValidatedAt:
		m.ResetValidatedAt()
		return nil
	case casbackend.FieldDefault:
		m.ResetDefault()
		return nil
	case casbackend.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case casbackend.FieldFallback:
		m.ResetFallback()
		return nil
	case casbackend.FieldMaxBlobSizeBytes:
		m.ResetMaxBlobSizeBytes()
		return nil
	}
	return fmt.Errorf("unknown CASBackend field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CASBackendMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.organization != nil {
		edges = append(edges, casbackend.EdgeOrganization)
	}
	if m.workflow_run != nil {
		edges = append(edges, casbackend.EdgeWorkflowRun)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CASBackendMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedorganization {
		edges = append(edges, casbackend.EdgeOrganization)
	}
	if m.clearedworkflow_run {
		edges = append(edges, casbackend.EdgeWorkflowRun)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CASBackendMutation) EdgeCleared(name string) bool {
	switch name {
	case casbackend.EdgeOrganization:
		return m.clearedorganization
	case casbackend.EdgeWorkflowRun:
		return m.clearedworkflow_run
	}
	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 *CASBackendMutation) ClearEdge(name string) error {
	switch name {
	case casbackend.EdgeOrganization:
		m.ClearOrganization()
		return nil
	}
	return fmt.Errorf("unknown CASBackend 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 *CASBackendMutation) ResetEdge(name string) error {
	switch name {
	case casbackend.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case casbackend.EdgeWorkflowRun:
		m.ResetWorkflowRun()
		return nil
	}
	return fmt.Errorf("unknown CASBackend edge %s", name)
}

// CASMappingMutation represents an operation that mutates the CASMapping nodes in the graph.
type CASMappingMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	digest              *string
	created_at          *time.Time
	workflow_run_id     *uuid.UUID
	clearedFields       map[string]struct{}
	cas_backend         *uuid.UUID
	clearedcas_backend  bool
	organization        *uuid.UUID
	clearedorganization bool
	project             *uuid.UUID
	clearedproject      bool
	done                bool
	oldValue            func(context.Context) (*CASMapping, error)
	predicates          []predicate.CASMapping
}

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

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

// newCASMappingMutation creates new mutation for the CASMapping entity.
func newCASMappingMutation(c config, op Op, opts ...casmappingOption) *CASMappingMutation {
	m := &CASMappingMutation{
		config:        c,
		op:            op,
		typ:           TypeCASMapping,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetDigest sets the "digest" field.
func (m *CASMappingMutation) SetDigest(s string) {
	m.digest = &s
}

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

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

// ResetDigest resets all changes to the "digest" field.
func (m *CASMappingMutation) ResetDigest() {
	m.digest = nil
}

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

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

// SetWorkflowRunID sets the "workflow_run_id" field.
func (m *CASMappingMutation) SetWorkflowRunID(u uuid.UUID) {
	m.workflow_run_id = &u
}

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

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

// ClearWorkflowRunID clears the value of the "workflow_run_id" field.
func (m *CASMappingMutation) ClearWorkflowRunID() {
	m.workflow_run_id = nil
	m.clearedFields[casmapping.FieldWorkflowRunID] = struct{}{}
}

// WorkflowRunIDCleared returns if the "workflow_run_id" field was cleared in this mutation.
func (m *CASMappingMutation) WorkflowRunIDCleared() bool {
	_, ok := m.clearedFields[casmapping.FieldWorkflowRunID]
	return ok
}

// ResetWorkflowRunID resets all changes to the "workflow_run_id" field.
func (m *CASMappingMutation) ResetWorkflowRunID() {
	m.workflow_run_id = nil
	delete(m.clearedFields, casmapping.FieldWorkflowRunID)
}

// SetOrganizationID sets the "organization_id" field.
func (m *CASMappingMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *CASMappingMutation) ResetOrganizationID() {
	m.organization = nil
}

// SetProjectID sets the "project_id" field.
func (m *CASMappingMutation) SetProjectID(u uuid.UUID) {
	m.project = &u
}

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

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

// ClearProjectID clears the value of the "project_id" field.
func (m *CASMappingMutation) ClearProjectID() {
	m.project = nil
	m.clearedFields[casmapping.FieldProjectID] = struct{}{}
}

// ProjectIDCleared returns if the "project_id" field was cleared in this mutation.
func (m *CASMappingMutation) ProjectIDCleared() bool {
	_, ok := m.clearedFields[casmapping.FieldProjectID]
	return ok
}

// ResetProjectID resets all changes to the "project_id" field.
func (m *CASMappingMutation) ResetProjectID() {
	m.project = nil
	delete(m.clearedFields, casmapping.FieldProjectID)
}

// SetCasBackendID sets the "cas_backend" edge to the CASBackend entity by id.
func (m *CASMappingMutation) SetCasBackendID(id uuid.UUID) {
	m.cas_backend = &id
}

// ClearCasBackend clears the "cas_backend" edge to the CASBackend entity.
func (m *CASMappingMutation) ClearCasBackend() {
	m.clearedcas_backend = true
}

// CasBackendCleared reports if the "cas_backend" edge to the CASBackend entity was cleared.
func (m *CASMappingMutation) CasBackendCleared() bool {
	return m.clearedcas_backend
}

// CasBackendID returns the "cas_backend" edge ID in the mutation.
func (m *CASMappingMutation) CasBackendID() (id uuid.UUID, exists bool) {
	if m.cas_backend != nil {
		return *m.cas_backend, true
	}
	return
}

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

// ResetCasBackend resets all changes to the "cas_backend" edge.
func (m *CASMappingMutation) ResetCasBackend() {
	m.cas_backend = nil
	m.clearedcas_backend = false
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *CASMappingMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[casmapping.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *CASMappingMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *CASMappingMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// ClearProject clears the "project" edge to the Project entity.
func (m *CASMappingMutation) ClearProject() {
	m.clearedproject = true
	m.clearedFields[casmapping.FieldProjectID] = struct{}{}
}

// ProjectCleared reports if the "project" edge to the Project entity was cleared.
func (m *CASMappingMutation) ProjectCleared() bool {
	return m.ProjectIDCleared() || m.clearedproject
}

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

// ResetProject resets all changes to the "project" edge.
func (m *CASMappingMutation) ResetProject() {
	m.project = nil
	m.clearedproject = false
}

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

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

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

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

// Type returns the node type of this mutation (CASMapping).
func (m *CASMappingMutation) 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 *CASMappingMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.digest != nil {
		fields = append(fields, casmapping.FieldDigest)
	}
	if m.created_at != nil {
		fields = append(fields, casmapping.FieldCreatedAt)
	}
	if m.workflow_run_id != nil {
		fields = append(fields, casmapping.FieldWorkflowRunID)
	}
	if m.organization != nil {
		fields = append(fields, casmapping.FieldOrganizationID)
	}
	if m.project != nil {
		fields = append(fields, casmapping.FieldProjectID)
	}
	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 *CASMappingMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case casmapping.FieldDigest:
		return m.Digest()
	case casmapping.FieldCreatedAt:
		return m.CreatedAt()
	case casmapping.FieldWorkflowRunID:
		return m.WorkflowRunID()
	case casmapping.FieldOrganizationID:
		return m.OrganizationID()
	case casmapping.FieldProjectID:
		return m.ProjectID()
	}
	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 *CASMappingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case casmapping.FieldDigest:
		return m.OldDigest(ctx)
	case casmapping.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case casmapping.FieldWorkflowRunID:
		return m.OldWorkflowRunID(ctx)
	case casmapping.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	case casmapping.FieldProjectID:
		return m.OldProjectID(ctx)
	}
	return nil, fmt.Errorf("unknown CASMapping 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 *CASMappingMutation) SetField(name string, value ent.Value) error {
	switch name {
	case casmapping.FieldDigest:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDigest(v)
		return nil
	case casmapping.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case casmapping.FieldWorkflowRunID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWorkflowRunID(v)
		return nil
	case casmapping.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	case casmapping.FieldProjectID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProjectID(v)
		return nil
	}
	return fmt.Errorf("unknown CASMapping field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CASMappingMutation) 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 *CASMappingMutation) ClearField(name string) error {
	switch name {
	case casmapping.FieldWorkflowRunID:
		m.ClearWorkflowRunID()
		return nil
	case casmapping.FieldProjectID:
		m.ClearProjectID()
		return nil
	}
	return fmt.Errorf("unknown CASMapping 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 *CASMappingMutation) ResetField(name string) error {
	switch name {
	case casmapping.FieldDigest:
		m.ResetDigest()
		return nil
	case casmapping.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case casmapping.FieldWorkflowRunID:
		m.ResetWorkflowRunID()
		return nil
	case casmapping.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	case casmapping.FieldProjectID:
		m.ResetProjectID()
		return nil
	}
	return fmt.Errorf("unknown CASMapping field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CASMappingMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.cas_backend != nil {
		edges = append(edges, casmapping.EdgeCasBackend)
	}
	if m.organization != nil {
		edges = append(edges, casmapping.EdgeOrganization)
	}
	if m.project != nil {
		edges = append(edges, casmapping.EdgeProject)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CASMappingMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case casmapping.EdgeCasBackend:
		if id := m.cas_backend; id != nil {
			return []ent.Value{*id}
		}
	case casmapping.EdgeOrganization:
		if id := m.organization; id != nil {
			return []ent.Value{*id}
		}
	case casmapping.EdgeProject:
		if id := m.project; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CASMappingMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedcas_backend {
		edges = append(edges, casmapping.EdgeCasBackend)
	}
	if m.clearedorganization {
		edges = append(edges, casmapping.EdgeOrganization)
	}
	if m.clearedproject {
		edges = append(edges, casmapping.EdgeProject)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CASMappingMutation) EdgeCleared(name string) bool {
	switch name {
	case casmapping.EdgeCasBackend:
		return m.clearedcas_backend
	case casmapping.EdgeOrganization:
		return m.clearedorganization
	case casmapping.EdgeProject:
		return m.clearedproject
	}
	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 *CASMappingMutation) ClearEdge(name string) error {
	switch name {
	case casmapping.EdgeCasBackend:
		m.ClearCasBackend()
		return nil
	case casmapping.EdgeOrganization:
		m.ClearOrganization()
		return nil
	case casmapping.EdgeProject:
		m.ClearProject()
		return nil
	}
	return fmt.Errorf("unknown CASMapping 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 *CASMappingMutation) ResetEdge(name string) error {
	switch name {
	case casmapping.EdgeCasBackend:
		m.ResetCasBackend()
		return nil
	case casmapping.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case casmapping.EdgeProject:
		m.ResetProject()
		return nil
	}
	return fmt.Errorf("unknown CASMapping edge %s", name)
}

// GroupMutation represents an operation that mutates the Group nodes in the graph.
type GroupMutation struct {
	config
	op                       Op
	typ                      string
	id                       *uuid.UUID
	name                     *string
	description              *string
	created_at               *time.Time
	updated_at               *time.Time
	deleted_at               *time.Time
	member_count             *int
	addmember_count          *int
	clearedFields            map[string]struct{}
	group_memberships        map[uuid.UUID]struct{}
	removedgroup_memberships map[uuid.UUID]struct{}
	clearedgroup_memberships bool
	organization             *uuid.UUID
	clearedorganization      bool
	done                     bool
	oldValue                 func(context.Context) (*Group, error)
	predicates               []predicate.Group
}

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

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

// newGroupMutation creates new mutation for the Group entity.
func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
	m := &GroupMutation{
		config:        c,
		op:            op,
		typ:           TypeGroup,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group 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 *GroupMutation) 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 *GroupMutation) ResetName() {
	m.name = nil
}

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

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

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

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

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

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

// SetOrganizationID sets the "organization_id" field.
func (m *GroupMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *GroupMutation) ResetOrganizationID() {
	m.organization = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *GroupMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *GroupMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[group.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *GroupMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[group.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *GroupMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, group.FieldDeletedAt)
}

// SetMemberCount sets the "member_count" field.
func (m *GroupMutation) SetMemberCount(i int) {
	m.member_count = &i
	m.addmember_count = nil
}

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

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

// AddMemberCount adds i to the "member_count" field.
func (m *GroupMutation) AddMemberCount(i int) {
	if m.addmember_count != nil {
		*m.addmember_count += i
	} else {
		m.addmember_count = &i
	}
}

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

// ResetMemberCount resets all changes to the "member_count" field.
func (m *GroupMutation) ResetMemberCount() {
	m.member_count = nil
	m.addmember_count = nil
}

// AddGroupMembershipIDs adds the "group_memberships" edge to the GroupMembership entity by ids.
func (m *GroupMutation) AddGroupMembershipIDs(ids ...uuid.UUID) {
	if m.group_memberships == nil {
		m.group_memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.group_memberships[ids[i]] = struct{}{}
	}
}

// ClearGroupMemberships clears the "group_memberships" edge to the GroupMembership entity.
func (m *GroupMutation) ClearGroupMemberships() {
	m.clearedgroup_memberships = true
}

// GroupMembershipsCleared reports if the "group_memberships" edge to the GroupMembership entity was cleared.
func (m *GroupMutation) GroupMembershipsCleared() bool {
	return m.clearedgroup_memberships
}

// RemoveGroupMembershipIDs removes the "group_memberships" edge to the GroupMembership entity by IDs.
func (m *GroupMutation) RemoveGroupMembershipIDs(ids ...uuid.UUID) {
	if m.removedgroup_memberships == nil {
		m.removedgroup_memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.group_memberships, ids[i])
		m.removedgroup_memberships[ids[i]] = struct{}{}
	}
}

// RemovedGroupMemberships returns the removed IDs of the "group_memberships" edge to the GroupMembership entity.
func (m *GroupMutation) RemovedGroupMembershipsIDs() (ids []uuid.UUID) {
	for id := range m.removedgroup_memberships {
		ids = append(ids, id)
	}
	return
}

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

// ResetGroupMemberships resets all changes to the "group_memberships" edge.
func (m *GroupMutation) ResetGroupMemberships() {
	m.group_memberships = nil
	m.clearedgroup_memberships = false
	m.removedgroup_memberships = nil
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *GroupMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[group.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *GroupMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *GroupMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

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

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

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

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

// Type returns the node type of this mutation (Group).
func (m *GroupMutation) 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 *GroupMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, group.FieldName)
	}
	if m.description != nil {
		fields = append(fields, group.FieldDescription)
	}
	if m.organization != nil {
		fields = append(fields, group.FieldOrganizationID)
	}
	if m.created_at != nil {
		fields = append(fields, group.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, group.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, group.FieldDeletedAt)
	}
	if m.member_count != nil {
		fields = append(fields, group.FieldMemberCount)
	}
	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 *GroupMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case group.FieldName:
		return m.Name()
	case group.FieldDescription:
		return m.Description()
	case group.FieldOrganizationID:
		return m.OrganizationID()
	case group.FieldCreatedAt:
		return m.CreatedAt()
	case group.FieldUpdatedAt:
		return m.UpdatedAt()
	case group.FieldDeletedAt:
		return m.DeletedAt()
	case group.FieldMemberCount:
		return m.MemberCount()
	}
	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 *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case group.FieldName:
		return m.OldName(ctx)
	case group.FieldDescription:
		return m.OldDescription(ctx)
	case group.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	case group.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case group.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case group.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case group.FieldMemberCount:
		return m.OldMemberCount(ctx)
	}
	return nil, fmt.Errorf("unknown Group 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 *GroupMutation) SetField(name string, value ent.Value) error {
	switch name {
	case group.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case group.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case group.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	case group.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case group.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case group.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case group.FieldMemberCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMemberCount(v)
		return nil
	}
	return fmt.Errorf("unknown Group field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GroupMutation) 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 *GroupMutation) ClearField(name string) error {
	switch name {
	case group.FieldDescription:
		m.ClearDescription()
		return nil
	case group.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown Group 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 *GroupMutation) ResetField(name string) error {
	switch name {
	case group.FieldName:
		m.ResetName()
		return nil
	case group.FieldDescription:
		m.ResetDescription()
		return nil
	case group.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	case group.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case group.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case group.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case group.FieldMemberCount:
		m.ResetMemberCount()
		return nil
	}
	return fmt.Errorf("unknown Group field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.group_memberships != nil {
		edges = append(edges, group.EdgeGroupMemberships)
	}
	if m.organization != nil {
		edges = append(edges, group.EdgeOrganization)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedgroup_memberships {
		edges = append(edges, group.EdgeGroupMemberships)
	}
	if m.clearedorganization {
		edges = append(edges, group.EdgeOrganization)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GroupMutation) EdgeCleared(name string) bool {
	switch name {
	case group.EdgeGroupMemberships:
		return m.clearedgroup_memberships
	case group.EdgeOrganization:
		return m.clearedorganization
	}
	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 *GroupMutation) ClearEdge(name string) error {
	switch name {
	case group.EdgeOrganization:
		m.ClearOrganization()
		return nil
	}
	return fmt.Errorf("unknown Group 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 *GroupMutation) ResetEdge(name string) error {
	switch name {
	case group.EdgeGroupMemberships:
		m.ResetGroupMemberships()
		return nil
	case group.EdgeOrganization:
		m.ResetOrganization()
		return nil
	}
	return fmt.Errorf("unknown Group edge %s", name)
}

// GroupMembershipMutation represents an operation that mutates the GroupMembership nodes in the graph.
type GroupMembershipMutation struct {
	config
	op            Op
	typ           string
	id            *uuid.UUID
	maintainer    *bool
	created_at    *time.Time
	updated_at    *time.Time
	deleted_at    *time.Time
	clearedFields map[string]struct{}
	group         *uuid.UUID
	clearedgroup  bool
	user          *uuid.UUID
	cleareduser   bool
	done          bool
	oldValue      func(context.Context) (*GroupMembership, error)
	predicates    []predicate.GroupMembership
}

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

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

// newGroupMembershipMutation creates new mutation for the GroupMembership entity.
func newGroupMembershipMutation(c config, op Op, opts ...groupmembershipOption) *GroupMembershipMutation {
	m := &GroupMembershipMutation{
		config:        c,
		op:            op,
		typ:           TypeGroupMembership,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetGroupID sets the "group_id" field.
func (m *GroupMembershipMutation) SetGroupID(u uuid.UUID) {
	m.group = &u
}

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

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

// ResetGroupID resets all changes to the "group_id" field.
func (m *GroupMembershipMutation) ResetGroupID() {
	m.group = nil
}

// SetUserID sets the "user_id" field.
func (m *GroupMembershipMutation) SetUserID(u uuid.UUID) {
	m.user = &u
}

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

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

// ResetUserID resets all changes to the "user_id" field.
func (m *GroupMembershipMutation) ResetUserID() {
	m.user = nil
}

// SetMaintainer sets the "maintainer" field.
func (m *GroupMembershipMutation) SetMaintainer(b bool) {
	m.maintainer = &b
}

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

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

// ResetMaintainer resets all changes to the "maintainer" field.
func (m *GroupMembershipMutation) ResetMaintainer() {
	m.maintainer = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *GroupMembershipMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *GroupMembershipMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[groupmembership.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *GroupMembershipMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[groupmembership.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *GroupMembershipMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, groupmembership.FieldDeletedAt)
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *GroupMembershipMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[groupmembership.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *GroupMembershipMutation) GroupCleared() bool {
	return m.clearedgroup
}

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

// ResetGroup resets all changes to the "group" edge.
func (m *GroupMembershipMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// ClearUser clears the "user" edge to the User entity.
func (m *GroupMembershipMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[groupmembership.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *GroupMembershipMutation) UserCleared() bool {
	return m.cleareduser
}

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

// ResetUser resets all changes to the "user" edge.
func (m *GroupMembershipMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

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

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

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

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

// Type returns the node type of this mutation (GroupMembership).
func (m *GroupMembershipMutation) 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 *GroupMembershipMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.group != nil {
		fields = append(fields, groupmembership.FieldGroupID)
	}
	if m.user != nil {
		fields = append(fields, groupmembership.FieldUserID)
	}
	if m.maintainer != nil {
		fields = append(fields, groupmembership.FieldMaintainer)
	}
	if m.created_at != nil {
		fields = append(fields, groupmembership.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, groupmembership.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, groupmembership.FieldDeletedAt)
	}
	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 *GroupMembershipMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case groupmembership.FieldGroupID:
		return m.GroupID()
	case groupmembership.FieldUserID:
		return m.UserID()
	case groupmembership.FieldMaintainer:
		return m.Maintainer()
	case groupmembership.FieldCreatedAt:
		return m.CreatedAt()
	case groupmembership.FieldUpdatedAt:
		return m.UpdatedAt()
	case groupmembership.FieldDeletedAt:
		return m.DeletedAt()
	}
	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 *GroupMembershipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case groupmembership.FieldGroupID:
		return m.OldGroupID(ctx)
	case groupmembership.FieldUserID:
		return m.OldUserID(ctx)
	case groupmembership.FieldMaintainer:
		return m.OldMaintainer(ctx)
	case groupmembership.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case groupmembership.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case groupmembership.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	}
	return nil, fmt.Errorf("unknown GroupMembership 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 *GroupMembershipMutation) SetField(name string, value ent.Value) error {
	switch name {
	case groupmembership.FieldGroupID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case groupmembership.FieldUserID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case groupmembership.FieldMaintainer:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMaintainer(v)
		return nil
	case groupmembership.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case groupmembership.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case groupmembership.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	}
	return fmt.Errorf("unknown GroupMembership field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GroupMembershipMutation) 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 *GroupMembershipMutation) ClearField(name string) error {
	switch name {
	case groupmembership.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown GroupMembership 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 *GroupMembershipMutation) ResetField(name string) error {
	switch name {
	case groupmembership.FieldGroupID:
		m.ResetGroupID()
		return nil
	case groupmembership.FieldUserID:
		m.ResetUserID()
		return nil
	case groupmembership.FieldMaintainer:
		m.ResetMaintainer()
		return nil
	case groupmembership.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case groupmembership.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case groupmembership.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown GroupMembership field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMembershipMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.group != nil {
		edges = append(edges, groupmembership.EdgeGroup)
	}
	if m.user != nil {
		edges = append(edges, groupmembership.EdgeUser)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMembershipMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedgroup {
		edges = append(edges, groupmembership.EdgeGroup)
	}
	if m.cleareduser {
		edges = append(edges, groupmembership.EdgeUser)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GroupMembershipMutation) EdgeCleared(name string) bool {
	switch name {
	case groupmembership.EdgeGroup:
		return m.clearedgroup
	case groupmembership.EdgeUser:
		return m.cleareduser
	}
	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 *GroupMembershipMutation) ClearEdge(name string) error {
	switch name {
	case groupmembership.EdgeGroup:
		m.ClearGroup()
		return nil
	case groupmembership.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown GroupMembership 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 *GroupMembershipMutation) ResetEdge(name string) error {
	switch name {
	case groupmembership.EdgeGroup:
		m.ResetGroup()
		return nil
	case groupmembership.EdgeUser:
		m.ResetUser()
		return nil
	}
	return fmt.Errorf("unknown GroupMembership edge %s", name)
}

// IntegrationMutation represents an operation that mutates the Integration nodes in the graph.
type IntegrationMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	name                *string
	kind                *string
	description         *string
	secret_name         *string
	created_at          *time.Time
	configuration       *[]byte
	deleted_at          *time.Time
	clearedFields       map[string]struct{}
	attachments         map[uuid.UUID]struct{}
	removedattachments  map[uuid.UUID]struct{}
	clearedattachments  bool
	organization        *uuid.UUID
	clearedorganization bool
	done                bool
	oldValue            func(context.Context) (*Integration, error)
	predicates          []predicate.Integration
}

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

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

// newIntegrationMutation creates new mutation for the Integration entity.
func newIntegrationMutation(c config, op Op, opts ...integrationOption) *IntegrationMutation {
	m := &IntegrationMutation{
		config:        c,
		op:            op,
		typ:           TypeIntegration,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *IntegrationMutation) 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 Integration entity.
// If the Integration 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 *IntegrationMutation) 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 *IntegrationMutation) ResetName() {
	m.name = nil
}

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

// Kind returns the value of the "kind" field in the mutation.
func (m *IntegrationMutation) 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 Integration entity.
// If the Integration 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 *IntegrationMutation) 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 *IntegrationMutation) ResetKind() {
	m.kind = nil
}

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

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

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

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

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

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

// SetSecretName sets the "secret_name" field.
func (m *IntegrationMutation) SetSecretName(s string) {
	m.secret_name = &s
}

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

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

// ResetSecretName resets all changes to the "secret_name" field.
func (m *IntegrationMutation) ResetSecretName() {
	m.secret_name = nil
}

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

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

// SetConfiguration sets the "configuration" field.
func (m *IntegrationMutation) SetConfiguration(b []byte) {
	m.configuration = &b
}

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

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

// ClearConfiguration clears the value of the "configuration" field.
func (m *IntegrationMutation) ClearConfiguration() {
	m.configuration = nil
	m.clearedFields[integration.FieldConfiguration] = struct{}{}
}

// ConfigurationCleared returns if the "configuration" field was cleared in this mutation.
func (m *IntegrationMutation) ConfigurationCleared() bool {
	_, ok := m.clearedFields[integration.FieldConfiguration]
	return ok
}

// ResetConfiguration resets all changes to the "configuration" field.
func (m *IntegrationMutation) ResetConfiguration() {
	m.configuration = nil
	delete(m.clearedFields, integration.FieldConfiguration)
}

// SetDeletedAt sets the "deleted_at" field.
func (m *IntegrationMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *IntegrationMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[integration.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *IntegrationMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[integration.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *IntegrationMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, integration.FieldDeletedAt)
}

// AddAttachmentIDs adds the "attachments" edge to the IntegrationAttachment entity by ids.
func (m *IntegrationMutation) AddAttachmentIDs(ids ...uuid.UUID) {
	if m.attachments == nil {
		m.attachments = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.attachments[ids[i]] = struct{}{}
	}
}

// ClearAttachments clears the "attachments" edge to the IntegrationAttachment entity.
func (m *IntegrationMutation) ClearAttachments() {
	m.clearedattachments = true
}

// AttachmentsCleared reports if the "attachments" edge to the IntegrationAttachment entity was cleared.
func (m *IntegrationMutation) AttachmentsCleared() bool {
	return m.clearedattachments
}

// RemoveAttachmentIDs removes the "attachments" edge to the IntegrationAttachment entity by IDs.
func (m *IntegrationMutation) RemoveAttachmentIDs(ids ...uuid.UUID) {
	if m.removedattachments == nil {
		m.removedattachments = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.attachments, ids[i])
		m.removedattachments[ids[i]] = struct{}{}
	}
}

// RemovedAttachments returns the removed IDs of the "attachments" edge to the IntegrationAttachment entity.
func (m *IntegrationMutation) RemovedAttachmentsIDs() (ids []uuid.UUID) {
	for id := range m.removedattachments {
		ids = append(ids, id)
	}
	return
}

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

// ResetAttachments resets all changes to the "attachments" edge.
func (m *IntegrationMutation) ResetAttachments() {
	m.attachments = nil
	m.clearedattachments = false
	m.removedattachments = nil
}

// SetOrganizationID sets the "organization" edge to the Organization entity by id.
func (m *IntegrationMutation) SetOrganizationID(id uuid.UUID) {
	m.organization = &id
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *IntegrationMutation) ClearOrganization() {
	m.clearedorganization = true
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *IntegrationMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

// OrganizationID returns the "organization" edge ID in the mutation.
func (m *IntegrationMutation) OrganizationID() (id uuid.UUID, exists bool) {
	if m.organization != nil {
		return *m.organization, true
	}
	return
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *IntegrationMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

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

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

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

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

// Type returns the node type of this mutation (Integration).
func (m *IntegrationMutation) 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 *IntegrationMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, integration.FieldName)
	}
	if m.kind != nil {
		fields = append(fields, integration.FieldKind)
	}
	if m.description != nil {
		fields = append(fields, integration.FieldDescription)
	}
	if m.secret_name != nil {
		fields = append(fields, integration.FieldSecretName)
	}
	if m.created_at != nil {
		fields = append(fields, integration.FieldCreatedAt)
	}
	if m.configuration != nil {
		fields = append(fields, integration.FieldConfiguration)
	}
	if m.deleted_at != nil {
		fields = append(fields, integration.FieldDeletedAt)
	}
	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 *IntegrationMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case integration.FieldName:
		return m.Name()
	case integration.FieldKind:
		return m.Kind()
	case integration.FieldDescription:
		return m.Description()
	case integration.FieldSecretName:
		return m.SecretName()
	case integration.FieldCreatedAt:
		return m.CreatedAt()
	case integration.FieldConfiguration:
		return m.Configuration()
	case integration.FieldDeletedAt:
		return m.DeletedAt()
	}
	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 *IntegrationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case integration.FieldName:
		return m.OldName(ctx)
	case integration.FieldKind:
		return m.OldKind(ctx)
	case integration.FieldDescription:
		return m.OldDescription(ctx)
	case integration.FieldSecretName:
		return m.OldSecretName(ctx)
	case integration.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case integration.FieldConfiguration:
		return m.OldConfiguration(ctx)
	case integration.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Integration 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 *IntegrationMutation) SetField(name string, value ent.Value) error {
	switch name {
	case integration.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case integration.FieldKind:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKind(v)
		return nil
	case integration.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case integration.FieldSecretName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSecretName(v)
		return nil
	case integration.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case integration.FieldConfiguration:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConfiguration(v)
		return nil
	case integration.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Integration field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *IntegrationMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(integration.FieldDescription) {
		fields = append(fields, integration.FieldDescription)
	}
	if m.FieldCleared(integration.FieldConfiguration) {
		fields = append(fields, integration.FieldConfiguration)
	}
	if m.FieldCleared(integration.FieldDeletedAt) {
		fields = append(fields, integration.FieldDeletedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *IntegrationMutation) 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 *IntegrationMutation) ClearField(name string) error {
	switch name {
	case integration.FieldDescription:
		m.ClearDescription()
		return nil
	case integration.FieldConfiguration:
		m.ClearConfiguration()
		return nil
	case integration.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown Integration 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 *IntegrationMutation) ResetField(name string) error {
	switch name {
	case integration.FieldName:
		m.ResetName()
		return nil
	case integration.FieldKind:
		m.ResetKind()
		return nil
	case integration.FieldDescription:
		m.ResetDescription()
		return nil
	case integration.FieldSecretName:
		m.ResetSecretName()
		return nil
	case integration.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case integration.FieldConfiguration:
		m.ResetConfiguration()
		return nil
	case integration.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown Integration field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *IntegrationMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.attachments != nil {
		edges = append(edges, integration.EdgeAttachments)
	}
	if m.organization != nil {
		edges = append(edges, integration.EdgeOrganization)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *IntegrationMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedattachments {
		edges = append(edges, integration.EdgeAttachments)
	}
	if m.clearedorganization {
		edges = append(edges, integration.EdgeOrganization)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *IntegrationMutation) EdgeCleared(name string) bool {
	switch name {
	case integration.EdgeAttachments:
		return m.clearedattachments
	case integration.EdgeOrganization:
		return m.clearedorganization
	}
	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 *IntegrationMutation) ClearEdge(name string) error {
	switch name {
	case integration.EdgeOrganization:
		m.ClearOrganization()
		return nil
	}
	return fmt.Errorf("unknown Integration 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 *IntegrationMutation) ResetEdge(name string) error {
	switch name {
	case integration.EdgeAttachments:
		m.ResetAttachments()
		return nil
	case integration.EdgeOrganization:
		m.ResetOrganization()
		return nil
	}
	return fmt.Errorf("unknown Integration edge %s", name)
}

// IntegrationAttachmentMutation represents an operation that mutates the IntegrationAttachment nodes in the graph.
type IntegrationAttachmentMutation struct {
	config
	op                 Op
	typ                string
	id                 *uuid.UUID
	created_at         *time.Time
	configuration      *[]byte
	deleted_at         *time.Time
	clearedFields      map[string]struct{}
	integration        *uuid.UUID
	clearedintegration bool
	workflow           *uuid.UUID
	clearedworkflow    bool
	done               bool
	oldValue           func(context.Context) (*IntegrationAttachment, error)
	predicates         []predicate.IntegrationAttachment
}

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

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

// newIntegrationAttachmentMutation creates new mutation for the IntegrationAttachment entity.
func newIntegrationAttachmentMutation(c config, op Op, opts ...integrationattachmentOption) *IntegrationAttachmentMutation {
	m := &IntegrationAttachmentMutation{
		config:        c,
		op:            op,
		typ:           TypeIntegrationAttachment,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

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

// SetConfiguration sets the "configuration" field.
func (m *IntegrationAttachmentMutation) SetConfiguration(b []byte) {
	m.configuration = &b
}

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

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

// ClearConfiguration clears the value of the "configuration" field.
func (m *IntegrationAttachmentMutation) ClearConfiguration() {
	m.configuration = nil
	m.clearedFields[integrationattachment.FieldConfiguration] = struct{}{}
}

// ConfigurationCleared returns if the "configuration" field was cleared in this mutation.
func (m *IntegrationAttachmentMutation) ConfigurationCleared() bool {
	_, ok := m.clearedFields[integrationattachment.FieldConfiguration]
	return ok
}

// ResetConfiguration resets all changes to the "configuration" field.
func (m *IntegrationAttachmentMutation) ResetConfiguration() {
	m.configuration = nil
	delete(m.clearedFields, integrationattachment.FieldConfiguration)
}

// SetDeletedAt sets the "deleted_at" field.
func (m *IntegrationAttachmentMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *IntegrationAttachmentMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[integrationattachment.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *IntegrationAttachmentMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[integrationattachment.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *IntegrationAttachmentMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, integrationattachment.FieldDeletedAt)
}

// SetWorkflowID sets the "workflow_id" field.
func (m *IntegrationAttachmentMutation) SetWorkflowID(u uuid.UUID) {
	m.workflow = &u
}

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

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

// ResetWorkflowID resets all changes to the "workflow_id" field.
func (m *IntegrationAttachmentMutation) ResetWorkflowID() {
	m.workflow = nil
}

// SetIntegrationID sets the "integration" edge to the Integration entity by id.
func (m *IntegrationAttachmentMutation) SetIntegrationID(id uuid.UUID) {
	m.integration = &id
}

// ClearIntegration clears the "integration" edge to the Integration entity.
func (m *IntegrationAttachmentMutation) ClearIntegration() {
	m.clearedintegration = true
}

// IntegrationCleared reports if the "integration" edge to the Integration entity was cleared.
func (m *IntegrationAttachmentMutation) IntegrationCleared() bool {
	return m.clearedintegration
}

// IntegrationID returns the "integration" edge ID in the mutation.
func (m *IntegrationAttachmentMutation) IntegrationID() (id uuid.UUID, exists bool) {
	if m.integration != nil {
		return *m.integration, true
	}
	return
}

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

// ResetIntegration resets all changes to the "integration" edge.
func (m *IntegrationAttachmentMutation) ResetIntegration() {
	m.integration = nil
	m.clearedintegration = false
}

// ClearWorkflow clears the "workflow" edge to the Workflow entity.
func (m *IntegrationAttachmentMutation) ClearWorkflow() {
	m.clearedworkflow = true
	m.clearedFields[integrationattachment.FieldWorkflowID] = struct{}{}
}

// WorkflowCleared reports if the "workflow" edge to the Workflow entity was cleared.
func (m *IntegrationAttachmentMutation) WorkflowCleared() bool {
	return m.clearedworkflow
}

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

// ResetWorkflow resets all changes to the "workflow" edge.
func (m *IntegrationAttachmentMutation) ResetWorkflow() {
	m.workflow = nil
	m.clearedworkflow = false
}

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

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

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

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

// Type returns the node type of this mutation (IntegrationAttachment).
func (m *IntegrationAttachmentMutation) 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 *IntegrationAttachmentMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.created_at != nil {
		fields = append(fields, integrationattachment.FieldCreatedAt)
	}
	if m.configuration != nil {
		fields = append(fields, integrationattachment.FieldConfiguration)
	}
	if m.deleted_at != nil {
		fields = append(fields, integrationattachment.FieldDeletedAt)
	}
	if m.workflow != nil {
		fields = append(fields, integrationattachment.FieldWorkflowID)
	}
	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 *IntegrationAttachmentMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case integrationattachment.FieldCreatedAt:
		return m.CreatedAt()
	case integrationattachment.FieldConfiguration:
		return m.Configuration()
	case integrationattachment.FieldDeletedAt:
		return m.DeletedAt()
	case integrationattachment.FieldWorkflowID:
		return m.WorkflowID()
	}
	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 *IntegrationAttachmentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case integrationattachment.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case integrationattachment.FieldConfiguration:
		return m.OldConfiguration(ctx)
	case integrationattachment.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case integrationattachment.FieldWorkflowID:
		return m.OldWorkflowID(ctx)
	}
	return nil, fmt.Errorf("unknown IntegrationAttachment 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 *IntegrationAttachmentMutation) SetField(name string, value ent.Value) error {
	switch name {
	case integrationattachment.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case integrationattachment.FieldConfiguration:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConfiguration(v)
		return nil
	case integrationattachment.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case integrationattachment.FieldWorkflowID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWorkflowID(v)
		return nil
	}
	return fmt.Errorf("unknown IntegrationAttachment field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *IntegrationAttachmentMutation) 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 *IntegrationAttachmentMutation) ClearField(name string) error {
	switch name {
	case integrationattachment.FieldConfiguration:
		m.ClearConfiguration()
		return nil
	case integrationattachment.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown IntegrationAttachment 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 *IntegrationAttachmentMutation) ResetField(name string) error {
	switch name {
	case integrationattachment.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case integrationattachment.FieldConfiguration:
		m.ResetConfiguration()
		return nil
	case integrationattachment.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case integrationattachment.FieldWorkflowID:
		m.ResetWorkflowID()
		return nil
	}
	return fmt.Errorf("unknown IntegrationAttachment field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *IntegrationAttachmentMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.integration != nil {
		edges = append(edges, integrationattachment.EdgeIntegration)
	}
	if m.workflow != nil {
		edges = append(edges, integrationattachment.EdgeWorkflow)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *IntegrationAttachmentMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedintegration {
		edges = append(edges, integrationattachment.EdgeIntegration)
	}
	if m.clearedworkflow {
		edges = append(edges, integrationattachment.EdgeWorkflow)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *IntegrationAttachmentMutation) EdgeCleared(name string) bool {
	switch name {
	case integrationattachment.EdgeIntegration:
		return m.clearedintegration
	case integrationattachment.EdgeWorkflow:
		return m.clearedworkflow
	}
	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 *IntegrationAttachmentMutation) ClearEdge(name string) error {
	switch name {
	case integrationattachment.EdgeIntegration:
		m.ClearIntegration()
		return nil
	case integrationattachment.EdgeWorkflow:
		m.ClearWorkflow()
		return nil
	}
	return fmt.Errorf("unknown IntegrationAttachment 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 *IntegrationAttachmentMutation) ResetEdge(name string) error {
	switch name {
	case integrationattachment.EdgeIntegration:
		m.ResetIntegration()
		return nil
	case integrationattachment.EdgeWorkflow:
		m.ResetWorkflow()
		return nil
	}
	return fmt.Errorf("unknown IntegrationAttachment edge %s", name)
}

// MembershipMutation represents an operation that mutates the Membership nodes in the graph.
type MembershipMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	current             *bool
	created_at          *time.Time
	updated_at          *time.Time
	role                *authz.Role
	membership_type     *authz.MembershipType
	member_id           *uuid.UUID
	resource_type       *authz.ResourceType
	resource_id         *uuid.UUID
	clearedFields       map[string]struct{}
	organization        *uuid.UUID
	clearedorganization bool
	user                *uuid.UUID
	cleareduser         bool
	parent              *uuid.UUID
	clearedparent       bool
	children            map[uuid.UUID]struct{}
	removedchildren     map[uuid.UUID]struct{}
	clearedchildren     bool
	done                bool
	oldValue            func(context.Context) (*Membership, error)
	predicates          []predicate.Membership
}

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

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

// newMembershipMutation creates new mutation for the Membership entity.
func newMembershipMutation(c config, op Op, opts ...membershipOption) *MembershipMutation {
	m := &MembershipMutation{
		config:        c,
		op:            op,
		typ:           TypeMembership,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetCurrent sets the "current" field.
func (m *MembershipMutation) SetCurrent(b bool) {
	m.current = &b
}

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

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

// ResetCurrent resets all changes to the "current" field.
func (m *MembershipMutation) ResetCurrent() {
	m.current = nil
}

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

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

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

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

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

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

// SetRole sets the "role" field.
func (m *MembershipMutation) SetRole(a authz.Role) {
	m.role = &a
}

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

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

// ResetRole resets all changes to the "role" field.
func (m *MembershipMutation) ResetRole() {
	m.role = nil
}

// SetMembershipType sets the "membership_type" field.
func (m *MembershipMutation) SetMembershipType(at authz.MembershipType) {
	m.membership_type = &at
}

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

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

// ClearMembershipType clears the value of the "membership_type" field.
func (m *MembershipMutation) ClearMembershipType() {
	m.membership_type = nil
	m.clearedFields[membership.FieldMembershipType] = struct{}{}
}

// MembershipTypeCleared returns if the "membership_type" field was cleared in this mutation.
func (m *MembershipMutation) MembershipTypeCleared() bool {
	_, ok := m.clearedFields[membership.FieldMembershipType]
	return ok
}

// ResetMembershipType resets all changes to the "membership_type" field.
func (m *MembershipMutation) ResetMembershipType() {
	m.membership_type = nil
	delete(m.clearedFields, membership.FieldMembershipType)
}

// SetMemberID sets the "member_id" field.
func (m *MembershipMutation) SetMemberID(u uuid.UUID) {
	m.member_id = &u
}

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

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

// ClearMemberID clears the value of the "member_id" field.
func (m *MembershipMutation) ClearMemberID() {
	m.member_id = nil
	m.clearedFields[membership.FieldMemberID] = struct{}{}
}

// MemberIDCleared returns if the "member_id" field was cleared in this mutation.
func (m *MembershipMutation) MemberIDCleared() bool {
	_, ok := m.clearedFields[membership.FieldMemberID]
	return ok
}

// ResetMemberID resets all changes to the "member_id" field.
func (m *MembershipMutation) ResetMemberID() {
	m.member_id = nil
	delete(m.clearedFields, membership.FieldMemberID)
}

// SetResourceType sets the "resource_type" field.
func (m *MembershipMutation) SetResourceType(at authz.ResourceType) {
	m.resource_type = &at
}

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

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

// ClearResourceType clears the value of the "resource_type" field.
func (m *MembershipMutation) ClearResourceType() {
	m.resource_type = nil
	m.clearedFields[membership.FieldResourceType] = struct{}{}
}

// ResourceTypeCleared returns if the "resource_type" field was cleared in this mutation.
func (m *MembershipMutation) ResourceTypeCleared() bool {
	_, ok := m.clearedFields[membership.FieldResourceType]
	return ok
}

// ResetResourceType resets all changes to the "resource_type" field.
func (m *MembershipMutation) ResetResourceType() {
	m.resource_type = nil
	delete(m.clearedFields, membership.FieldResourceType)
}

// SetResourceID sets the "resource_id" field.
func (m *MembershipMutation) SetResourceID(u uuid.UUID) {
	m.resource_id = &u
}

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

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

// ClearResourceID clears the value of the "resource_id" field.
func (m *MembershipMutation) ClearResourceID() {
	m.resource_id = nil
	m.clearedFields[membership.FieldResourceID] = struct{}{}
}

// ResourceIDCleared returns if the "resource_id" field was cleared in this mutation.
func (m *MembershipMutation) ResourceIDCleared() bool {
	_, ok := m.clearedFields[membership.FieldResourceID]
	return ok
}

// ResetResourceID resets all changes to the "resource_id" field.
func (m *MembershipMutation) ResetResourceID() {
	m.resource_id = nil
	delete(m.clearedFields, membership.FieldResourceID)
}

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

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

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

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

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

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

// SetOrganizationID sets the "organization" edge to the Organization entity by id.
func (m *MembershipMutation) SetOrganizationID(id uuid.UUID) {
	m.organization = &id
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *MembershipMutation) ClearOrganization() {
	m.clearedorganization = true
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *MembershipMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

// OrganizationID returns the "organization" edge ID in the mutation.
func (m *MembershipMutation) OrganizationID() (id uuid.UUID, exists bool) {
	if m.organization != nil {
		return *m.organization, true
	}
	return
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *MembershipMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// SetUserID sets the "user" edge to the User entity by id.
func (m *MembershipMutation) SetUserID(id uuid.UUID) {
	m.user = &id
}

// ClearUser clears the "user" edge to the User entity.
func (m *MembershipMutation) ClearUser() {
	m.cleareduser = true
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *MembershipMutation) UserCleared() bool {
	return m.cleareduser
}

// UserID returns the "user" edge ID in the mutation.
func (m *MembershipMutation) UserID() (id uuid.UUID, exists bool) {
	if m.user != nil {
		return *m.user, true
	}
	return
}

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

// ResetUser resets all changes to the "user" edge.
func (m *MembershipMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

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

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

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

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

// AddChildIDs adds the "children" edge to the Membership entity by ids.
func (m *MembershipMutation) AddChildIDs(ids ...uuid.UUID) {
	if m.children == nil {
		m.children = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.children[ids[i]] = struct{}{}
	}
}

// ClearChildren clears the "children" edge to the Membership entity.
func (m *MembershipMutation) ClearChildren() {
	m.clearedchildren = true
}

// ChildrenCleared reports if the "children" edge to the Membership entity was cleared.
func (m *MembershipMutation) ChildrenCleared() bool {
	return m.clearedchildren
}

// RemoveChildIDs removes the "children" edge to the Membership entity by IDs.
func (m *MembershipMutation) RemoveChildIDs(ids ...uuid.UUID) {
	if m.removedchildren == nil {
		m.removedchildren = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.children, ids[i])
		m.removedchildren[ids[i]] = struct{}{}
	}
}

// RemovedChildren returns the removed IDs of the "children" edge to the Membership entity.
func (m *MembershipMutation) RemovedChildrenIDs() (ids []uuid.UUID) {
	for id := range m.removedchildren {
		ids = append(ids, id)
	}
	return
}

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

// ResetChildren resets all changes to the "children" edge.
func (m *MembershipMutation) ResetChildren() {
	m.children = nil
	m.clearedchildren = false
	m.removedchildren = nil
}

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

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

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

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

// Type returns the node type of this mutation (Membership).
func (m *MembershipMutation) 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 *MembershipMutation) Fields() []string {
	fields := make([]string, 0, 9)
	if m.current != nil {
		fields = append(fields, membership.FieldCurrent)
	}
	if m.created_at != nil {
		fields = append(fields, membership.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, membership.FieldUpdatedAt)
	}
	if m.role != nil {
		fields = append(fields, membership.FieldRole)
	}
	if m.membership_type != nil {
		fields = append(fields, membership.FieldMembershipType)
	}
	if m.member_id != nil {
		fields = append(fields, membership.FieldMemberID)
	}
	if m.resource_type != nil {
		fields = append(fields, membership.FieldResourceType)
	}
	if m.resource_id != nil {
		fields = append(fields, membership.FieldResourceID)
	}
	if m.parent != nil {
		fields = append(fields, membership.FieldParentID)
	}
	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 *MembershipMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case membership.FieldCurrent:
		return m.Current()
	case membership.FieldCreatedAt:
		return m.CreatedAt()
	case membership.FieldUpdatedAt:
		return m.UpdatedAt()
	case membership.FieldRole:
		return m.Role()
	case membership.FieldMembershipType:
		return m.MembershipType()
	case membership.FieldMemberID:
		return m.MemberID()
	case membership.FieldResourceType:
		return m.ResourceType()
	case membership.FieldResourceID:
		return m.ResourceID()
	case membership.FieldParentID:
		return m.ParentID()
	}
	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 *MembershipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case membership.FieldCurrent:
		return m.OldCurrent(ctx)
	case membership.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case membership.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case membership.FieldRole:
		return m.OldRole(ctx)
	case membership.FieldMembershipType:
		return m.OldMembershipType(ctx)
	case membership.FieldMemberID:
		return m.OldMemberID(ctx)
	case membership.FieldResourceType:
		return m.OldResourceType(ctx)
	case membership.FieldResourceID:
		return m.OldResourceID(ctx)
	case membership.FieldParentID:
		return m.OldParentID(ctx)
	}
	return nil, fmt.Errorf("unknown Membership 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 *MembershipMutation) SetField(name string, value ent.Value) error {
	switch name {
	case membership.FieldCurrent:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCurrent(v)
		return nil
	case membership.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case membership.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case membership.FieldRole:
		v, ok := value.(authz.Role)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRole(v)
		return nil
	case membership.FieldMembershipType:
		v, ok := value.(authz.MembershipType)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMembershipType(v)
		return nil
	case membership.FieldMemberID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMemberID(v)
		return nil
	case membership.FieldResourceType:
		v, ok := value.(authz.ResourceType)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResourceType(v)
		return nil
	case membership.FieldResourceID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResourceID(v)
		return nil
	case membership.FieldParentID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetParentID(v)
		return nil
	}
	return fmt.Errorf("unknown Membership field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *MembershipMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(membership.FieldMembershipType) {
		fields = append(fields, membership.FieldMembershipType)
	}
	if m.FieldCleared(membership.FieldMemberID) {
		fields = append(fields, membership.FieldMemberID)
	}
	if m.FieldCleared(membership.FieldResourceType) {
		fields = append(fields, membership.FieldResourceType)
	}
	if m.FieldCleared(membership.FieldResourceID) {
		fields = append(fields, membership.FieldResourceID)
	}
	if m.FieldCleared(membership.FieldParentID) {
		fields = append(fields, membership.FieldParentID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *MembershipMutation) 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 *MembershipMutation) ClearField(name string) error {
	switch name {
	case membership.FieldMembershipType:
		m.ClearMembershipType()
		return nil
	case membership.FieldMemberID:
		m.ClearMemberID()
		return nil
	case membership.FieldResourceType:
		m.ClearResourceType()
		return nil
	case membership.FieldResourceID:
		m.ClearResourceID()
		return nil
	case membership.FieldParentID:
		m.ClearParentID()
		return nil
	}
	return fmt.Errorf("unknown Membership 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 *MembershipMutation) ResetField(name string) error {
	switch name {
	case membership.FieldCurrent:
		m.ResetCurrent()
		return nil
	case membership.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case membership.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case membership.FieldRole:
		m.ResetRole()
		return nil
	case membership.FieldMembershipType:
		m.ResetMembershipType()
		return nil
	case membership.FieldMemberID:
		m.ResetMemberID()
		return nil
	case membership.FieldResourceType:
		m.ResetResourceType()
		return nil
	case membership.FieldResourceID:
		m.ResetResourceID()
		return nil
	case membership.FieldParentID:
		m.ResetParentID()
		return nil
	}
	return fmt.Errorf("unknown Membership field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *MembershipMutation) AddedEdges() []string {
	edges := make([]string, 0, 4)
	if m.organization != nil {
		edges = append(edges, membership.EdgeOrganization)
	}
	if m.user != nil {
		edges = append(edges, membership.EdgeUser)
	}
	if m.parent != nil {
		edges = append(edges, membership.EdgeParent)
	}
	if m.children != nil {
		edges = append(edges, membership.EdgeChildren)
	}
	return edges
}

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

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *MembershipMutation) RemovedEdges() []string {
	edges := make([]string, 0, 4)
	if m.removedchildren != nil {
		edges = append(edges, membership.EdgeChildren)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *MembershipMutation) ClearedEdges() []string {
	edges := make([]string, 0, 4)
	if m.clearedorganization {
		edges = append(edges, membership.EdgeOrganization)
	}
	if m.cleareduser {
		edges = append(edges, membership.EdgeUser)
	}
	if m.clearedparent {
		edges = append(edges, membership.EdgeParent)
	}
	if m.clearedchildren {
		edges = append(edges, membership.EdgeChildren)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *MembershipMutation) EdgeCleared(name string) bool {
	switch name {
	case membership.EdgeOrganization:
		return m.clearedorganization
	case membership.EdgeUser:
		return m.cleareduser
	case membership.EdgeParent:
		return m.clearedparent
	case membership.EdgeChildren:
		return m.clearedchildren
	}
	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 *MembershipMutation) ClearEdge(name string) error {
	switch name {
	case membership.EdgeOrganization:
		m.ClearOrganization()
		return nil
	case membership.EdgeUser:
		m.ClearUser()
		return nil
	case membership.EdgeParent:
		m.ClearParent()
		return nil
	}
	return fmt.Errorf("unknown Membership 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 *MembershipMutation) ResetEdge(name string) error {
	switch name {
	case membership.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case membership.EdgeUser:
		m.ResetUser()
		return nil
	case membership.EdgeParent:
		m.ResetParent()
		return nil
	case membership.EdgeChildren:
		m.ResetChildren()
		return nil
	}
	return fmt.Errorf("unknown Membership edge %s", name)
}

// OrgInvitationMutation represents an operation that mutates the OrgInvitation nodes in the graph.
type OrgInvitationMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	receiver_email      *string
	status              *biz.OrgInvitationStatus
	created_at          *time.Time
	deleted_at          *time.Time
	role                *authz.Role
	context             *biz.OrgInvitationContext
	clearedFields       map[string]struct{}
	organization        *uuid.UUID
	clearedorganization bool
	sender              *uuid.UUID
	clearedsender       bool
	done                bool
	oldValue            func(context.Context) (*OrgInvitation, error)
	predicates          []predicate.OrgInvitation
}

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

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

// newOrgInvitationMutation creates new mutation for the OrgInvitation entity.
func newOrgInvitationMutation(c config, op Op, opts ...orginvitationOption) *OrgInvitationMutation {
	m := &OrgInvitationMutation{
		config:        c,
		op:            op,
		typ:           TypeOrgInvitation,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetReceiverEmail sets the "receiver_email" field.
func (m *OrgInvitationMutation) SetReceiverEmail(s string) {
	m.receiver_email = &s
}

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

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

// ResetReceiverEmail resets all changes to the "receiver_email" field.
func (m *OrgInvitationMutation) ResetReceiverEmail() {
	m.receiver_email = nil
}

// SetStatus sets the "status" field.
func (m *OrgInvitationMutation) SetStatus(bis biz.OrgInvitationStatus) {
	m.status = &bis
}

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

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

// ResetStatus resets all changes to the "status" field.
func (m *OrgInvitationMutation) ResetStatus() {
	m.status = nil
}

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *OrgInvitationMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *OrgInvitationMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[orginvitation.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *OrgInvitationMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[orginvitation.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *OrgInvitationMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, orginvitation.FieldDeletedAt)
}

// SetOrganizationID sets the "organization_id" field.
func (m *OrgInvitationMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *OrgInvitationMutation) ResetOrganizationID() {
	m.organization = nil
}

// SetSenderID sets the "sender_id" field.
func (m *OrgInvitationMutation) SetSenderID(u uuid.UUID) {
	m.sender = &u
}

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

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

// ResetSenderID resets all changes to the "sender_id" field.
func (m *OrgInvitationMutation) ResetSenderID() {
	m.sender = nil
}

// SetRole sets the "role" field.
func (m *OrgInvitationMutation) SetRole(a authz.Role) {
	m.role = &a
}

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

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

// ClearRole clears the value of the "role" field.
func (m *OrgInvitationMutation) ClearRole() {
	m.role = nil
	m.clearedFields[orginvitation.FieldRole] = struct{}{}
}

// RoleCleared returns if the "role" field was cleared in this mutation.
func (m *OrgInvitationMutation) RoleCleared() bool {
	_, ok := m.clearedFields[orginvitation.FieldRole]
	return ok
}

// ResetRole resets all changes to the "role" field.
func (m *OrgInvitationMutation) ResetRole() {
	m.role = nil
	delete(m.clearedFields, orginvitation.FieldRole)
}

// SetContext sets the "context" field.
func (m *OrgInvitationMutation) SetContext(bic biz.OrgInvitationContext) {
	m.context = &bic
}

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

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

// ClearContext clears the value of the "context" field.
func (m *OrgInvitationMutation) ClearContext() {
	m.context = nil
	m.clearedFields[orginvitation.FieldContext] = struct{}{}
}

// ContextCleared returns if the "context" field was cleared in this mutation.
func (m *OrgInvitationMutation) ContextCleared() bool {
	_, ok := m.clearedFields[orginvitation.FieldContext]
	return ok
}

// ResetContext resets all changes to the "context" field.
func (m *OrgInvitationMutation) ResetContext() {
	m.context = nil
	delete(m.clearedFields, orginvitation.FieldContext)
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *OrgInvitationMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[orginvitation.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *OrgInvitationMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *OrgInvitationMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// ClearSender clears the "sender" edge to the User entity.
func (m *OrgInvitationMutation) ClearSender() {
	m.clearedsender = true
	m.clearedFields[orginvitation.FieldSenderID] = struct{}{}
}

// SenderCleared reports if the "sender" edge to the User entity was cleared.
func (m *OrgInvitationMutation) SenderCleared() bool {
	return m.clearedsender
}

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

// ResetSender resets all changes to the "sender" edge.
func (m *OrgInvitationMutation) ResetSender() {
	m.sender = nil
	m.clearedsender = false
}

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

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

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

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

// Type returns the node type of this mutation (OrgInvitation).
func (m *OrgInvitationMutation) 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 *OrgInvitationMutation) Fields() []string {
	fields := make([]string, 0, 8)
	if m.receiver_email != nil {
		fields = append(fields, orginvitation.FieldReceiverEmail)
	}
	if m.status != nil {
		fields = append(fields, orginvitation.FieldStatus)
	}
	if m.created_at != nil {
		fields = append(fields, orginvitation.FieldCreatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, orginvitation.FieldDeletedAt)
	}
	if m.organization != nil {
		fields = append(fields, orginvitation.FieldOrganizationID)
	}
	if m.sender != nil {
		fields = append(fields, orginvitation.FieldSenderID)
	}
	if m.role != nil {
		fields = append(fields, orginvitation.FieldRole)
	}
	if m.context != nil {
		fields = append(fields, orginvitation.FieldContext)
	}
	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 *OrgInvitationMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case orginvitation.FieldReceiverEmail:
		return m.ReceiverEmail()
	case orginvitation.FieldStatus:
		return m.Status()
	case orginvitation.FieldCreatedAt:
		return m.CreatedAt()
	case orginvitation.FieldDeletedAt:
		return m.DeletedAt()
	case orginvitation.FieldOrganizationID:
		return m.OrganizationID()
	case orginvitation.FieldSenderID:
		return m.SenderID()
	case orginvitation.FieldRole:
		return m.Role()
	case orginvitation.FieldContext:
		return m.Context()
	}
	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 *OrgInvitationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case orginvitation.FieldReceiverEmail:
		return m.OldReceiverEmail(ctx)
	case orginvitation.FieldStatus:
		return m.OldStatus(ctx)
	case orginvitation.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case orginvitation.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case orginvitation.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	case orginvitation.FieldSenderID:
		return m.OldSenderID(ctx)
	case orginvitation.FieldRole:
		return m.OldRole(ctx)
	case orginvitation.FieldContext:
		return m.OldContext(ctx)
	}
	return nil, fmt.Errorf("unknown OrgInvitation 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 *OrgInvitationMutation) SetField(name string, value ent.Value) error {
	switch name {
	case orginvitation.FieldReceiverEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReceiverEmail(v)
		return nil
	case orginvitation.FieldStatus:
		v, ok := value.(biz.OrgInvitationStatus)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case orginvitation.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case orginvitation.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case orginvitation.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	case orginvitation.FieldSenderID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSenderID(v)
		return nil
	case orginvitation.FieldRole:
		v, ok := value.(authz.Role)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRole(v)
		return nil
	case orginvitation.FieldContext:
		v, ok := value.(biz.OrgInvitationContext)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetContext(v)
		return nil
	}
	return fmt.Errorf("unknown OrgInvitation field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *OrgInvitationMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(orginvitation.FieldDeletedAt) {
		fields = append(fields, orginvitation.FieldDeletedAt)
	}
	if m.FieldCleared(orginvitation.FieldRole) {
		fields = append(fields, orginvitation.FieldRole)
	}
	if m.FieldCleared(orginvitation.FieldContext) {
		fields = append(fields, orginvitation.FieldContext)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *OrgInvitationMutation) 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 *OrgInvitationMutation) ClearField(name string) error {
	switch name {
	case orginvitation.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case orginvitation.FieldRole:
		m.ClearRole()
		return nil
	case orginvitation.FieldContext:
		m.ClearContext()
		return nil
	}
	return fmt.Errorf("unknown OrgInvitation 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 *OrgInvitationMutation) ResetField(name string) error {
	switch name {
	case orginvitation.FieldReceiverEmail:
		m.ResetReceiverEmail()
		return nil
	case orginvitation.FieldStatus:
		m.ResetStatus()
		return nil
	case orginvitation.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case orginvitation.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case orginvitation.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	case orginvitation.FieldSenderID:
		m.ResetSenderID()
		return nil
	case orginvitation.FieldRole:
		m.ResetRole()
		return nil
	case orginvitation.FieldContext:
		m.ResetContext()
		return nil
	}
	return fmt.Errorf("unknown OrgInvitation field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *OrgInvitationMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.organization != nil {
		edges = append(edges, orginvitation.EdgeOrganization)
	}
	if m.sender != nil {
		edges = append(edges, orginvitation.EdgeSender)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *OrgInvitationMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedorganization {
		edges = append(edges, orginvitation.EdgeOrganization)
	}
	if m.clearedsender {
		edges = append(edges, orginvitation.EdgeSender)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *OrgInvitationMutation) EdgeCleared(name string) bool {
	switch name {
	case orginvitation.EdgeOrganization:
		return m.clearedorganization
	case orginvitation.EdgeSender:
		return m.clearedsender
	}
	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 *OrgInvitationMutation) ClearEdge(name string) error {
	switch name {
	case orginvitation.EdgeOrganization:
		m.ClearOrganization()
		return nil
	case orginvitation.EdgeSender:
		m.ClearSender()
		return nil
	}
	return fmt.Errorf("unknown OrgInvitation 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 *OrgInvitationMutation) ResetEdge(name string) error {
	switch name {
	case orginvitation.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case orginvitation.EdgeSender:
		m.ResetSender()
		return nil
	}
	return fmt.Errorf("unknown OrgInvitation edge %s", name)
}

// OrganizationMutation represents an operation that mutates the Organization nodes in the graph.
type OrganizationMutation struct {
	config
	op                               Op
	typ                              string
	id                               *uuid.UUID
	name                             *string
	created_at                       *time.Time
	updated_at                       *time.Time
	deleted_at                       *time.Time
	block_on_policy_violation        *bool
	policies_allowed_hostnames       *[]string
	appendpolicies_allowed_hostnames []string
	clearedFields                    map[string]struct{}
	memberships                      map[uuid.UUID]struct{}
	removedmemberships               map[uuid.UUID]struct{}
	clearedmemberships               bool
	workflow_contracts               map[uuid.UUID]struct{}
	removedworkflow_contracts        map[uuid.UUID]struct{}
	clearedworkflow_contracts        bool
	workflows                        map[uuid.UUID]struct{}
	removedworkflows                 map[uuid.UUID]struct{}
	clearedworkflows                 bool
	cas_backends                     map[uuid.UUID]struct{}
	removedcas_backends              map[uuid.UUID]struct{}
	clearedcas_backends              bool
	integrations                     map[uuid.UUID]struct{}
	removedintegrations              map[uuid.UUID]struct{}
	clearedintegrations              bool
	api_tokens                       map[uuid.UUID]struct{}
	removedapi_tokens                map[uuid.UUID]struct{}
	clearedapi_tokens                bool
	projects                         map[uuid.UUID]struct{}
	removedprojects                  map[uuid.UUID]struct{}
	clearedprojects                  bool
	groups                           map[uuid.UUID]struct{}
	removedgroups                    map[uuid.UUID]struct{}
	clearedgroups                    bool
	done                             bool
	oldValue                         func(context.Context) (*Organization, error)
	predicates                       []predicate.Organization
}

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

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

// newOrganizationMutation creates new mutation for the Organization entity.
func newOrganizationMutation(c config, op Op, opts ...organizationOption) *OrganizationMutation {
	m := &OrganizationMutation{
		config:        c,
		op:            op,
		typ:           TypeOrganization,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *OrganizationMutation) 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 Organization entity.
// If the Organization 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 *OrganizationMutation) 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 *OrganizationMutation) ResetName() {
	m.name = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *OrganizationMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *OrganizationMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[organization.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *OrganizationMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[organization.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *OrganizationMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, organization.FieldDeletedAt)
}

// SetBlockOnPolicyViolation sets the "block_on_policy_violation" field.
func (m *OrganizationMutation) SetBlockOnPolicyViolation(b bool) {
	m.block_on_policy_violation = &b
}

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

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

// ResetBlockOnPolicyViolation resets all changes to the "block_on_policy_violation" field.
func (m *OrganizationMutation) ResetBlockOnPolicyViolation() {
	m.block_on_policy_violation = nil
}

// SetPoliciesAllowedHostnames sets the "policies_allowed_hostnames" field.
func (m *OrganizationMutation) SetPoliciesAllowedHostnames(s []string) {
	m.policies_allowed_hostnames = &s
	m.appendpolicies_allowed_hostnames = nil
}

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

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

// AppendPoliciesAllowedHostnames adds s to the "policies_allowed_hostnames" field.
func (m *OrganizationMutation) AppendPoliciesAllowedHostnames(s []string) {
	m.appendpolicies_allowed_hostnames = append(m.appendpolicies_allowed_hostnames, s...)
}

// AppendedPoliciesAllowedHostnames returns the list of values that were appended to the "policies_allowed_hostnames" field in this mutation.
func (m *OrganizationMutation) AppendedPoliciesAllowedHostnames() ([]string, bool) {
	if len(m.appendpolicies_allowed_hostnames) == 0 {
		return nil, false
	}
	return m.appendpolicies_allowed_hostnames, true
}

// ClearPoliciesAllowedHostnames clears the value of the "policies_allowed_hostnames" field.
func (m *OrganizationMutation) ClearPoliciesAllowedHostnames() {
	m.policies_allowed_hostnames = nil
	m.appendpolicies_allowed_hostnames = nil
	m.clearedFields[organization.FieldPoliciesAllowedHostnames] = struct{}{}
}

// PoliciesAllowedHostnamesCleared returns if the "policies_allowed_hostnames" field was cleared in this mutation.
func (m *OrganizationMutation) PoliciesAllowedHostnamesCleared() bool {
	_, ok := m.clearedFields[organization.FieldPoliciesAllowedHostnames]
	return ok
}

// ResetPoliciesAllowedHostnames resets all changes to the "policies_allowed_hostnames" field.
func (m *OrganizationMutation) ResetPoliciesAllowedHostnames() {
	m.policies_allowed_hostnames = nil
	m.appendpolicies_allowed_hostnames = nil
	delete(m.clearedFields, organization.FieldPoliciesAllowedHostnames)
}

// AddMembershipIDs adds the "memberships" edge to the Membership entity by ids.
func (m *OrganizationMutation) AddMembershipIDs(ids ...uuid.UUID) {
	if m.memberships == nil {
		m.memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.memberships[ids[i]] = struct{}{}
	}
}

// ClearMemberships clears the "memberships" edge to the Membership entity.
func (m *OrganizationMutation) ClearMemberships() {
	m.clearedmemberships = true
}

// MembershipsCleared reports if the "memberships" edge to the Membership entity was cleared.
func (m *OrganizationMutation) MembershipsCleared() bool {
	return m.clearedmemberships
}

// RemoveMembershipIDs removes the "memberships" edge to the Membership entity by IDs.
func (m *OrganizationMutation) RemoveMembershipIDs(ids ...uuid.UUID) {
	if m.removedmemberships == nil {
		m.removedmemberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.memberships, ids[i])
		m.removedmemberships[ids[i]] = struct{}{}
	}
}

// RemovedMemberships returns the removed IDs of the "memberships" edge to the Membership entity.
func (m *OrganizationMutation) RemovedMembershipsIDs() (ids []uuid.UUID) {
	for id := range m.removedmemberships {
		ids = append(ids, id)
	}
	return
}

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

// ResetMemberships resets all changes to the "memberships" edge.
func (m *OrganizationMutation) ResetMemberships() {
	m.memberships = nil
	m.clearedmemberships = false
	m.removedmemberships = nil
}

// AddWorkflowContractIDs adds the "workflow_contracts" edge to the WorkflowContract entity by ids.
func (m *OrganizationMutation) AddWorkflowContractIDs(ids ...uuid.UUID) {
	if m.workflow_contracts == nil {
		m.workflow_contracts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflow_contracts[ids[i]] = struct{}{}
	}
}

// ClearWorkflowContracts clears the "workflow_contracts" edge to the WorkflowContract entity.
func (m *OrganizationMutation) ClearWorkflowContracts() {
	m.clearedworkflow_contracts = true
}

// WorkflowContractsCleared reports if the "workflow_contracts" edge to the WorkflowContract entity was cleared.
func (m *OrganizationMutation) WorkflowContractsCleared() bool {
	return m.clearedworkflow_contracts
}

// RemoveWorkflowContractIDs removes the "workflow_contracts" edge to the WorkflowContract entity by IDs.
func (m *OrganizationMutation) RemoveWorkflowContractIDs(ids ...uuid.UUID) {
	if m.removedworkflow_contracts == nil {
		m.removedworkflow_contracts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflow_contracts, ids[i])
		m.removedworkflow_contracts[ids[i]] = struct{}{}
	}
}

// RemovedWorkflowContracts returns the removed IDs of the "workflow_contracts" edge to the WorkflowContract entity.
func (m *OrganizationMutation) RemovedWorkflowContractsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflow_contracts {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflowContracts resets all changes to the "workflow_contracts" edge.
func (m *OrganizationMutation) ResetWorkflowContracts() {
	m.workflow_contracts = nil
	m.clearedworkflow_contracts = false
	m.removedworkflow_contracts = nil
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by ids.
func (m *OrganizationMutation) AddWorkflowIDs(ids ...uuid.UUID) {
	if m.workflows == nil {
		m.workflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflows[ids[i]] = struct{}{}
	}
}

// ClearWorkflows clears the "workflows" edge to the Workflow entity.
func (m *OrganizationMutation) ClearWorkflows() {
	m.clearedworkflows = true
}

// WorkflowsCleared reports if the "workflows" edge to the Workflow entity was cleared.
func (m *OrganizationMutation) WorkflowsCleared() bool {
	return m.clearedworkflows
}

// RemoveWorkflowIDs removes the "workflows" edge to the Workflow entity by IDs.
func (m *OrganizationMutation) RemoveWorkflowIDs(ids ...uuid.UUID) {
	if m.removedworkflows == nil {
		m.removedworkflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflows, ids[i])
		m.removedworkflows[ids[i]] = struct{}{}
	}
}

// RemovedWorkflows returns the removed IDs of the "workflows" edge to the Workflow entity.
func (m *OrganizationMutation) RemovedWorkflowsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflows {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflows resets all changes to the "workflows" edge.
func (m *OrganizationMutation) ResetWorkflows() {
	m.workflows = nil
	m.clearedworkflows = false
	m.removedworkflows = nil
}

// AddCasBackendIDs adds the "cas_backends" edge to the CASBackend entity by ids.
func (m *OrganizationMutation) AddCasBackendIDs(ids ...uuid.UUID) {
	if m.cas_backends == nil {
		m.cas_backends = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.cas_backends[ids[i]] = struct{}{}
	}
}

// ClearCasBackends clears the "cas_backends" edge to the CASBackend entity.
func (m *OrganizationMutation) ClearCasBackends() {
	m.clearedcas_backends = true
}

// CasBackendsCleared reports if the "cas_backends" edge to the CASBackend entity was cleared.
func (m *OrganizationMutation) CasBackendsCleared() bool {
	return m.clearedcas_backends
}

// RemoveCasBackendIDs removes the "cas_backends" edge to the CASBackend entity by IDs.
func (m *OrganizationMutation) RemoveCasBackendIDs(ids ...uuid.UUID) {
	if m.removedcas_backends == nil {
		m.removedcas_backends = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.cas_backends, ids[i])
		m.removedcas_backends[ids[i]] = struct{}{}
	}
}

// RemovedCasBackends returns the removed IDs of the "cas_backends" edge to the CASBackend entity.
func (m *OrganizationMutation) RemovedCasBackendsIDs() (ids []uuid.UUID) {
	for id := range m.removedcas_backends {
		ids = append(ids, id)
	}
	return
}

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

// ResetCasBackends resets all changes to the "cas_backends" edge.
func (m *OrganizationMutation) ResetCasBackends() {
	m.cas_backends = nil
	m.clearedcas_backends = false
	m.removedcas_backends = nil
}

// AddIntegrationIDs adds the "integrations" edge to the Integration entity by ids.
func (m *OrganizationMutation) AddIntegrationIDs(ids ...uuid.UUID) {
	if m.integrations == nil {
		m.integrations = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.integrations[ids[i]] = struct{}{}
	}
}

// ClearIntegrations clears the "integrations" edge to the Integration entity.
func (m *OrganizationMutation) ClearIntegrations() {
	m.clearedintegrations = true
}

// IntegrationsCleared reports if the "integrations" edge to the Integration entity was cleared.
func (m *OrganizationMutation) IntegrationsCleared() bool {
	return m.clearedintegrations
}

// RemoveIntegrationIDs removes the "integrations" edge to the Integration entity by IDs.
func (m *OrganizationMutation) RemoveIntegrationIDs(ids ...uuid.UUID) {
	if m.removedintegrations == nil {
		m.removedintegrations = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.integrations, ids[i])
		m.removedintegrations[ids[i]] = struct{}{}
	}
}

// RemovedIntegrations returns the removed IDs of the "integrations" edge to the Integration entity.
func (m *OrganizationMutation) RemovedIntegrationsIDs() (ids []uuid.UUID) {
	for id := range m.removedintegrations {
		ids = append(ids, id)
	}
	return
}

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

// ResetIntegrations resets all changes to the "integrations" edge.
func (m *OrganizationMutation) ResetIntegrations() {
	m.integrations = nil
	m.clearedintegrations = false
	m.removedintegrations = nil
}

// AddAPITokenIDs adds the "api_tokens" edge to the APIToken entity by ids.
func (m *OrganizationMutation) AddAPITokenIDs(ids ...uuid.UUID) {
	if m.api_tokens == nil {
		m.api_tokens = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.api_tokens[ids[i]] = struct{}{}
	}
}

// ClearAPITokens clears the "api_tokens" edge to the APIToken entity.
func (m *OrganizationMutation) ClearAPITokens() {
	m.clearedapi_tokens = true
}

// APITokensCleared reports if the "api_tokens" edge to the APIToken entity was cleared.
func (m *OrganizationMutation) APITokensCleared() bool {
	return m.clearedapi_tokens
}

// RemoveAPITokenIDs removes the "api_tokens" edge to the APIToken entity by IDs.
func (m *OrganizationMutation) RemoveAPITokenIDs(ids ...uuid.UUID) {
	if m.removedapi_tokens == nil {
		m.removedapi_tokens = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.api_tokens, ids[i])
		m.removedapi_tokens[ids[i]] = struct{}{}
	}
}

// RemovedAPITokens returns the removed IDs of the "api_tokens" edge to the APIToken entity.
func (m *OrganizationMutation) RemovedAPITokensIDs() (ids []uuid.UUID) {
	for id := range m.removedapi_tokens {
		ids = append(ids, id)
	}
	return
}

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

// ResetAPITokens resets all changes to the "api_tokens" edge.
func (m *OrganizationMutation) ResetAPITokens() {
	m.api_tokens = nil
	m.clearedapi_tokens = false
	m.removedapi_tokens = nil
}

// AddProjectIDs adds the "projects" edge to the Project entity by ids.
func (m *OrganizationMutation) AddProjectIDs(ids ...uuid.UUID) {
	if m.projects == nil {
		m.projects = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.projects[ids[i]] = struct{}{}
	}
}

// ClearProjects clears the "projects" edge to the Project entity.
func (m *OrganizationMutation) ClearProjects() {
	m.clearedprojects = true
}

// ProjectsCleared reports if the "projects" edge to the Project entity was cleared.
func (m *OrganizationMutation) ProjectsCleared() bool {
	return m.clearedprojects
}

// RemoveProjectIDs removes the "projects" edge to the Project entity by IDs.
func (m *OrganizationMutation) RemoveProjectIDs(ids ...uuid.UUID) {
	if m.removedprojects == nil {
		m.removedprojects = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.projects, ids[i])
		m.removedprojects[ids[i]] = struct{}{}
	}
}

// RemovedProjects returns the removed IDs of the "projects" edge to the Project entity.
func (m *OrganizationMutation) RemovedProjectsIDs() (ids []uuid.UUID) {
	for id := range m.removedprojects {
		ids = append(ids, id)
	}
	return
}

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

// ResetProjects resets all changes to the "projects" edge.
func (m *OrganizationMutation) ResetProjects() {
	m.projects = nil
	m.clearedprojects = false
	m.removedprojects = nil
}

// AddGroupIDs adds the "groups" edge to the Group entity by ids.
func (m *OrganizationMutation) AddGroupIDs(ids ...uuid.UUID) {
	if m.groups == nil {
		m.groups = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.groups[ids[i]] = struct{}{}
	}
}

// ClearGroups clears the "groups" edge to the Group entity.
func (m *OrganizationMutation) ClearGroups() {
	m.clearedgroups = true
}

// GroupsCleared reports if the "groups" edge to the Group entity was cleared.
func (m *OrganizationMutation) GroupsCleared() bool {
	return m.clearedgroups
}

// RemoveGroupIDs removes the "groups" edge to the Group entity by IDs.
func (m *OrganizationMutation) RemoveGroupIDs(ids ...uuid.UUID) {
	if m.removedgroups == nil {
		m.removedgroups = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.groups, ids[i])
		m.removedgroups[ids[i]] = struct{}{}
	}
}

// RemovedGroups returns the removed IDs of the "groups" edge to the Group entity.
func (m *OrganizationMutation) RemovedGroupsIDs() (ids []uuid.UUID) {
	for id := range m.removedgroups {
		ids = append(ids, id)
	}
	return
}

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

// ResetGroups resets all changes to the "groups" edge.
func (m *OrganizationMutation) ResetGroups() {
	m.groups = nil
	m.clearedgroups = false
	m.removedgroups = nil
}

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

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

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

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

// Type returns the node type of this mutation (Organization).
func (m *OrganizationMutation) 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 *OrganizationMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.name != nil {
		fields = append(fields, organization.FieldName)
	}
	if m.created_at != nil {
		fields = append(fields, organization.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, organization.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, organization.FieldDeletedAt)
	}
	if m.block_on_policy_violation != nil {
		fields = append(fields, organization.FieldBlockOnPolicyViolation)
	}
	if m.policies_allowed_hostnames != nil {
		fields = append(fields, organization.FieldPoliciesAllowedHostnames)
	}
	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 *OrganizationMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case organization.FieldName:
		return m.Name()
	case organization.FieldCreatedAt:
		return m.CreatedAt()
	case organization.FieldUpdatedAt:
		return m.UpdatedAt()
	case organization.FieldDeletedAt:
		return m.DeletedAt()
	case organization.FieldBlockOnPolicyViolation:
		return m.BlockOnPolicyViolation()
	case organization.FieldPoliciesAllowedHostnames:
		return m.PoliciesAllowedHostnames()
	}
	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 *OrganizationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case organization.FieldName:
		return m.OldName(ctx)
	case organization.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case organization.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case organization.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case organization.FieldBlockOnPolicyViolation:
		return m.OldBlockOnPolicyViolation(ctx)
	case organization.FieldPoliciesAllowedHostnames:
		return m.OldPoliciesAllowedHostnames(ctx)
	}
	return nil, fmt.Errorf("unknown Organization 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 *OrganizationMutation) SetField(name string, value ent.Value) error {
	switch name {
	case organization.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case organization.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case organization.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case organization.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case organization.FieldBlockOnPolicyViolation:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBlockOnPolicyViolation(v)
		return nil
	case organization.FieldPoliciesAllowedHostnames:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPoliciesAllowedHostnames(v)
		return nil
	}
	return fmt.Errorf("unknown Organization field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *OrganizationMutation) 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 *OrganizationMutation) ClearField(name string) error {
	switch name {
	case organization.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case organization.FieldPoliciesAllowedHostnames:
		m.ClearPoliciesAllowedHostnames()
		return nil
	}
	return fmt.Errorf("unknown Organization 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 *OrganizationMutation) ResetField(name string) error {
	switch name {
	case organization.FieldName:
		m.ResetName()
		return nil
	case organization.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case organization.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case organization.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case organization.FieldBlockOnPolicyViolation:
		m.ResetBlockOnPolicyViolation()
		return nil
	case organization.FieldPoliciesAllowedHostnames:
		m.ResetPoliciesAllowedHostnames()
		return nil
	}
	return fmt.Errorf("unknown Organization field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *OrganizationMutation) AddedEdges() []string {
	edges := make([]string, 0, 8)
	if m.memberships != nil {
		edges = append(edges, organization.EdgeMemberships)
	}
	if m.workflow_contracts != nil {
		edges = append(edges, organization.EdgeWorkflowContracts)
	}
	if m.workflows != nil {
		edges = append(edges, organization.EdgeWorkflows)
	}
	if m.cas_backends != nil {
		edges = append(edges, organization.EdgeCasBackends)
	}
	if m.integrations != nil {
		edges = append(edges, organization.EdgeIntegrations)
	}
	if m.api_tokens != nil {
		edges = append(edges, organization.EdgeAPITokens)
	}
	if m.projects != nil {
		edges = append(edges, organization.EdgeProjects)
	}
	if m.groups != nil {
		edges = append(edges, organization.EdgeGroups)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *OrganizationMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case organization.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.memberships))
		for id := range m.memberships {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeWorkflowContracts:
		ids := make([]ent.Value, 0, len(m.workflow_contracts))
		for id := range m.workflow_contracts {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.workflows))
		for id := range m.workflows {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeCasBackends:
		ids := make([]ent.Value, 0, len(m.cas_backends))
		for id := range m.cas_backends {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeIntegrations:
		ids := make([]ent.Value, 0, len(m.integrations))
		for id := range m.integrations {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeAPITokens:
		ids := make([]ent.Value, 0, len(m.api_tokens))
		for id := range m.api_tokens {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeProjects:
		ids := make([]ent.Value, 0, len(m.projects))
		for id := range m.projects {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeGroups:
		ids := make([]ent.Value, 0, len(m.groups))
		for id := range m.groups {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *OrganizationMutation) RemovedEdges() []string {
	edges := make([]string, 0, 8)
	if m.removedmemberships != nil {
		edges = append(edges, organization.EdgeMemberships)
	}
	if m.removedworkflow_contracts != nil {
		edges = append(edges, organization.EdgeWorkflowContracts)
	}
	if m.removedworkflows != nil {
		edges = append(edges, organization.EdgeWorkflows)
	}
	if m.removedcas_backends != nil {
		edges = append(edges, organization.EdgeCasBackends)
	}
	if m.removedintegrations != nil {
		edges = append(edges, organization.EdgeIntegrations)
	}
	if m.removedapi_tokens != nil {
		edges = append(edges, organization.EdgeAPITokens)
	}
	if m.removedprojects != nil {
		edges = append(edges, organization.EdgeProjects)
	}
	if m.removedgroups != nil {
		edges = append(edges, organization.EdgeGroups)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *OrganizationMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case organization.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.removedmemberships))
		for id := range m.removedmemberships {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeWorkflowContracts:
		ids := make([]ent.Value, 0, len(m.removedworkflow_contracts))
		for id := range m.removedworkflow_contracts {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.removedworkflows))
		for id := range m.removedworkflows {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeCasBackends:
		ids := make([]ent.Value, 0, len(m.removedcas_backends))
		for id := range m.removedcas_backends {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeIntegrations:
		ids := make([]ent.Value, 0, len(m.removedintegrations))
		for id := range m.removedintegrations {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeAPITokens:
		ids := make([]ent.Value, 0, len(m.removedapi_tokens))
		for id := range m.removedapi_tokens {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeProjects:
		ids := make([]ent.Value, 0, len(m.removedprojects))
		for id := range m.removedprojects {
			ids = append(ids, id)
		}
		return ids
	case organization.EdgeGroups:
		ids := make([]ent.Value, 0, len(m.removedgroups))
		for id := range m.removedgroups {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *OrganizationMutation) ClearedEdges() []string {
	edges := make([]string, 0, 8)
	if m.clearedmemberships {
		edges = append(edges, organization.EdgeMemberships)
	}
	if m.clearedworkflow_contracts {
		edges = append(edges, organization.EdgeWorkflowContracts)
	}
	if m.clearedworkflows {
		edges = append(edges, organization.EdgeWorkflows)
	}
	if m.clearedcas_backends {
		edges = append(edges, organization.EdgeCasBackends)
	}
	if m.clearedintegrations {
		edges = append(edges, organization.EdgeIntegrations)
	}
	if m.clearedapi_tokens {
		edges = append(edges, organization.EdgeAPITokens)
	}
	if m.clearedprojects {
		edges = append(edges, organization.EdgeProjects)
	}
	if m.clearedgroups {
		edges = append(edges, organization.EdgeGroups)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *OrganizationMutation) EdgeCleared(name string) bool {
	switch name {
	case organization.EdgeMemberships:
		return m.clearedmemberships
	case organization.EdgeWorkflowContracts:
		return m.clearedworkflow_contracts
	case organization.EdgeWorkflows:
		return m.clearedworkflows
	case organization.EdgeCasBackends:
		return m.clearedcas_backends
	case organization.EdgeIntegrations:
		return m.clearedintegrations
	case organization.EdgeAPITokens:
		return m.clearedapi_tokens
	case organization.EdgeProjects:
		return m.clearedprojects
	case organization.EdgeGroups:
		return m.clearedgroups
	}
	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 *OrganizationMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Organization 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 *OrganizationMutation) ResetEdge(name string) error {
	switch name {
	case organization.EdgeMemberships:
		m.ResetMemberships()
		return nil
	case organization.EdgeWorkflowContracts:
		m.ResetWorkflowContracts()
		return nil
	case organization.EdgeWorkflows:
		m.ResetWorkflows()
		return nil
	case organization.EdgeCasBackends:
		m.ResetCasBackends()
		return nil
	case organization.EdgeIntegrations:
		m.ResetIntegrations()
		return nil
	case organization.EdgeAPITokens:
		m.ResetAPITokens()
		return nil
	case organization.EdgeProjects:
		m.ResetProjects()
		return nil
	case organization.EdgeGroups:
		m.ResetGroups()
		return nil
	}
	return fmt.Errorf("unknown Organization edge %s", name)
}

// ProjectMutation represents an operation that mutates the Project nodes in the graph.
type ProjectMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uuid.UUID
	name                *string
	description         *string
	created_at          *time.Time
	updated_at          *time.Time
	deleted_at          *time.Time
	clearedFields       map[string]struct{}
	organization        *uuid.UUID
	clearedorganization bool
	workflows           map[uuid.UUID]struct{}
	removedworkflows    map[uuid.UUID]struct{}
	clearedworkflows    bool
	versions            map[uuid.UUID]struct{}
	removedversions     map[uuid.UUID]struct{}
	clearedversions     bool
	done                bool
	oldValue            func(context.Context) (*Project, error)
	predicates          []predicate.Project
}

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

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

// newProjectMutation creates new mutation for the Project entity.
func newProjectMutation(c config, op Op, opts ...projectOption) *ProjectMutation {
	m := &ProjectMutation{
		config:        c,
		op:            op,
		typ:           TypeProject,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *ProjectMutation) 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 Project entity.
// If the Project 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 *ProjectMutation) 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 *ProjectMutation) ResetName() {
	m.name = nil
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *ProjectMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *ProjectMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[project.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *ProjectMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[project.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *ProjectMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, project.FieldDeletedAt)
}

// SetOrganizationID sets the "organization_id" field.
func (m *ProjectMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *ProjectMutation) ResetOrganizationID() {
	m.organization = nil
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *ProjectMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[project.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *ProjectMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *ProjectMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by ids.
func (m *ProjectMutation) AddWorkflowIDs(ids ...uuid.UUID) {
	if m.workflows == nil {
		m.workflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflows[ids[i]] = struct{}{}
	}
}

// ClearWorkflows clears the "workflows" edge to the Workflow entity.
func (m *ProjectMutation) ClearWorkflows() {
	m.clearedworkflows = true
}

// WorkflowsCleared reports if the "workflows" edge to the Workflow entity was cleared.
func (m *ProjectMutation) WorkflowsCleared() bool {
	return m.clearedworkflows
}

// RemoveWorkflowIDs removes the "workflows" edge to the Workflow entity by IDs.
func (m *ProjectMutation) RemoveWorkflowIDs(ids ...uuid.UUID) {
	if m.removedworkflows == nil {
		m.removedworkflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflows, ids[i])
		m.removedworkflows[ids[i]] = struct{}{}
	}
}

// RemovedWorkflows returns the removed IDs of the "workflows" edge to the Workflow entity.
func (m *ProjectMutation) RemovedWorkflowsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflows {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflows resets all changes to the "workflows" edge.
func (m *ProjectMutation) ResetWorkflows() {
	m.workflows = nil
	m.clearedworkflows = false
	m.removedworkflows = nil
}

// AddVersionIDs adds the "versions" edge to the ProjectVersion entity by ids.
func (m *ProjectMutation) AddVersionIDs(ids ...uuid.UUID) {
	if m.versions == nil {
		m.versions = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.versions[ids[i]] = struct{}{}
	}
}

// ClearVersions clears the "versions" edge to the ProjectVersion entity.
func (m *ProjectMutation) ClearVersions() {
	m.clearedversions = true
}

// VersionsCleared reports if the "versions" edge to the ProjectVersion entity was cleared.
func (m *ProjectMutation) VersionsCleared() bool {
	return m.clearedversions
}

// RemoveVersionIDs removes the "versions" edge to the ProjectVersion entity by IDs.
func (m *ProjectMutation) RemoveVersionIDs(ids ...uuid.UUID) {
	if m.removedversions == nil {
		m.removedversions = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.versions, ids[i])
		m.removedversions[ids[i]] = struct{}{}
	}
}

// RemovedVersions returns the removed IDs of the "versions" edge to the ProjectVersion entity.
func (m *ProjectMutation) RemovedVersionsIDs() (ids []uuid.UUID) {
	for id := range m.removedversions {
		ids = append(ids, id)
	}
	return
}

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

// ResetVersions resets all changes to the "versions" edge.
func (m *ProjectMutation) ResetVersions() {
	m.versions = nil
	m.clearedversions = false
	m.removedversions = nil
}

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

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

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

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

// Type returns the node type of this mutation (Project).
func (m *ProjectMutation) 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 *ProjectMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.name != nil {
		fields = append(fields, project.FieldName)
	}
	if m.description != nil {
		fields = append(fields, project.FieldDescription)
	}
	if m.created_at != nil {
		fields = append(fields, project.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, project.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, project.FieldDeletedAt)
	}
	if m.organization != nil {
		fields = append(fields, project.FieldOrganizationID)
	}
	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 *ProjectMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case project.FieldName:
		return m.Name()
	case project.FieldDescription:
		return m.Description()
	case project.FieldCreatedAt:
		return m.CreatedAt()
	case project.FieldUpdatedAt:
		return m.UpdatedAt()
	case project.FieldDeletedAt:
		return m.DeletedAt()
	case project.FieldOrganizationID:
		return m.OrganizationID()
	}
	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 *ProjectMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case project.FieldName:
		return m.OldName(ctx)
	case project.FieldDescription:
		return m.OldDescription(ctx)
	case project.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case project.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case project.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case project.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	}
	return nil, fmt.Errorf("unknown Project 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 *ProjectMutation) SetField(name string, value ent.Value) error {
	switch name {
	case project.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case project.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case project.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case project.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case project.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case project.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	}
	return fmt.Errorf("unknown Project field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ProjectMutation) 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 *ProjectMutation) ClearField(name string) error {
	switch name {
	case project.FieldDescription:
		m.ClearDescription()
		return nil
	case project.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown Project 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 *ProjectMutation) ResetField(name string) error {
	switch name {
	case project.FieldName:
		m.ResetName()
		return nil
	case project.FieldDescription:
		m.ResetDescription()
		return nil
	case project.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case project.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case project.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case project.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	}
	return fmt.Errorf("unknown Project field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ProjectMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.organization != nil {
		edges = append(edges, project.EdgeOrganization)
	}
	if m.workflows != nil {
		edges = append(edges, project.EdgeWorkflows)
	}
	if m.versions != nil {
		edges = append(edges, project.EdgeVersions)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ProjectMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case project.EdgeOrganization:
		if id := m.organization; id != nil {
			return []ent.Value{*id}
		}
	case project.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.workflows))
		for id := range m.workflows {
			ids = append(ids, id)
		}
		return ids
	case project.EdgeVersions:
		ids := make([]ent.Value, 0, len(m.versions))
		for id := range m.versions {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ProjectMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedworkflows != nil {
		edges = append(edges, project.EdgeWorkflows)
	}
	if m.removedversions != nil {
		edges = append(edges, project.EdgeVersions)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ProjectMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedorganization {
		edges = append(edges, project.EdgeOrganization)
	}
	if m.clearedworkflows {
		edges = append(edges, project.EdgeWorkflows)
	}
	if m.clearedversions {
		edges = append(edges, project.EdgeVersions)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ProjectMutation) EdgeCleared(name string) bool {
	switch name {
	case project.EdgeOrganization:
		return m.clearedorganization
	case project.EdgeWorkflows:
		return m.clearedworkflows
	case project.EdgeVersions:
		return m.clearedversions
	}
	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 *ProjectMutation) ClearEdge(name string) error {
	switch name {
	case project.EdgeOrganization:
		m.ClearOrganization()
		return nil
	}
	return fmt.Errorf("unknown Project 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 *ProjectMutation) ResetEdge(name string) error {
	switch name {
	case project.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case project.EdgeWorkflows:
		m.ResetWorkflows()
		return nil
	case project.EdgeVersions:
		m.ResetVersions()
		return nil
	}
	return fmt.Errorf("unknown Project edge %s", name)
}

// ProjectVersionMutation represents an operation that mutates the ProjectVersion nodes in the graph.
type ProjectVersionMutation struct {
	config
	op                    Op
	typ                   string
	id                    *uuid.UUID
	version               *string
	created_at            *time.Time
	updated_at            *time.Time
	deleted_at            *time.Time
	prerelease            *bool
	workflow_run_count    *int
	addworkflow_run_count *int
	released_at           *time.Time
	last_run_at           *time.Time
	latest                *bool
	clearedFields         map[string]struct{}
	project               *uuid.UUID
	clearedproject        bool
	runs                  map[uuid.UUID]struct{}
	removedruns           map[uuid.UUID]struct{}
	clearedruns           bool
	done                  bool
	oldValue              func(context.Context) (*ProjectVersion, error)
	predicates            []predicate.ProjectVersion
}

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

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

// newProjectVersionMutation creates new mutation for the ProjectVersion entity.
func newProjectVersionMutation(c config, op Op, opts ...projectversionOption) *ProjectVersionMutation {
	m := &ProjectVersionMutation{
		config:        c,
		op:            op,
		typ:           TypeProjectVersion,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Version returns the value of the "version" field in the mutation.
func (m *ProjectVersionMutation) 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 ProjectVersion entity.
// If the ProjectVersion 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 *ProjectVersionMutation) 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 *ProjectVersionMutation) ResetVersion() {
	m.version = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *ProjectVersionMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *ProjectVersionMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[projectversion.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *ProjectVersionMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[projectversion.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *ProjectVersionMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, projectversion.FieldDeletedAt)
}

// SetProjectID sets the "project_id" field.
func (m *ProjectVersionMutation) SetProjectID(u uuid.UUID) {
	m.project = &u
}

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

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

// ResetProjectID resets all changes to the "project_id" field.
func (m *ProjectVersionMutation) ResetProjectID() {
	m.project = nil
}

// SetPrerelease sets the "prerelease" field.
func (m *ProjectVersionMutation) SetPrerelease(b bool) {
	m.prerelease = &b
}

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

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

// ResetPrerelease resets all changes to the "prerelease" field.
func (m *ProjectVersionMutation) ResetPrerelease() {
	m.prerelease = nil
}

// SetWorkflowRunCount sets the "workflow_run_count" field.
func (m *ProjectVersionMutation) SetWorkflowRunCount(i int) {
	m.workflow_run_count = &i
	m.addworkflow_run_count = nil
}

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

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

// AddWorkflowRunCount adds i to the "workflow_run_count" field.
func (m *ProjectVersionMutation) AddWorkflowRunCount(i int) {
	if m.addworkflow_run_count != nil {
		*m.addworkflow_run_count += i
	} else {
		m.addworkflow_run_count = &i
	}
}

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

// ResetWorkflowRunCount resets all changes to the "workflow_run_count" field.
func (m *ProjectVersionMutation) ResetWorkflowRunCount() {
	m.workflow_run_count = nil
	m.addworkflow_run_count = nil
}

// SetReleasedAt sets the "released_at" field.
func (m *ProjectVersionMutation) SetReleasedAt(t time.Time) {
	m.released_at = &t
}

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

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

// ClearReleasedAt clears the value of the "released_at" field.
func (m *ProjectVersionMutation) ClearReleasedAt() {
	m.released_at = nil
	m.clearedFields[projectversion.FieldReleasedAt] = struct{}{}
}

// ReleasedAtCleared returns if the "released_at" field was cleared in this mutation.
func (m *ProjectVersionMutation) ReleasedAtCleared() bool {
	_, ok := m.clearedFields[projectversion.FieldReleasedAt]
	return ok
}

// ResetReleasedAt resets all changes to the "released_at" field.
func (m *ProjectVersionMutation) ResetReleasedAt() {
	m.released_at = nil
	delete(m.clearedFields, projectversion.FieldReleasedAt)
}

// SetLastRunAt sets the "last_run_at" field.
func (m *ProjectVersionMutation) SetLastRunAt(t time.Time) {
	m.last_run_at = &t
}

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

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

// ClearLastRunAt clears the value of the "last_run_at" field.
func (m *ProjectVersionMutation) ClearLastRunAt() {
	m.last_run_at = nil
	m.clearedFields[projectversion.FieldLastRunAt] = struct{}{}
}

// LastRunAtCleared returns if the "last_run_at" field was cleared in this mutation.
func (m *ProjectVersionMutation) LastRunAtCleared() bool {
	_, ok := m.clearedFields[projectversion.FieldLastRunAt]
	return ok
}

// ResetLastRunAt resets all changes to the "last_run_at" field.
func (m *ProjectVersionMutation) ResetLastRunAt() {
	m.last_run_at = nil
	delete(m.clearedFields, projectversion.FieldLastRunAt)
}

// SetLatest sets the "latest" field.
func (m *ProjectVersionMutation) SetLatest(b bool) {
	m.latest = &b
}

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

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

// ResetLatest resets all changes to the "latest" field.
func (m *ProjectVersionMutation) ResetLatest() {
	m.latest = nil
}

// ClearProject clears the "project" edge to the Project entity.
func (m *ProjectVersionMutation) ClearProject() {
	m.clearedproject = true
	m.clearedFields[projectversion.FieldProjectID] = struct{}{}
}

// ProjectCleared reports if the "project" edge to the Project entity was cleared.
func (m *ProjectVersionMutation) ProjectCleared() bool {
	return m.clearedproject
}

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

// ResetProject resets all changes to the "project" edge.
func (m *ProjectVersionMutation) ResetProject() {
	m.project = nil
	m.clearedproject = false
}

// AddRunIDs adds the "runs" edge to the WorkflowRun entity by ids.
func (m *ProjectVersionMutation) AddRunIDs(ids ...uuid.UUID) {
	if m.runs == nil {
		m.runs = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.runs[ids[i]] = struct{}{}
	}
}

// ClearRuns clears the "runs" edge to the WorkflowRun entity.
func (m *ProjectVersionMutation) ClearRuns() {
	m.clearedruns = true
}

// RunsCleared reports if the "runs" edge to the WorkflowRun entity was cleared.
func (m *ProjectVersionMutation) RunsCleared() bool {
	return m.clearedruns
}

// RemoveRunIDs removes the "runs" edge to the WorkflowRun entity by IDs.
func (m *ProjectVersionMutation) RemoveRunIDs(ids ...uuid.UUID) {
	if m.removedruns == nil {
		m.removedruns = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.runs, ids[i])
		m.removedruns[ids[i]] = struct{}{}
	}
}

// RemovedRuns returns the removed IDs of the "runs" edge to the WorkflowRun entity.
func (m *ProjectVersionMutation) RemovedRunsIDs() (ids []uuid.UUID) {
	for id := range m.removedruns {
		ids = append(ids, id)
	}
	return
}

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

// ResetRuns resets all changes to the "runs" edge.
func (m *ProjectVersionMutation) ResetRuns() {
	m.runs = nil
	m.clearedruns = false
	m.removedruns = nil
}

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

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

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

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

// Type returns the node type of this mutation (ProjectVersion).
func (m *ProjectVersionMutation) 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 *ProjectVersionMutation) Fields() []string {
	fields := make([]string, 0, 10)
	if m.version != nil {
		fields = append(fields, projectversion.FieldVersion)
	}
	if m.created_at != nil {
		fields = append(fields, projectversion.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, projectversion.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, projectversion.FieldDeletedAt)
	}
	if m.project != nil {
		fields = append(fields, projectversion.FieldProjectID)
	}
	if m.prerelease != nil {
		fields = append(fields, projectversion.FieldPrerelease)
	}
	if m.workflow_run_count != nil {
		fields = append(fields, projectversion.FieldWorkflowRunCount)
	}
	if m.released_at != nil {
		fields = append(fields, projectversion.FieldReleasedAt)
	}
	if m.last_run_at != nil {
		fields = append(fields, projectversion.FieldLastRunAt)
	}
	if m.latest != nil {
		fields = append(fields, projectversion.FieldLatest)
	}
	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 *ProjectVersionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case projectversion.FieldVersion:
		return m.Version()
	case projectversion.FieldCreatedAt:
		return m.CreatedAt()
	case projectversion.FieldUpdatedAt:
		return m.UpdatedAt()
	case projectversion.FieldDeletedAt:
		return m.DeletedAt()
	case projectversion.FieldProjectID:
		return m.ProjectID()
	case projectversion.FieldPrerelease:
		return m.Prerelease()
	case projectversion.FieldWorkflowRunCount:
		return m.WorkflowRunCount()
	case projectversion.FieldReleasedAt:
		return m.ReleasedAt()
	case projectversion.FieldLastRunAt:
		return m.LastRunAt()
	case projectversion.FieldLatest:
		return m.Latest()
	}
	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 *ProjectVersionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case projectversion.FieldVersion:
		return m.OldVersion(ctx)
	case projectversion.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case projectversion.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case projectversion.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case projectversion.FieldProjectID:
		return m.OldProjectID(ctx)
	case projectversion.FieldPrerelease:
		return m.OldPrerelease(ctx)
	case projectversion.FieldWorkflowRunCount:
		return m.OldWorkflowRunCount(ctx)
	case projectversion.FieldReleasedAt:
		return m.OldReleasedAt(ctx)
	case projectversion.FieldLastRunAt:
		return m.OldLastRunAt(ctx)
	case projectversion.FieldLatest:
		return m.OldLatest(ctx)
	}
	return nil, fmt.Errorf("unknown ProjectVersion 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 *ProjectVersionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case projectversion.FieldVersion:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetVersion(v)
		return nil
	case projectversion.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case projectversion.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case projectversion.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case projectversion.FieldProjectID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProjectID(v)
		return nil
	case projectversion.FieldPrerelease:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrerelease(v)
		return nil
	case projectversion.FieldWorkflowRunCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWorkflowRunCount(v)
		return nil
	case projectversion.FieldReleasedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReleasedAt(v)
		return nil
	case projectversion.FieldLastRunAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastRunAt(v)
		return nil
	case projectversion.FieldLatest:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLatest(v)
		return nil
	}
	return fmt.Errorf("unknown ProjectVersion field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ProjectVersionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(projectversion.FieldDeletedAt) {
		fields = append(fields, projectversion.FieldDeletedAt)
	}
	if m.FieldCleared(projectversion.FieldReleasedAt) {
		fields = append(fields, projectversion.FieldReleasedAt)
	}
	if m.FieldCleared(projectversion.FieldLastRunAt) {
		fields = append(fields, projectversion.FieldLastRunAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ProjectVersionMutation) 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 *ProjectVersionMutation) ClearField(name string) error {
	switch name {
	case projectversion.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case projectversion.FieldReleasedAt:
		m.ClearReleasedAt()
		return nil
	case projectversion.FieldLastRunAt:
		m.ClearLastRunAt()
		return nil
	}
	return fmt.Errorf("unknown ProjectVersion 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 *ProjectVersionMutation) ResetField(name string) error {
	switch name {
	case projectversion.FieldVersion:
		m.ResetVersion()
		return nil
	case projectversion.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case projectversion.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case projectversion.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case projectversion.FieldProjectID:
		m.ResetProjectID()
		return nil
	case projectversion.FieldPrerelease:
		m.ResetPrerelease()
		return nil
	case projectversion.FieldWorkflowRunCount:
		m.ResetWorkflowRunCount()
		return nil
	case projectversion.FieldReleasedAt:
		m.ResetReleasedAt()
		return nil
	case projectversion.FieldLastRunAt:
		m.ResetLastRunAt()
		return nil
	case projectversion.FieldLatest:
		m.ResetLatest()
		return nil
	}
	return fmt.Errorf("unknown ProjectVersion field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ProjectVersionMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.project != nil {
		edges = append(edges, projectversion.EdgeProject)
	}
	if m.runs != nil {
		edges = append(edges, projectversion.EdgeRuns)
	}
	return edges
}

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

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

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ProjectVersionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedproject {
		edges = append(edges, projectversion.EdgeProject)
	}
	if m.clearedruns {
		edges = append(edges, projectversion.EdgeRuns)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ProjectVersionMutation) EdgeCleared(name string) bool {
	switch name {
	case projectversion.EdgeProject:
		return m.clearedproject
	case projectversion.EdgeRuns:
		return m.clearedruns
	}
	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 *ProjectVersionMutation) ClearEdge(name string) error {
	switch name {
	case projectversion.EdgeProject:
		m.ClearProject()
		return nil
	}
	return fmt.Errorf("unknown ProjectVersion 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 *ProjectVersionMutation) ResetEdge(name string) error {
	switch name {
	case projectversion.EdgeProject:
		m.ResetProject()
		return nil
	case projectversion.EdgeRuns:
		m.ResetRuns()
		return nil
	}
	return fmt.Errorf("unknown ProjectVersion edge %s", name)
}

// ReferrerMutation represents an operation that mutates the Referrer nodes in the graph.
type ReferrerMutation struct {
	config
	op                 Op
	typ                string
	id                 *uuid.UUID
	digest             *string
	kind               *string
	downloadable       *bool
	created_at         *time.Time
	metadata           *map[string]string
	annotations        *map[string]string
	clearedFields      map[string]struct{}
	referred_by        map[uuid.UUID]struct{}
	removedreferred_by map[uuid.UUID]struct{}
	clearedreferred_by bool
	references         map[uuid.UUID]struct{}
	removedreferences  map[uuid.UUID]struct{}
	clearedreferences  bool
	workflows          map[uuid.UUID]struct{}
	removedworkflows   map[uuid.UUID]struct{}
	clearedworkflows   bool
	done               bool
	oldValue           func(context.Context) (*Referrer, error)
	predicates         []predicate.Referrer
}

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

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

// newReferrerMutation creates new mutation for the Referrer entity.
func newReferrerMutation(c config, op Op, opts ...referrerOption) *ReferrerMutation {
	m := &ReferrerMutation{
		config:        c,
		op:            op,
		typ:           TypeReferrer,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetDigest sets the "digest" field.
func (m *ReferrerMutation) SetDigest(s string) {
	m.digest = &s
}

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

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

// ResetDigest resets all changes to the "digest" field.
func (m *ReferrerMutation) ResetDigest() {
	m.digest = nil
}

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

// Kind returns the value of the "kind" field in the mutation.
func (m *ReferrerMutation) 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 Referrer entity.
// If the Referrer 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 *ReferrerMutation) 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 *ReferrerMutation) ResetKind() {
	m.kind = nil
}

// SetDownloadable sets the "downloadable" field.
func (m *ReferrerMutation) SetDownloadable(b bool) {
	m.downloadable = &b
}

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

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

// ResetDownloadable resets all changes to the "downloadable" field.
func (m *ReferrerMutation) ResetDownloadable() {
	m.downloadable = nil
}

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

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

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

// Metadata returns the value of the "metadata" field in the mutation.
func (m *ReferrerMutation) 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 Referrer entity.
// If the Referrer 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 *ReferrerMutation) 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 *ReferrerMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[referrer.FieldMetadata] = struct{}{}
}

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

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

// SetAnnotations sets the "annotations" field.
func (m *ReferrerMutation) SetAnnotations(value map[string]string) {
	m.annotations = &value
}

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

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

// ClearAnnotations clears the value of the "annotations" field.
func (m *ReferrerMutation) ClearAnnotations() {
	m.annotations = nil
	m.clearedFields[referrer.FieldAnnotations] = struct{}{}
}

// AnnotationsCleared returns if the "annotations" field was cleared in this mutation.
func (m *ReferrerMutation) AnnotationsCleared() bool {
	_, ok := m.clearedFields[referrer.FieldAnnotations]
	return ok
}

// ResetAnnotations resets all changes to the "annotations" field.
func (m *ReferrerMutation) ResetAnnotations() {
	m.annotations = nil
	delete(m.clearedFields, referrer.FieldAnnotations)
}

// AddReferredByIDs adds the "referred_by" edge to the Referrer entity by ids.
func (m *ReferrerMutation) AddReferredByIDs(ids ...uuid.UUID) {
	if m.referred_by == nil {
		m.referred_by = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.referred_by[ids[i]] = struct{}{}
	}
}

// ClearReferredBy clears the "referred_by" edge to the Referrer entity.
func (m *ReferrerMutation) ClearReferredBy() {
	m.clearedreferred_by = true
}

// ReferredByCleared reports if the "referred_by" edge to the Referrer entity was cleared.
func (m *ReferrerMutation) ReferredByCleared() bool {
	return m.clearedreferred_by
}

// RemoveReferredByIDs removes the "referred_by" edge to the Referrer entity by IDs.
func (m *ReferrerMutation) RemoveReferredByIDs(ids ...uuid.UUID) {
	if m.removedreferred_by == nil {
		m.removedreferred_by = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.referred_by, ids[i])
		m.removedreferred_by[ids[i]] = struct{}{}
	}
}

// RemovedReferredBy returns the removed IDs of the "referred_by" edge to the Referrer entity.
func (m *ReferrerMutation) RemovedReferredByIDs() (ids []uuid.UUID) {
	for id := range m.removedreferred_by {
		ids = append(ids, id)
	}
	return
}

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

// ResetReferredBy resets all changes to the "referred_by" edge.
func (m *ReferrerMutation) ResetReferredBy() {
	m.referred_by = nil
	m.clearedreferred_by = false
	m.removedreferred_by = nil
}

// AddReferenceIDs adds the "references" edge to the Referrer entity by ids.
func (m *ReferrerMutation) AddReferenceIDs(ids ...uuid.UUID) {
	if m.references == nil {
		m.references = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.references[ids[i]] = struct{}{}
	}
}

// ClearReferences clears the "references" edge to the Referrer entity.
func (m *ReferrerMutation) ClearReferences() {
	m.clearedreferences = true
}

// ReferencesCleared reports if the "references" edge to the Referrer entity was cleared.
func (m *ReferrerMutation) ReferencesCleared() bool {
	return m.clearedreferences
}

// RemoveReferenceIDs removes the "references" edge to the Referrer entity by IDs.
func (m *ReferrerMutation) RemoveReferenceIDs(ids ...uuid.UUID) {
	if m.removedreferences == nil {
		m.removedreferences = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.references, ids[i])
		m.removedreferences[ids[i]] = struct{}{}
	}
}

// RemovedReferences returns the removed IDs of the "references" edge to the Referrer entity.
func (m *ReferrerMutation) RemovedReferencesIDs() (ids []uuid.UUID) {
	for id := range m.removedreferences {
		ids = append(ids, id)
	}
	return
}

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

// ResetReferences resets all changes to the "references" edge.
func (m *ReferrerMutation) ResetReferences() {
	m.references = nil
	m.clearedreferences = false
	m.removedreferences = nil
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by ids.
func (m *ReferrerMutation) AddWorkflowIDs(ids ...uuid.UUID) {
	if m.workflows == nil {
		m.workflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflows[ids[i]] = struct{}{}
	}
}

// ClearWorkflows clears the "workflows" edge to the Workflow entity.
func (m *ReferrerMutation) ClearWorkflows() {
	m.clearedworkflows = true
}

// WorkflowsCleared reports if the "workflows" edge to the Workflow entity was cleared.
func (m *ReferrerMutation) WorkflowsCleared() bool {
	return m.clearedworkflows
}

// RemoveWorkflowIDs removes the "workflows" edge to the Workflow entity by IDs.
func (m *ReferrerMutation) RemoveWorkflowIDs(ids ...uuid.UUID) {
	if m.removedworkflows == nil {
		m.removedworkflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflows, ids[i])
		m.removedworkflows[ids[i]] = struct{}{}
	}
}

// RemovedWorkflows returns the removed IDs of the "workflows" edge to the Workflow entity.
func (m *ReferrerMutation) RemovedWorkflowsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflows {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflows resets all changes to the "workflows" edge.
func (m *ReferrerMutation) ResetWorkflows() {
	m.workflows = nil
	m.clearedworkflows = false
	m.removedworkflows = nil
}

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

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

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

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

// Type returns the node type of this mutation (Referrer).
func (m *ReferrerMutation) 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 *ReferrerMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.digest != nil {
		fields = append(fields, referrer.FieldDigest)
	}
	if m.kind != nil {
		fields = append(fields, referrer.FieldKind)
	}
	if m.downloadable != nil {
		fields = append(fields, referrer.FieldDownloadable)
	}
	if m.created_at != nil {
		fields = append(fields, referrer.FieldCreatedAt)
	}
	if m.metadata != nil {
		fields = append(fields, referrer.FieldMetadata)
	}
	if m.annotations != nil {
		fields = append(fields, referrer.FieldAnnotations)
	}
	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 *ReferrerMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case referrer.FieldDigest:
		return m.Digest()
	case referrer.FieldKind:
		return m.Kind()
	case referrer.FieldDownloadable:
		return m.Downloadable()
	case referrer.FieldCreatedAt:
		return m.CreatedAt()
	case referrer.FieldMetadata:
		return m.Metadata()
	case referrer.FieldAnnotations:
		return m.Annotations()
	}
	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 *ReferrerMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case referrer.FieldDigest:
		return m.OldDigest(ctx)
	case referrer.FieldKind:
		return m.OldKind(ctx)
	case referrer.FieldDownloadable:
		return m.OldDownloadable(ctx)
	case referrer.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case referrer.FieldMetadata:
		return m.OldMetadata(ctx)
	case referrer.FieldAnnotations:
		return m.OldAnnotations(ctx)
	}
	return nil, fmt.Errorf("unknown Referrer 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 *ReferrerMutation) SetField(name string, value ent.Value) error {
	switch name {
	case referrer.FieldDigest:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDigest(v)
		return nil
	case referrer.FieldKind:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKind(v)
		return nil
	case referrer.FieldDownloadable:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDownloadable(v)
		return nil
	case referrer.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case referrer.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 referrer.FieldAnnotations:
		v, ok := value.(map[string]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAnnotations(v)
		return nil
	}
	return fmt.Errorf("unknown Referrer field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ReferrerMutation) 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 *ReferrerMutation) ClearField(name string) error {
	switch name {
	case referrer.FieldMetadata:
		m.ClearMetadata()
		return nil
	case referrer.FieldAnnotations:
		m.ClearAnnotations()
		return nil
	}
	return fmt.Errorf("unknown Referrer 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 *ReferrerMutation) ResetField(name string) error {
	switch name {
	case referrer.FieldDigest:
		m.ResetDigest()
		return nil
	case referrer.FieldKind:
		m.ResetKind()
		return nil
	case referrer.FieldDownloadable:
		m.ResetDownloadable()
		return nil
	case referrer.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case referrer.FieldMetadata:
		m.ResetMetadata()
		return nil
	case referrer.FieldAnnotations:
		m.ResetAnnotations()
		return nil
	}
	return fmt.Errorf("unknown Referrer field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ReferrerMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.referred_by != nil {
		edges = append(edges, referrer.EdgeReferredBy)
	}
	if m.references != nil {
		edges = append(edges, referrer.EdgeReferences)
	}
	if m.workflows != nil {
		edges = append(edges, referrer.EdgeWorkflows)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ReferrerMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case referrer.EdgeReferredBy:
		ids := make([]ent.Value, 0, len(m.referred_by))
		for id := range m.referred_by {
			ids = append(ids, id)
		}
		return ids
	case referrer.EdgeReferences:
		ids := make([]ent.Value, 0, len(m.references))
		for id := range m.references {
			ids = append(ids, id)
		}
		return ids
	case referrer.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.workflows))
		for id := range m.workflows {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ReferrerMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedreferred_by != nil {
		edges = append(edges, referrer.EdgeReferredBy)
	}
	if m.removedreferences != nil {
		edges = append(edges, referrer.EdgeReferences)
	}
	if m.removedworkflows != nil {
		edges = append(edges, referrer.EdgeWorkflows)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ReferrerMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case referrer.EdgeReferredBy:
		ids := make([]ent.Value, 0, len(m.removedreferred_by))
		for id := range m.removedreferred_by {
			ids = append(ids, id)
		}
		return ids
	case referrer.EdgeReferences:
		ids := make([]ent.Value, 0, len(m.removedreferences))
		for id := range m.removedreferences {
			ids = append(ids, id)
		}
		return ids
	case referrer.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.removedworkflows))
		for id := range m.removedworkflows {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ReferrerMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedreferred_by {
		edges = append(edges, referrer.EdgeReferredBy)
	}
	if m.clearedreferences {
		edges = append(edges, referrer.EdgeReferences)
	}
	if m.clearedworkflows {
		edges = append(edges, referrer.EdgeWorkflows)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ReferrerMutation) EdgeCleared(name string) bool {
	switch name {
	case referrer.EdgeReferredBy:
		return m.clearedreferred_by
	case referrer.EdgeReferences:
		return m.clearedreferences
	case referrer.EdgeWorkflows:
		return m.clearedworkflows
	}
	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 *ReferrerMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Referrer 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 *ReferrerMutation) ResetEdge(name string) error {
	switch name {
	case referrer.EdgeReferredBy:
		m.ResetReferredBy()
		return nil
	case referrer.EdgeReferences:
		m.ResetReferences()
		return nil
	case referrer.EdgeWorkflows:
		m.ResetWorkflows()
		return nil
	}
	return fmt.Errorf("unknown Referrer edge %s", name)
}

// RobotAccountMutation represents an operation that mutates the RobotAccount nodes in the graph.
type RobotAccountMutation struct {
	config
	op              Op
	typ             string
	id              *uuid.UUID
	name            *string
	created_at      *time.Time
	revoked_at      *time.Time
	clearedFields   map[string]struct{}
	workflow        *uuid.UUID
	clearedworkflow bool
	done            bool
	oldValue        func(context.Context) (*RobotAccount, error)
	predicates      []predicate.RobotAccount
}

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

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

// newRobotAccountMutation creates new mutation for the RobotAccount entity.
func newRobotAccountMutation(c config, op Op, opts ...robotaccountOption) *RobotAccountMutation {
	m := &RobotAccountMutation{
		config:        c,
		op:            op,
		typ:           TypeRobotAccount,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *RobotAccountMutation) 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 RobotAccount entity.
// If the RobotAccount 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 *RobotAccountMutation) 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 *RobotAccountMutation) ResetName() {
	m.name = nil
}

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

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

// SetRevokedAt sets the "revoked_at" field.
func (m *RobotAccountMutation) SetRevokedAt(t time.Time) {
	m.revoked_at = &t
}

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

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

// ClearRevokedAt clears the value of the "revoked_at" field.
func (m *RobotAccountMutation) ClearRevokedAt() {
	m.revoked_at = nil
	m.clearedFields[robotaccount.FieldRevokedAt] = struct{}{}
}

// RevokedAtCleared returns if the "revoked_at" field was cleared in this mutation.
func (m *RobotAccountMutation) RevokedAtCleared() bool {
	_, ok := m.clearedFields[robotaccount.FieldRevokedAt]
	return ok
}

// ResetRevokedAt resets all changes to the "revoked_at" field.
func (m *RobotAccountMutation) ResetRevokedAt() {
	m.revoked_at = nil
	delete(m.clearedFields, robotaccount.FieldRevokedAt)
}

// SetWorkflowID sets the "workflow" edge to the Workflow entity by id.
func (m *RobotAccountMutation) SetWorkflowID(id uuid.UUID) {
	m.workflow = &id
}

// ClearWorkflow clears the "workflow" edge to the Workflow entity.
func (m *RobotAccountMutation) ClearWorkflow() {
	m.clearedworkflow = true
}

// WorkflowCleared reports if the "workflow" edge to the Workflow entity was cleared.
func (m *RobotAccountMutation) WorkflowCleared() bool {
	return m.clearedworkflow
}

// WorkflowID returns the "workflow" edge ID in the mutation.
func (m *RobotAccountMutation) WorkflowID() (id uuid.UUID, exists bool) {
	if m.workflow != nil {
		return *m.workflow, true
	}
	return
}

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

// ResetWorkflow resets all changes to the "workflow" edge.
func (m *RobotAccountMutation) ResetWorkflow() {
	m.workflow = nil
	m.clearedworkflow = false
}

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

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

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

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

// Type returns the node type of this mutation (RobotAccount).
func (m *RobotAccountMutation) 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 *RobotAccountMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.name != nil {
		fields = append(fields, robotaccount.FieldName)
	}
	if m.created_at != nil {
		fields = append(fields, robotaccount.FieldCreatedAt)
	}
	if m.revoked_at != nil {
		fields = append(fields, robotaccount.FieldRevokedAt)
	}
	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 *RobotAccountMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case robotaccount.FieldName:
		return m.Name()
	case robotaccount.FieldCreatedAt:
		return m.CreatedAt()
	case robotaccount.FieldRevokedAt:
		return m.RevokedAt()
	}
	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 *RobotAccountMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case robotaccount.FieldName:
		return m.OldName(ctx)
	case robotaccount.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case robotaccount.FieldRevokedAt:
		return m.OldRevokedAt(ctx)
	}
	return nil, fmt.Errorf("unknown RobotAccount 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 *RobotAccountMutation) SetField(name string, value ent.Value) error {
	switch name {
	case robotaccount.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case robotaccount.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case robotaccount.FieldRevokedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRevokedAt(v)
		return nil
	}
	return fmt.Errorf("unknown RobotAccount field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *RobotAccountMutation) 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 *RobotAccountMutation) ClearField(name string) error {
	switch name {
	case robotaccount.FieldRevokedAt:
		m.ClearRevokedAt()
		return nil
	}
	return fmt.Errorf("unknown RobotAccount 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 *RobotAccountMutation) ResetField(name string) error {
	switch name {
	case robotaccount.FieldName:
		m.ResetName()
		return nil
	case robotaccount.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case robotaccount.FieldRevokedAt:
		m.ResetRevokedAt()
		return nil
	}
	return fmt.Errorf("unknown RobotAccount field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *RobotAccountMutation) EdgeCleared(name string) bool {
	switch name {
	case robotaccount.EdgeWorkflow:
		return m.clearedworkflow
	}
	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 *RobotAccountMutation) ClearEdge(name string) error {
	switch name {
	case robotaccount.EdgeWorkflow:
		m.ClearWorkflow()
		return nil
	}
	return fmt.Errorf("unknown RobotAccount 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 *RobotAccountMutation) ResetEdge(name string) error {
	switch name {
	case robotaccount.EdgeWorkflow:
		m.ResetWorkflow()
		return nil
	}
	return fmt.Errorf("unknown RobotAccount edge %s", name)
}

// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
	config
	op                       Op
	typ                      string
	id                       *uuid.UUID
	email                    *string
	created_at               *time.Time
	updated_at               *time.Time
	has_restricted_access    *bool
	first_name               *string
	last_name                *string
	clearedFields            map[string]struct{}
	memberships              map[uuid.UUID]struct{}
	removedmemberships       map[uuid.UUID]struct{}
	clearedmemberships       bool
	group_memberships        map[uuid.UUID]struct{}
	removedgroup_memberships map[uuid.UUID]struct{}
	clearedgroup_memberships bool
	done                     bool
	oldValue                 func(context.Context) (*User, error)
	predicates               []predicate.User
}

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

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

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

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

// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
	return func(m *UserMutation) {
		m.oldValue = func(context.Context) (*User, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

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

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

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

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

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

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

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

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

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

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

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserMutation) 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 User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) 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 *UserMutation) ResetCreatedAt() {
	m.created_at = nil
}

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

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

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

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

// SetHasRestrictedAccess sets the "has_restricted_access" field.
func (m *UserMutation) SetHasRestrictedAccess(b bool) {
	m.has_restricted_access = &b
}

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

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

// ClearHasRestrictedAccess clears the value of the "has_restricted_access" field.
func (m *UserMutation) ClearHasRestrictedAccess() {
	m.has_restricted_access = nil
	m.clearedFields[user.FieldHasRestrictedAccess] = struct{}{}
}

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

// ResetHasRestrictedAccess resets all changes to the "has_restricted_access" field.
func (m *UserMutation) ResetHasRestrictedAccess() {
	m.has_restricted_access = nil
	delete(m.clearedFields, user.FieldHasRestrictedAccess)
}

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

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

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

// ClearFirstName clears the value of the "first_name" field.
func (m *UserMutation) ClearFirstName() {
	m.first_name = nil
	m.clearedFields[user.FieldFirstName] = struct{}{}
}

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

// ResetFirstName resets all changes to the "first_name" field.
func (m *UserMutation) ResetFirstName() {
	m.first_name = nil
	delete(m.clearedFields, user.FieldFirstName)
}

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

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

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

// ClearLastName clears the value of the "last_name" field.
func (m *UserMutation) ClearLastName() {
	m.last_name = nil
	m.clearedFields[user.FieldLastName] = struct{}{}
}

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

// ResetLastName resets all changes to the "last_name" field.
func (m *UserMutation) ResetLastName() {
	m.last_name = nil
	delete(m.clearedFields, user.FieldLastName)
}

// AddMembershipIDs adds the "memberships" edge to the Membership entity by ids.
func (m *UserMutation) AddMembershipIDs(ids ...uuid.UUID) {
	if m.memberships == nil {
		m.memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.memberships[ids[i]] = struct{}{}
	}
}

// ClearMemberships clears the "memberships" edge to the Membership entity.
func (m *UserMutation) ClearMemberships() {
	m.clearedmemberships = true
}

// MembershipsCleared reports if the "memberships" edge to the Membership entity was cleared.
func (m *UserMutation) MembershipsCleared() bool {
	return m.clearedmemberships
}

// RemoveMembershipIDs removes the "memberships" edge to the Membership entity by IDs.
func (m *UserMutation) RemoveMembershipIDs(ids ...uuid.UUID) {
	if m.removedmemberships == nil {
		m.removedmemberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.memberships, ids[i])
		m.removedmemberships[ids[i]] = struct{}{}
	}
}

// RemovedMemberships returns the removed IDs of the "memberships" edge to the Membership entity.
func (m *UserMutation) RemovedMembershipsIDs() (ids []uuid.UUID) {
	for id := range m.removedmemberships {
		ids = append(ids, id)
	}
	return
}

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

// ResetMemberships resets all changes to the "memberships" edge.
func (m *UserMutation) ResetMemberships() {
	m.memberships = nil
	m.clearedmemberships = false
	m.removedmemberships = nil
}

// AddGroupMembershipIDs adds the "group_memberships" edge to the GroupMembership entity by ids.
func (m *UserMutation) AddGroupMembershipIDs(ids ...uuid.UUID) {
	if m.group_memberships == nil {
		m.group_memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.group_memberships[ids[i]] = struct{}{}
	}
}

// ClearGroupMemberships clears the "group_memberships" edge to the GroupMembership entity.
func (m *UserMutation) ClearGroupMemberships() {
	m.clearedgroup_memberships = true
}

// GroupMembershipsCleared reports if the "group_memberships" edge to the GroupMembership entity was cleared.
func (m *UserMutation) GroupMembershipsCleared() bool {
	return m.clearedgroup_memberships
}

// RemoveGroupMembershipIDs removes the "group_memberships" edge to the GroupMembership entity by IDs.
func (m *UserMutation) RemoveGroupMembershipIDs(ids ...uuid.UUID) {
	if m.removedgroup_memberships == nil {
		m.removedgroup_memberships = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.group_memberships, ids[i])
		m.removedgroup_memberships[ids[i]] = struct{}{}
	}
}

// RemovedGroupMemberships returns the removed IDs of the "group_memberships" edge to the GroupMembership entity.
func (m *UserMutation) RemovedGroupMembershipsIDs() (ids []uuid.UUID) {
	for id := range m.removedgroup_memberships {
		ids = append(ids, id)
	}
	return
}

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

// ResetGroupMemberships resets all changes to the "group_memberships" edge.
func (m *UserMutation) ResetGroupMemberships() {
	m.group_memberships = nil
	m.clearedgroup_memberships = false
	m.removedgroup_memberships = nil
}

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

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

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

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

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

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.email != nil {
		fields = append(fields, user.FieldEmail)
	}
	if m.created_at != nil {
		fields = append(fields, user.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, user.FieldUpdatedAt)
	}
	if m.has_restricted_access != nil {
		fields = append(fields, user.FieldHasRestrictedAccess)
	}
	if m.first_name != nil {
		fields = append(fields, user.FieldFirstName)
	}
	if m.last_name != nil {
		fields = append(fields, user.FieldLastName)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UserMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case user.FieldEmail:
		return m.Email()
	case user.FieldCreatedAt:
		return m.CreatedAt()
	case user.FieldUpdatedAt:
		return m.UpdatedAt()
	case user.FieldHasRestrictedAccess:
		return m.HasRestrictedAccess()
	case user.FieldFirstName:
		return m.FirstName()
	case user.FieldLastName:
		return m.LastName()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case user.FieldEmail:
		return m.OldEmail(ctx)
	case user.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case user.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case user.FieldHasRestrictedAccess:
		return m.OldHasRestrictedAccess(ctx)
	case user.FieldFirstName:
		return m.OldFirstName(ctx)
	case user.FieldLastName:
		return m.OldLastName(ctx)
	}
	return nil, fmt.Errorf("unknown User field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) SetField(name string, value ent.Value) error {
	switch name {
	case user.FieldEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEmail(v)
		return nil
	case user.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case user.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case user.FieldHasRestrictedAccess:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHasRestrictedAccess(v)
		return nil
	case user.FieldFirstName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFirstName(v)
		return nil
	case user.FieldLastName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastName(v)
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

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

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

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

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
	switch name {
	case user.FieldHasRestrictedAccess:
		m.ClearHasRestrictedAccess()
		return nil
	case user.FieldFirstName:
		m.ClearFirstName()
		return nil
	case user.FieldLastName:
		m.ClearLastName()
		return nil
	}
	return fmt.Errorf("unknown User nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
	switch name {
	case user.FieldEmail:
		m.ResetEmail()
		return nil
	case user.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case user.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case user.FieldHasRestrictedAccess:
		m.ResetHasRestrictedAccess()
		return nil
	case user.FieldFirstName:
		m.ResetFirstName()
		return nil
	case user.FieldLastName:
		m.ResetLastName()
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.memberships != nil {
		edges = append(edges, user.EdgeMemberships)
	}
	if m.group_memberships != nil {
		edges = append(edges, user.EdgeGroupMemberships)
	}
	return edges
}

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

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	if m.removedmemberships != nil {
		edges = append(edges, user.EdgeMemberships)
	}
	if m.removedgroup_memberships != nil {
		edges = append(edges, user.EdgeGroupMemberships)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedmemberships {
		edges = append(edges, user.EdgeMemberships)
	}
	if m.clearedgroup_memberships {
		edges = append(edges, user.EdgeGroupMemberships)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
	switch name {
	case user.EdgeMemberships:
		return m.clearedmemberships
	case user.EdgeGroupMemberships:
		return m.clearedgroup_memberships
	}
	return false
}

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

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMutation) ResetEdge(name string) error {
	switch name {
	case user.EdgeMemberships:
		m.ResetMemberships()
		return nil
	case user.EdgeGroupMemberships:
		m.ResetGroupMemberships()
		return nil
	}
	return fmt.Errorf("unknown User edge %s", name)
}

// WorkflowMutation represents an operation that mutates the Workflow nodes in the graph.
type WorkflowMutation struct {
	config
	op                             Op
	typ                            string
	id                             *uuid.UUID
	name                           *string
	project_old                    *string
	team                           *string
	runs_count                     *int
	addruns_count                  *int
	created_at                     *time.Time
	updated_at                     *time.Time
	deleted_at                     *time.Time
	public                         *bool
	description                    *string
	metadata                       *map[string]interface{}
	clearedFields                  map[string]struct{}
	robotaccounts                  map[uuid.UUID]struct{}
	removedrobotaccounts           map[uuid.UUID]struct{}
	clearedrobotaccounts           bool
	workflowruns                   map[uuid.UUID]struct{}
	removedworkflowruns            map[uuid.UUID]struct{}
	clearedworkflowruns            bool
	organization                   *uuid.UUID
	clearedorganization            bool
	contract                       *uuid.UUID
	clearedcontract                bool
	integration_attachments        map[uuid.UUID]struct{}
	removedintegration_attachments map[uuid.UUID]struct{}
	clearedintegration_attachments bool
	project                        *uuid.UUID
	clearedproject                 bool
	latest_workflow_run            *uuid.UUID
	clearedlatest_workflow_run     bool
	referrers                      map[uuid.UUID]struct{}
	removedreferrers               map[uuid.UUID]struct{}
	clearedreferrers               bool
	done                           bool
	oldValue                       func(context.Context) (*Workflow, error)
	predicates                     []predicate.Workflow
}

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

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

// newWorkflowMutation creates new mutation for the Workflow entity.
func newWorkflowMutation(c config, op Op, opts ...workflowOption) *WorkflowMutation {
	m := &WorkflowMutation{
		config:        c,
		op:            op,
		typ:           TypeWorkflow,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *WorkflowMutation) 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 Workflow entity.
// If the Workflow 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 *WorkflowMutation) 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 *WorkflowMutation) ResetName() {
	m.name = nil
}

// SetProjectOld sets the "project_old" field.
func (m *WorkflowMutation) SetProjectOld(s string) {
	m.project_old = &s
}

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

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

// ClearProjectOld clears the value of the "project_old" field.
func (m *WorkflowMutation) ClearProjectOld() {
	m.project_old = nil
	m.clearedFields[workflow.FieldProjectOld] = struct{}{}
}

// ProjectOldCleared returns if the "project_old" field was cleared in this mutation.
func (m *WorkflowMutation) ProjectOldCleared() bool {
	_, ok := m.clearedFields[workflow.FieldProjectOld]
	return ok
}

// ResetProjectOld resets all changes to the "project_old" field.
func (m *WorkflowMutation) ResetProjectOld() {
	m.project_old = nil
	delete(m.clearedFields, workflow.FieldProjectOld)
}

// SetTeam sets the "team" field.
func (m *WorkflowMutation) SetTeam(s string) {
	m.team = &s
}

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

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

// ClearTeam clears the value of the "team" field.
func (m *WorkflowMutation) ClearTeam() {
	m.team = nil
	m.clearedFields[workflow.FieldTeam] = struct{}{}
}

// TeamCleared returns if the "team" field was cleared in this mutation.
func (m *WorkflowMutation) TeamCleared() bool {
	_, ok := m.clearedFields[workflow.FieldTeam]
	return ok
}

// ResetTeam resets all changes to the "team" field.
func (m *WorkflowMutation) ResetTeam() {
	m.team = nil
	delete(m.clearedFields, workflow.FieldTeam)
}

// SetRunsCount sets the "runs_count" field.
func (m *WorkflowMutation) SetRunsCount(i int) {
	m.runs_count = &i
	m.addruns_count = nil
}

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

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

// AddRunsCount adds i to the "runs_count" field.
func (m *WorkflowMutation) AddRunsCount(i int) {
	if m.addruns_count != nil {
		*m.addruns_count += i
	} else {
		m.addruns_count = &i
	}
}

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

// ResetRunsCount resets all changes to the "runs_count" field.
func (m *WorkflowMutation) ResetRunsCount() {
	m.runs_count = nil
	m.addruns_count = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *WorkflowMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *WorkflowMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[workflow.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *WorkflowMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[workflow.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *WorkflowMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, workflow.FieldDeletedAt)
}

// SetPublic sets the "public" field.
func (m *WorkflowMutation) SetPublic(b bool) {
	m.public = &b
}

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

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

// ResetPublic resets all changes to the "public" field.
func (m *WorkflowMutation) ResetPublic() {
	m.public = nil
}

// SetOrganizationID sets the "organization_id" field.
func (m *WorkflowMutation) SetOrganizationID(u uuid.UUID) {
	m.organization = &u
}

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

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

// ResetOrganizationID resets all changes to the "organization_id" field.
func (m *WorkflowMutation) ResetOrganizationID() {
	m.organization = nil
}

// SetProjectID sets the "project_id" field.
func (m *WorkflowMutation) SetProjectID(u uuid.UUID) {
	m.project = &u
}

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

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

// ResetProjectID resets all changes to the "project_id" field.
func (m *WorkflowMutation) ResetProjectID() {
	m.project = nil
}

// SetLatestRun sets the "latest_run" field.
func (m *WorkflowMutation) SetLatestRun(u uuid.UUID) {
	m.latest_workflow_run = &u
}

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

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

// ClearLatestRun clears the value of the "latest_run" field.
func (m *WorkflowMutation) ClearLatestRun() {
	m.latest_workflow_run = nil
	m.clearedFields[workflow.FieldLatestRun] = struct{}{}
}

// LatestRunCleared returns if the "latest_run" field was cleared in this mutation.
func (m *WorkflowMutation) LatestRunCleared() bool {
	_, ok := m.clearedFields[workflow.FieldLatestRun]
	return ok
}

// ResetLatestRun resets all changes to the "latest_run" field.
func (m *WorkflowMutation) ResetLatestRun() {
	m.latest_workflow_run = nil
	delete(m.clearedFields, workflow.FieldLatestRun)
}

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

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

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

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

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

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

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

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

// OldMetadata returns the old "metadata" field's value of the Workflow entity.
// If the Workflow 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 *WorkflowMutation) OldMetadata(ctx context.Context) (v map[string]interface{}, 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 *WorkflowMutation) ClearMetadata() {
	m.metadata = nil
	m.clearedFields[workflow.FieldMetadata] = struct{}{}
}

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

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

// AddRobotaccountIDs adds the "robotaccounts" edge to the RobotAccount entity by ids.
func (m *WorkflowMutation) AddRobotaccountIDs(ids ...uuid.UUID) {
	if m.robotaccounts == nil {
		m.robotaccounts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.robotaccounts[ids[i]] = struct{}{}
	}
}

// ClearRobotaccounts clears the "robotaccounts" edge to the RobotAccount entity.
func (m *WorkflowMutation) ClearRobotaccounts() {
	m.clearedrobotaccounts = true
}

// RobotaccountsCleared reports if the "robotaccounts" edge to the RobotAccount entity was cleared.
func (m *WorkflowMutation) RobotaccountsCleared() bool {
	return m.clearedrobotaccounts
}

// RemoveRobotaccountIDs removes the "robotaccounts" edge to the RobotAccount entity by IDs.
func (m *WorkflowMutation) RemoveRobotaccountIDs(ids ...uuid.UUID) {
	if m.removedrobotaccounts == nil {
		m.removedrobotaccounts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.robotaccounts, ids[i])
		m.removedrobotaccounts[ids[i]] = struct{}{}
	}
}

// RemovedRobotaccounts returns the removed IDs of the "robotaccounts" edge to the RobotAccount entity.
func (m *WorkflowMutation) RemovedRobotaccountsIDs() (ids []uuid.UUID) {
	for id := range m.removedrobotaccounts {
		ids = append(ids, id)
	}
	return
}

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

// ResetRobotaccounts resets all changes to the "robotaccounts" edge.
func (m *WorkflowMutation) ResetRobotaccounts() {
	m.robotaccounts = nil
	m.clearedrobotaccounts = false
	m.removedrobotaccounts = nil
}

// AddWorkflowrunIDs adds the "workflowruns" edge to the WorkflowRun entity by ids.
func (m *WorkflowMutation) AddWorkflowrunIDs(ids ...uuid.UUID) {
	if m.workflowruns == nil {
		m.workflowruns = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflowruns[ids[i]] = struct{}{}
	}
}

// ClearWorkflowruns clears the "workflowruns" edge to the WorkflowRun entity.
func (m *WorkflowMutation) ClearWorkflowruns() {
	m.clearedworkflowruns = true
}

// WorkflowrunsCleared reports if the "workflowruns" edge to the WorkflowRun entity was cleared.
func (m *WorkflowMutation) WorkflowrunsCleared() bool {
	return m.clearedworkflowruns
}

// RemoveWorkflowrunIDs removes the "workflowruns" edge to the WorkflowRun entity by IDs.
func (m *WorkflowMutation) RemoveWorkflowrunIDs(ids ...uuid.UUID) {
	if m.removedworkflowruns == nil {
		m.removedworkflowruns = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflowruns, ids[i])
		m.removedworkflowruns[ids[i]] = struct{}{}
	}
}

// RemovedWorkflowruns returns the removed IDs of the "workflowruns" edge to the WorkflowRun entity.
func (m *WorkflowMutation) RemovedWorkflowrunsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflowruns {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflowruns resets all changes to the "workflowruns" edge.
func (m *WorkflowMutation) ResetWorkflowruns() {
	m.workflowruns = nil
	m.clearedworkflowruns = false
	m.removedworkflowruns = nil
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *WorkflowMutation) ClearOrganization() {
	m.clearedorganization = true
	m.clearedFields[workflow.FieldOrganizationID] = struct{}{}
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *WorkflowMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *WorkflowMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// SetContractID sets the "contract" edge to the WorkflowContract entity by id.
func (m *WorkflowMutation) SetContractID(id uuid.UUID) {
	m.contract = &id
}

// ClearContract clears the "contract" edge to the WorkflowContract entity.
func (m *WorkflowMutation) ClearContract() {
	m.clearedcontract = true
}

// ContractCleared reports if the "contract" edge to the WorkflowContract entity was cleared.
func (m *WorkflowMutation) ContractCleared() bool {
	return m.clearedcontract
}

// ContractID returns the "contract" edge ID in the mutation.
func (m *WorkflowMutation) ContractID() (id uuid.UUID, exists bool) {
	if m.contract != nil {
		return *m.contract, true
	}
	return
}

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

// ResetContract resets all changes to the "contract" edge.
func (m *WorkflowMutation) ResetContract() {
	m.contract = nil
	m.clearedcontract = false
}

// AddIntegrationAttachmentIDs adds the "integration_attachments" edge to the IntegrationAttachment entity by ids.
func (m *WorkflowMutation) AddIntegrationAttachmentIDs(ids ...uuid.UUID) {
	if m.integration_attachments == nil {
		m.integration_attachments = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.integration_attachments[ids[i]] = struct{}{}
	}
}

// ClearIntegrationAttachments clears the "integration_attachments" edge to the IntegrationAttachment entity.
func (m *WorkflowMutation) ClearIntegrationAttachments() {
	m.clearedintegration_attachments = true
}

// IntegrationAttachmentsCleared reports if the "integration_attachments" edge to the IntegrationAttachment entity was cleared.
func (m *WorkflowMutation) IntegrationAttachmentsCleared() bool {
	return m.clearedintegration_attachments
}

// RemoveIntegrationAttachmentIDs removes the "integration_attachments" edge to the IntegrationAttachment entity by IDs.
func (m *WorkflowMutation) RemoveIntegrationAttachmentIDs(ids ...uuid.UUID) {
	if m.removedintegration_attachments == nil {
		m.removedintegration_attachments = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.integration_attachments, ids[i])
		m.removedintegration_attachments[ids[i]] = struct{}{}
	}
}

// RemovedIntegrationAttachments returns the removed IDs of the "integration_attachments" edge to the IntegrationAttachment entity.
func (m *WorkflowMutation) RemovedIntegrationAttachmentsIDs() (ids []uuid.UUID) {
	for id := range m.removedintegration_attachments {
		ids = append(ids, id)
	}
	return
}

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

// ResetIntegrationAttachments resets all changes to the "integration_attachments" edge.
func (m *WorkflowMutation) ResetIntegrationAttachments() {
	m.integration_attachments = nil
	m.clearedintegration_attachments = false
	m.removedintegration_attachments = nil
}

// ClearProject clears the "project" edge to the Project entity.
func (m *WorkflowMutation) ClearProject() {
	m.clearedproject = true
	m.clearedFields[workflow.FieldProjectID] = struct{}{}
}

// ProjectCleared reports if the "project" edge to the Project entity was cleared.
func (m *WorkflowMutation) ProjectCleared() bool {
	return m.clearedproject
}

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

// ResetProject resets all changes to the "project" edge.
func (m *WorkflowMutation) ResetProject() {
	m.project = nil
	m.clearedproject = false
}

// SetLatestWorkflowRunID sets the "latest_workflow_run" edge to the WorkflowRun entity by id.
func (m *WorkflowMutation) SetLatestWorkflowRunID(id uuid.UUID) {
	m.latest_workflow_run = &id
}

// ClearLatestWorkflowRun clears the "latest_workflow_run" edge to the WorkflowRun entity.
func (m *WorkflowMutation) ClearLatestWorkflowRun() {
	m.clearedlatest_workflow_run = true
	m.clearedFields[workflow.FieldLatestRun] = struct{}{}
}

// LatestWorkflowRunCleared reports if the "latest_workflow_run" edge to the WorkflowRun entity was cleared.
func (m *WorkflowMutation) LatestWorkflowRunCleared() bool {
	return m.LatestRunCleared() || m.clearedlatest_workflow_run
}

// LatestWorkflowRunID returns the "latest_workflow_run" edge ID in the mutation.
func (m *WorkflowMutation) LatestWorkflowRunID() (id uuid.UUID, exists bool) {
	if m.latest_workflow_run != nil {
		return *m.latest_workflow_run, true
	}
	return
}

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

// ResetLatestWorkflowRun resets all changes to the "latest_workflow_run" edge.
func (m *WorkflowMutation) ResetLatestWorkflowRun() {
	m.latest_workflow_run = nil
	m.clearedlatest_workflow_run = false
}

// AddReferrerIDs adds the "referrers" edge to the Referrer entity by ids.
func (m *WorkflowMutation) AddReferrerIDs(ids ...uuid.UUID) {
	if m.referrers == nil {
		m.referrers = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.referrers[ids[i]] = struct{}{}
	}
}

// ClearReferrers clears the "referrers" edge to the Referrer entity.
func (m *WorkflowMutation) ClearReferrers() {
	m.clearedreferrers = true
}

// ReferrersCleared reports if the "referrers" edge to the Referrer entity was cleared.
func (m *WorkflowMutation) ReferrersCleared() bool {
	return m.clearedreferrers
}

// RemoveReferrerIDs removes the "referrers" edge to the Referrer entity by IDs.
func (m *WorkflowMutation) RemoveReferrerIDs(ids ...uuid.UUID) {
	if m.removedreferrers == nil {
		m.removedreferrers = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.referrers, ids[i])
		m.removedreferrers[ids[i]] = struct{}{}
	}
}

// RemovedReferrers returns the removed IDs of the "referrers" edge to the Referrer entity.
func (m *WorkflowMutation) RemovedReferrersIDs() (ids []uuid.UUID) {
	for id := range m.removedreferrers {
		ids = append(ids, id)
	}
	return
}

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

// ResetReferrers resets all changes to the "referrers" edge.
func (m *WorkflowMutation) ResetReferrers() {
	m.referrers = nil
	m.clearedreferrers = false
	m.removedreferrers = nil
}

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

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

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

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

// Type returns the node type of this mutation (Workflow).
func (m *WorkflowMutation) 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 *WorkflowMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.name != nil {
		fields = append(fields, workflow.FieldName)
	}
	if m.project_old != nil {
		fields = append(fields, workflow.FieldProjectOld)
	}
	if m.team != nil {
		fields = append(fields, workflow.FieldTeam)
	}
	if m.runs_count != nil {
		fields = append(fields, workflow.FieldRunsCount)
	}
	if m.created_at != nil {
		fields = append(fields, workflow.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, workflow.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, workflow.FieldDeletedAt)
	}
	if m.public != nil {
		fields = append(fields, workflow.FieldPublic)
	}
	if m.organization != nil {
		fields = append(fields, workflow.FieldOrganizationID)
	}
	if m.project != nil {
		fields = append(fields, workflow.FieldProjectID)
	}
	if m.latest_workflow_run != nil {
		fields = append(fields, workflow.FieldLatestRun)
	}
	if m.description != nil {
		fields = append(fields, workflow.FieldDescription)
	}
	if m.metadata != nil {
		fields = append(fields, workflow.FieldMetadata)
	}
	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 *WorkflowMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case workflow.FieldName:
		return m.Name()
	case workflow.FieldProjectOld:
		return m.ProjectOld()
	case workflow.FieldTeam:
		return m.Team()
	case workflow.FieldRunsCount:
		return m.RunsCount()
	case workflow.FieldCreatedAt:
		return m.CreatedAt()
	case workflow.FieldUpdatedAt:
		return m.UpdatedAt()
	case workflow.FieldDeletedAt:
		return m.DeletedAt()
	case workflow.FieldPublic:
		return m.Public()
	case workflow.FieldOrganizationID:
		return m.OrganizationID()
	case workflow.FieldProjectID:
		return m.ProjectID()
	case workflow.FieldLatestRun:
		return m.LatestRun()
	case workflow.FieldDescription:
		return m.Description()
	case workflow.FieldMetadata:
		return m.Metadata()
	}
	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 *WorkflowMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case workflow.FieldName:
		return m.OldName(ctx)
	case workflow.FieldProjectOld:
		return m.OldProjectOld(ctx)
	case workflow.FieldTeam:
		return m.OldTeam(ctx)
	case workflow.FieldRunsCount:
		return m.OldRunsCount(ctx)
	case workflow.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case workflow.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case workflow.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case workflow.FieldPublic:
		return m.OldPublic(ctx)
	case workflow.FieldOrganizationID:
		return m.OldOrganizationID(ctx)
	case workflow.FieldProjectID:
		return m.OldProjectID(ctx)
	case workflow.FieldLatestRun:
		return m.OldLatestRun(ctx)
	case workflow.FieldDescription:
		return m.OldDescription(ctx)
	case workflow.FieldMetadata:
		return m.OldMetadata(ctx)
	}
	return nil, fmt.Errorf("unknown Workflow 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 *WorkflowMutation) SetField(name string, value ent.Value) error {
	switch name {
	case workflow.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case workflow.FieldProjectOld:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProjectOld(v)
		return nil
	case workflow.FieldTeam:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTeam(v)
		return nil
	case workflow.FieldRunsCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRunsCount(v)
		return nil
	case workflow.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case workflow.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case workflow.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case workflow.FieldPublic:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPublic(v)
		return nil
	case workflow.FieldOrganizationID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrganizationID(v)
		return nil
	case workflow.FieldProjectID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProjectID(v)
		return nil
	case workflow.FieldLatestRun:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLatestRun(v)
		return nil
	case workflow.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case workflow.FieldMetadata:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	}
	return fmt.Errorf("unknown Workflow field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WorkflowMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(workflow.FieldProjectOld) {
		fields = append(fields, workflow.FieldProjectOld)
	}
	if m.FieldCleared(workflow.FieldTeam) {
		fields = append(fields, workflow.FieldTeam)
	}
	if m.FieldCleared(workflow.FieldDeletedAt) {
		fields = append(fields, workflow.FieldDeletedAt)
	}
	if m.FieldCleared(workflow.FieldLatestRun) {
		fields = append(fields, workflow.FieldLatestRun)
	}
	if m.FieldCleared(workflow.FieldDescription) {
		fields = append(fields, workflow.FieldDescription)
	}
	if m.FieldCleared(workflow.FieldMetadata) {
		fields = append(fields, workflow.FieldMetadata)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WorkflowMutation) 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 *WorkflowMutation) ClearField(name string) error {
	switch name {
	case workflow.FieldProjectOld:
		m.ClearProjectOld()
		return nil
	case workflow.FieldTeam:
		m.ClearTeam()
		return nil
	case workflow.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case workflow.FieldLatestRun:
		m.ClearLatestRun()
		return nil
	case workflow.FieldDescription:
		m.ClearDescription()
		return nil
	case workflow.FieldMetadata:
		m.ClearMetadata()
		return nil
	}
	return fmt.Errorf("unknown Workflow 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 *WorkflowMutation) ResetField(name string) error {
	switch name {
	case workflow.FieldName:
		m.ResetName()
		return nil
	case workflow.FieldProjectOld:
		m.ResetProjectOld()
		return nil
	case workflow.FieldTeam:
		m.ResetTeam()
		return nil
	case workflow.FieldRunsCount:
		m.ResetRunsCount()
		return nil
	case workflow.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case workflow.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case workflow.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case workflow.FieldPublic:
		m.ResetPublic()
		return nil
	case workflow.FieldOrganizationID:
		m.ResetOrganizationID()
		return nil
	case workflow.FieldProjectID:
		m.ResetProjectID()
		return nil
	case workflow.FieldLatestRun:
		m.ResetLatestRun()
		return nil
	case workflow.FieldDescription:
		m.ResetDescription()
		return nil
	case workflow.FieldMetadata:
		m.ResetMetadata()
		return nil
	}
	return fmt.Errorf("unknown Workflow field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WorkflowMutation) AddedEdges() []string {
	edges := make([]string, 0, 8)
	if m.robotaccounts != nil {
		edges = append(edges, workflow.EdgeRobotaccounts)
	}
	if m.workflowruns != nil {
		edges = append(edges, workflow.EdgeWorkflowruns)
	}
	if m.organization != nil {
		edges = append(edges, workflow.EdgeOrganization)
	}
	if m.contract != nil {
		edges = append(edges, workflow.EdgeContract)
	}
	if m.integration_attachments != nil {
		edges = append(edges, workflow.EdgeIntegrationAttachments)
	}
	if m.project != nil {
		edges = append(edges, workflow.EdgeProject)
	}
	if m.latest_workflow_run != nil {
		edges = append(edges, workflow.EdgeLatestWorkflowRun)
	}
	if m.referrers != nil {
		edges = append(edges, workflow.EdgeReferrers)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WorkflowMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case workflow.EdgeRobotaccounts:
		ids := make([]ent.Value, 0, len(m.robotaccounts))
		for id := range m.robotaccounts {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeWorkflowruns:
		ids := make([]ent.Value, 0, len(m.workflowruns))
		for id := range m.workflowruns {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeOrganization:
		if id := m.organization; id != nil {
			return []ent.Value{*id}
		}
	case workflow.EdgeContract:
		if id := m.contract; id != nil {
			return []ent.Value{*id}
		}
	case workflow.EdgeIntegrationAttachments:
		ids := make([]ent.Value, 0, len(m.integration_attachments))
		for id := range m.integration_attachments {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeProject:
		if id := m.project; id != nil {
			return []ent.Value{*id}
		}
	case workflow.EdgeLatestWorkflowRun:
		if id := m.latest_workflow_run; id != nil {
			return []ent.Value{*id}
		}
	case workflow.EdgeReferrers:
		ids := make([]ent.Value, 0, len(m.referrers))
		for id := range m.referrers {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WorkflowMutation) RemovedEdges() []string {
	edges := make([]string, 0, 8)
	if m.removedrobotaccounts != nil {
		edges = append(edges, workflow.EdgeRobotaccounts)
	}
	if m.removedworkflowruns != nil {
		edges = append(edges, workflow.EdgeWorkflowruns)
	}
	if m.removedintegration_attachments != nil {
		edges = append(edges, workflow.EdgeIntegrationAttachments)
	}
	if m.removedreferrers != nil {
		edges = append(edges, workflow.EdgeReferrers)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *WorkflowMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case workflow.EdgeRobotaccounts:
		ids := make([]ent.Value, 0, len(m.removedrobotaccounts))
		for id := range m.removedrobotaccounts {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeWorkflowruns:
		ids := make([]ent.Value, 0, len(m.removedworkflowruns))
		for id := range m.removedworkflowruns {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeIntegrationAttachments:
		ids := make([]ent.Value, 0, len(m.removedintegration_attachments))
		for id := range m.removedintegration_attachments {
			ids = append(ids, id)
		}
		return ids
	case workflow.EdgeReferrers:
		ids := make([]ent.Value, 0, len(m.removedreferrers))
		for id := range m.removedreferrers {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WorkflowMutation) ClearedEdges() []string {
	edges := make([]string, 0, 8)
	if m.clearedrobotaccounts {
		edges = append(edges, workflow.EdgeRobotaccounts)
	}
	if m.clearedworkflowruns {
		edges = append(edges, workflow.EdgeWorkflowruns)
	}
	if m.clearedorganization {
		edges = append(edges, workflow.EdgeOrganization)
	}
	if m.clearedcontract {
		edges = append(edges, workflow.EdgeContract)
	}
	if m.clearedintegration_attachments {
		edges = append(edges, workflow.EdgeIntegrationAttachments)
	}
	if m.clearedproject {
		edges = append(edges, workflow.EdgeProject)
	}
	if m.clearedlatest_workflow_run {
		edges = append(edges, workflow.EdgeLatestWorkflowRun)
	}
	if m.clearedreferrers {
		edges = append(edges, workflow.EdgeReferrers)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WorkflowMutation) EdgeCleared(name string) bool {
	switch name {
	case workflow.EdgeRobotaccounts:
		return m.clearedrobotaccounts
	case workflow.EdgeWorkflowruns:
		return m.clearedworkflowruns
	case workflow.EdgeOrganization:
		return m.clearedorganization
	case workflow.EdgeContract:
		return m.clearedcontract
	case workflow.EdgeIntegrationAttachments:
		return m.clearedintegration_attachments
	case workflow.EdgeProject:
		return m.clearedproject
	case workflow.EdgeLatestWorkflowRun:
		return m.clearedlatest_workflow_run
	case workflow.EdgeReferrers:
		return m.clearedreferrers
	}
	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 *WorkflowMutation) ClearEdge(name string) error {
	switch name {
	case workflow.EdgeOrganization:
		m.ClearOrganization()
		return nil
	case workflow.EdgeContract:
		m.ClearContract()
		return nil
	case workflow.EdgeProject:
		m.ClearProject()
		return nil
	case workflow.EdgeLatestWorkflowRun:
		m.ClearLatestWorkflowRun()
		return nil
	}
	return fmt.Errorf("unknown Workflow 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 *WorkflowMutation) ResetEdge(name string) error {
	switch name {
	case workflow.EdgeRobotaccounts:
		m.ResetRobotaccounts()
		return nil
	case workflow.EdgeWorkflowruns:
		m.ResetWorkflowruns()
		return nil
	case workflow.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case workflow.EdgeContract:
		m.ResetContract()
		return nil
	case workflow.EdgeIntegrationAttachments:
		m.ResetIntegrationAttachments()
		return nil
	case workflow.EdgeProject:
		m.ResetProject()
		return nil
	case workflow.EdgeLatestWorkflowRun:
		m.ResetLatestWorkflowRun()
		return nil
	case workflow.EdgeReferrers:
		m.ResetReferrers()
		return nil
	}
	return fmt.Errorf("unknown Workflow edge %s", name)
}

// WorkflowContractMutation represents an operation that mutates the WorkflowContract nodes in the graph.
type WorkflowContractMutation struct {
	config
	op                   Op
	typ                  string
	id                   *uuid.UUID
	name                 *string
	created_at           *time.Time
	updated_at           *time.Time
	deleted_at           *time.Time
	description          *string
	scoped_resource_type *biz.ContractScope
	scoped_resource_id   *uuid.UUID
	clearedFields        map[string]struct{}
	versions             map[uuid.UUID]struct{}
	removedversions      map[uuid.UUID]struct{}
	clearedversions      bool
	organization         *uuid.UUID
	clearedorganization  bool
	workflows            map[uuid.UUID]struct{}
	removedworkflows     map[uuid.UUID]struct{}
	clearedworkflows     bool
	done                 bool
	oldValue             func(context.Context) (*WorkflowContract, error)
	predicates           []predicate.WorkflowContract
}

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

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

// newWorkflowContractMutation creates new mutation for the WorkflowContract entity.
func newWorkflowContractMutation(c config, op Op, opts ...workflowcontractOption) *WorkflowContractMutation {
	m := &WorkflowContractMutation{
		config:        c,
		op:            op,
		typ:           TypeWorkflowContract,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

// Name returns the value of the "name" field in the mutation.
func (m *WorkflowContractMutation) 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 WorkflowContract entity.
// If the WorkflowContract 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 *WorkflowContractMutation) 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 *WorkflowContractMutation) ResetName() {
	m.name = nil
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (m *WorkflowContractMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *WorkflowContractMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[workflowcontract.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *WorkflowContractMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[workflowcontract.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *WorkflowContractMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, workflowcontract.FieldDeletedAt)
}

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

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

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

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

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

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

// SetScopedResourceType sets the "scoped_resource_type" field.
func (m *WorkflowContractMutation) SetScopedResourceType(bs biz.ContractScope) {
	m.scoped_resource_type = &bs
}

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

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

// ClearScopedResourceType clears the value of the "scoped_resource_type" field.
func (m *WorkflowContractMutation) ClearScopedResourceType() {
	m.scoped_resource_type = nil
	m.clearedFields[workflowcontract.FieldScopedResourceType] = struct{}{}
}

// ScopedResourceTypeCleared returns if the "scoped_resource_type" field was cleared in this mutation.
func (m *WorkflowContractMutation) ScopedResourceTypeCleared() bool {
	_, ok := m.clearedFields[workflowcontract.FieldScopedResourceType]
	return ok
}

// ResetScopedResourceType resets all changes to the "scoped_resource_type" field.
func (m *WorkflowContractMutation) ResetScopedResourceType() {
	m.scoped_resource_type = nil
	delete(m.clearedFields, workflowcontract.FieldScopedResourceType)
}

// SetScopedResourceID sets the "scoped_resource_id" field.
func (m *WorkflowContractMutation) SetScopedResourceID(u uuid.UUID) {
	m.scoped_resource_id = &u
}

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

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

// ClearScopedResourceID clears the value of the "scoped_resource_id" field.
func (m *WorkflowContractMutation) ClearScopedResourceID() {
	m.scoped_resource_id = nil
	m.clearedFields[workflowcontract.FieldScopedResourceID] = struct{}{}
}

// ScopedResourceIDCleared returns if the "scoped_resource_id" field was cleared in this mutation.
func (m *WorkflowContractMutation) ScopedResourceIDCleared() bool {
	_, ok := m.clearedFields[workflowcontract.FieldScopedResourceID]
	return ok
}

// ResetScopedResourceID resets all changes to the "scoped_resource_id" field.
func (m *WorkflowContractMutation) ResetScopedResourceID() {
	m.scoped_resource_id = nil
	delete(m.clearedFields, workflowcontract.FieldScopedResourceID)
}

// AddVersionIDs adds the "versions" edge to the WorkflowContractVersion entity by ids.
func (m *WorkflowContractMutation) AddVersionIDs(ids ...uuid.UUID) {
	if m.versions == nil {
		m.versions = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.versions[ids[i]] = struct{}{}
	}
}

// ClearVersions clears the "versions" edge to the WorkflowContractVersion entity.
func (m *WorkflowContractMutation) ClearVersions() {
	m.clearedversions = true
}

// VersionsCleared reports if the "versions" edge to the WorkflowContractVersion entity was cleared.
func (m *WorkflowContractMutation) VersionsCleared() bool {
	return m.clearedversions
}

// RemoveVersionIDs removes the "versions" edge to the WorkflowContractVersion entity by IDs.
func (m *WorkflowContractMutation) RemoveVersionIDs(ids ...uuid.UUID) {
	if m.removedversions == nil {
		m.removedversions = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.versions, ids[i])
		m.removedversions[ids[i]] = struct{}{}
	}
}

// RemovedVersions returns the removed IDs of the "versions" edge to the WorkflowContractVersion entity.
func (m *WorkflowContractMutation) RemovedVersionsIDs() (ids []uuid.UUID) {
	for id := range m.removedversions {
		ids = append(ids, id)
	}
	return
}

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

// ResetVersions resets all changes to the "versions" edge.
func (m *WorkflowContractMutation) ResetVersions() {
	m.versions = nil
	m.clearedversions = false
	m.removedversions = nil
}

// SetOrganizationID sets the "organization" edge to the Organization entity by id.
func (m *WorkflowContractMutation) SetOrganizationID(id uuid.UUID) {
	m.organization = &id
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *WorkflowContractMutation) ClearOrganization() {
	m.clearedorganization = true
}

// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *WorkflowContractMutation) OrganizationCleared() bool {
	return m.clearedorganization
}

// OrganizationID returns the "organization" edge ID in the mutation.
func (m *WorkflowContractMutation) OrganizationID() (id uuid.UUID, exists bool) {
	if m.organization != nil {
		return *m.organization, true
	}
	return
}

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

// ResetOrganization resets all changes to the "organization" edge.
func (m *WorkflowContractMutation) ResetOrganization() {
	m.organization = nil
	m.clearedorganization = false
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by ids.
func (m *WorkflowContractMutation) AddWorkflowIDs(ids ...uuid.UUID) {
	if m.workflows == nil {
		m.workflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.workflows[ids[i]] = struct{}{}
	}
}

// ClearWorkflows clears the "workflows" edge to the Workflow entity.
func (m *WorkflowContractMutation) ClearWorkflows() {
	m.clearedworkflows = true
}

// WorkflowsCleared reports if the "workflows" edge to the Workflow entity was cleared.
func (m *WorkflowContractMutation) WorkflowsCleared() bool {
	return m.clearedworkflows
}

// RemoveWorkflowIDs removes the "workflows" edge to the Workflow entity by IDs.
func (m *WorkflowContractMutation) RemoveWorkflowIDs(ids ...uuid.UUID) {
	if m.removedworkflows == nil {
		m.removedworkflows = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.workflows, ids[i])
		m.removedworkflows[ids[i]] = struct{}{}
	}
}

// RemovedWorkflows returns the removed IDs of the "workflows" edge to the Workflow entity.
func (m *WorkflowContractMutation) RemovedWorkflowsIDs() (ids []uuid.UUID) {
	for id := range m.removedworkflows {
		ids = append(ids, id)
	}
	return
}

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

// ResetWorkflows resets all changes to the "workflows" edge.
func (m *WorkflowContractMutation) ResetWorkflows() {
	m.workflows = nil
	m.clearedworkflows = false
	m.removedworkflows = nil
}

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

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

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

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

// Type returns the node type of this mutation (WorkflowContract).
func (m *WorkflowContractMutation) 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 *WorkflowContractMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, workflowcontract.FieldName)
	}
	if m.created_at != nil {
		fields = append(fields, workflowcontract.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, workflowcontract.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, workflowcontract.FieldDeletedAt)
	}
	if m.description != nil {
		fields = append(fields, workflowcontract.FieldDescription)
	}
	if m.scoped_resource_type != nil {
		fields = append(fields, workflowcontract.FieldScopedResourceType)
	}
	if m.scoped_resource_id != nil {
		fields = append(fields, workflowcontract.FieldScopedResourceID)
	}
	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 *WorkflowContractMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case workflowcontract.FieldName:
		return m.Name()
	case workflowcontract.FieldCreatedAt:
		return m.CreatedAt()
	case workflowcontract.FieldUpdatedAt:
		return m.UpdatedAt()
	case workflowcontract.FieldDeletedAt:
		return m.DeletedAt()
	case workflowcontract.FieldDescription:
		return m.Description()
	case workflowcontract.FieldScopedResourceType:
		return m.ScopedResourceType()
	case workflowcontract.FieldScopedResourceID:
		return m.ScopedResourceID()
	}
	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 *WorkflowContractMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case workflowcontract.FieldName:
		return m.OldName(ctx)
	case workflowcontract.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case workflowcontract.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case workflowcontract.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case workflowcontract.FieldDescription:
		return m.OldDescription(ctx)
	case workflowcontract.FieldScopedResourceType:
		return m.OldScopedResourceType(ctx)
	case workflowcontract.FieldScopedResourceID:
		return m.OldScopedResourceID(ctx)
	}
	return nil, fmt.Errorf("unknown WorkflowContract 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 *WorkflowContractMutation) SetField(name string, value ent.Value) error {
	switch name {
	case workflowcontract.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case workflowcontract.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case workflowcontract.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	case workflowcontract.FieldDeletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedAt(v)
		return nil
	case workflowcontract.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case workflowcontract.FieldScopedResourceType:
		v, ok := value.(biz.ContractScope)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetScopedResourceType(v)
		return nil
	case workflowcontract.FieldScopedResourceID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetScopedResourceID(v)
		return nil
	}
	return fmt.Errorf("unknown WorkflowContract field %s", name)
}

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

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WorkflowContractMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(workflowcontract.FieldDeletedAt) {
		fields = append(fields, workflowcontract.FieldDeletedAt)
	}
	if m.FieldCleared(workflowcontract.FieldDescription) {
		fields = append(fields, workflowcontract.FieldDescription)
	}
	if m.FieldCleared(workflowcontract.FieldScopedResourceType) {
		fields = append(fields, workflowcontract.FieldScopedResourceType)
	}
	if m.FieldCleared(workflowcontract.FieldScopedResourceID) {
		fields = append(fields, workflowcontract.FieldScopedResourceID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WorkflowContractMutation) 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 *WorkflowContractMutation) ClearField(name string) error {
	switch name {
	case workflowcontract.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case workflowcontract.FieldDescription:
		m.ClearDescription()
		return nil
	case workflowcontract.FieldScopedResourceType:
		m.ClearScopedResourceType()
		return nil
	case workflowcontract.FieldScopedResourceID:
		m.ClearScopedResourceID()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContract 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 *WorkflowContractMutation) ResetField(name string) error {
	switch name {
	case workflowcontract.FieldName:
		m.ResetName()
		return nil
	case workflowcontract.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case workflowcontract.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case workflowcontract.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case workflowcontract.FieldDescription:
		m.ResetDescription()
		return nil
	case workflowcontract.FieldScopedResourceType:
		m.ResetScopedResourceType()
		return nil
	case workflowcontract.FieldScopedResourceID:
		m.ResetScopedResourceID()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContract field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WorkflowContractMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.versions != nil {
		edges = append(edges, workflowcontract.EdgeVersions)
	}
	if m.organization != nil {
		edges = append(edges, workflowcontract.EdgeOrganization)
	}
	if m.workflows != nil {
		edges = append(edges, workflowcontract.EdgeWorkflows)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WorkflowContractMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case workflowcontract.EdgeVersions:
		ids := make([]ent.Value, 0, len(m.versions))
		for id := range m.versions {
			ids = append(ids, id)
		}
		return ids
	case workflowcontract.EdgeOrganization:
		if id := m.organization; id != nil {
			return []ent.Value{*id}
		}
	case workflowcontract.EdgeWorkflows:
		ids := make([]ent.Value, 0, len(m.workflows))
		for id := range m.workflows {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WorkflowContractMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedversions != nil {
		edges = append(edges, workflowcontract.EdgeVersions)
	}
	if m.removedworkflows != nil {
		edges = append(edges, workflowcontract.EdgeWorkflows)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WorkflowContractMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedversions {
		edges = append(edges, workflowcontract.EdgeVersions)
	}
	if m.clearedorganization {
		edges = append(edges, workflowcontract.EdgeOrganization)
	}
	if m.clearedworkflows {
		edges = append(edges, workflowcontract.EdgeWorkflows)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WorkflowContractMutation) EdgeCleared(name string) bool {
	switch name {
	case workflowcontract.EdgeVersions:
		return m.clearedversions
	case workflowcontract.EdgeOrganization:
		return m.clearedorganization
	case workflowcontract.EdgeWorkflows:
		return m.clearedworkflows
	}
	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 *WorkflowContractMutation) ClearEdge(name string) error {
	switch name {
	case workflowcontract.EdgeOrganization:
		m.ClearOrganization()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContract 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 *WorkflowContractMutation) ResetEdge(name string) error {
	switch name {
	case workflowcontract.EdgeVersions:
		m.ResetVersions()
		return nil
	case workflowcontract.EdgeOrganization:
		m.ResetOrganization()
		return nil
	case workflowcontract.EdgeWorkflows:
		m.ResetWorkflows()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContract edge %s", name)
}

// WorkflowContractVersionMutation represents an operation that mutates the WorkflowContractVersion nodes in the graph.
type WorkflowContractVersionMutation struct {
	config
	op              Op
	typ             string
	id              *uuid.UUID
	body            *[]byte
	raw_body        *[]byte
	raw_body_format *unmarshal.RawFormat
	revision        *int
	addrevision     *int
	created_at      *time.Time
	clearedFields   map[string]struct{}
	contract        *uuid.UUID
	clearedcontract bool
	done            bool
	oldValue        func(context.Context) (*WorkflowContractVersion, error)
	predicates      []predicate.WorkflowContractVersion
}

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

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

// newWorkflowContractVersionMutation creates new mutation for the WorkflowContractVersion entity.
func newWorkflowContractVersionMutation(c config, op Op, opts ...workflowcontractversionOption) *WorkflowContractVersionMutation {
	m := &WorkflowContractVersionMutation{
		config:        c,
		op:            op,
		typ:           TypeWorkflowContractVersion,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

// SetBody sets the "body" field.
func (m *WorkflowContractVersionMutation) SetBody(b []byte) {
	m.body = &b
}

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

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

// ClearBody clears the value of the "body" field.
func (m *WorkflowContractVersionMutation) ClearBody() {
	m.body = nil
	m.clearedFields[workflowcontractversion.FieldBody] = struct{}{}
}

// BodyCleared returns if the "body" field was cleared in this mutation.
func (m *WorkflowContractVersionMutation) BodyCleared() bool {
	_, ok := m.clearedFields[workflowcontractversion.FieldBody]
	return ok
}

// ResetBody resets all changes to the "body" field.
func (m *WorkflowContractVersionMutation) ResetBody() {
	m.body = nil
	delete(m.clearedFields, workflowcontractversion.FieldBody)
}

// SetRawBody sets the "raw_body" field.
func (m *WorkflowContractVersionMutation) SetRawBody(b []byte) {
	m.raw_body = &b
}

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

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

// ResetRawBody resets all changes to the "raw_body" field.
func (m *WorkflowContractVersionMutation) ResetRawBody() {
	m.raw_body = nil
}

// SetRawBodyFormat sets the "raw_body_format" field.
func (m *WorkflowContractVersionMutation) SetRawBodyFormat(uf unmarshal.RawFormat) {
	m.raw_body_format = &uf
}

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

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

// ResetRawBodyFormat resets all changes to the "raw_body_format" field.
func (m *WorkflowContractVersionMutation) ResetRawBodyFormat() {
	m.raw_body_format = nil
}

// SetRevision sets the "revision" field.
func (m *WorkflowContractVersionMutation) SetRevision(i int) {
	m.revision = &i
	m.addrevision = nil
}

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

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

// AddRevision adds i to the "revision" field.
func (m *WorkflowContractVersionMutation) AddRevision(i int) {
	if m.addrevision != nil {
		*m.addrevision += i
	} else {
		m.addrevision = &i
	}
}

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

// ResetRevision resets all changes to the "revision" field.
func (m *WorkflowContractVersionMutation) ResetRevision() {
	m.revision = nil
	m.addrevision = nil
}

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

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

// SetContractID sets the "contract" edge to the WorkflowContract entity by id.
func (m *WorkflowContractVersionMutation) SetContractID(id uuid.UUID) {
	m.contract = &id
}

// ClearContract clears the "contract" edge to the WorkflowContract entity.
func (m *WorkflowContractVersionMutation) ClearContract() {
	m.clearedcontract = true
}

// ContractCleared reports if the "contract" edge to the WorkflowContract entity was cleared.
func (m *WorkflowContractVersionMutation) ContractCleared() bool {
	return m.clearedcontract
}

// ContractID returns the "contract" edge ID in the mutation.
func (m *WorkflowContractVersionMutation) ContractID() (id uuid.UUID, exists bool) {
	if m.contract != nil {
		return *m.contract, true
	}
	return
}

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

// ResetContract resets all changes to the "contract" edge.
func (m *WorkflowContractVersionMutation) ResetContract() {
	m.contract = nil
	m.clearedcontract = false
}

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

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

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

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

// Type returns the node type of this mutation (WorkflowContractVersion).
func (m *WorkflowContractVersionMutation) 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 *WorkflowContractVersionMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.body != nil {
		fields = append(fields, workflowcontractversion.FieldBody)
	}
	if m.raw_body != nil {
		fields = append(fields, workflowcontractversion.FieldRawBody)
	}
	if m.raw_body_format != nil {
		fields = append(fields, workflowcontractversion.FieldRawBodyFormat)
	}
	if m.revision != nil {
		fields = append(fields, workflowcontractversion.FieldRevision)
	}
	if m.created_at != nil {
		fields = append(fields, workflowcontractversion.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 *WorkflowContractVersionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case workflowcontractversion.FieldBody:
		return m.Body()
	case workflowcontractversion.FieldRawBody:
		return m.RawBody()
	case workflowcontractversion.FieldRawBodyFormat:
		return m.RawBodyFormat()
	case workflowcontractversion.FieldRevision:
		return m.Revision()
	case workflowcontractversion.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 *WorkflowContractVersionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case workflowcontractversion.FieldBody:
		return m.OldBody(ctx)
	case workflowcontractversion.FieldRawBody:
		return m.OldRawBody(ctx)
	case workflowcontractversion.FieldRawBodyFormat:
		return m.OldRawBodyFormat(ctx)
	case workflowcontractversion.FieldRevision:
		return m.OldRevision(ctx)
	case workflowcontractversion.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown WorkflowContractVersion 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 *WorkflowContractVersionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case workflowcontractversion.FieldBody:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBody(v)
		return nil
	case workflowcontractversion.FieldRawBody:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRawBody(v)
		return nil
	case workflowcontractversion.FieldRawBodyFormat:
		v, ok := value.(unmarshal.RawFormat)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRawBodyFormat(v)
		return nil
	case workflowcontractversion.FieldRevision:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRevision(v)
		return nil
	case workflowcontractversion.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 WorkflowContractVersion field %s", name)
}

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

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WorkflowContractVersionMutation) 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 *WorkflowContractVersionMutation) ClearField(name string) error {
	switch name {
	case workflowcontractversion.FieldBody:
		m.ClearBody()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContractVersion 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 *WorkflowContractVersionMutation) ResetField(name string) error {
	switch name {
	case workflowcontractversion.FieldBody:
		m.ResetBody()
		return nil
	case workflowcontractversion.FieldRawBody:
		m.ResetRawBody()
		return nil
	case workflowcontractversion.FieldRawBodyFormat:
		m.ResetRawBodyFormat()
		return nil
	case workflowcontractversion.FieldRevision:
		m.ResetRevision()
		return nil
	case workflowcontractversion.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContractVersion field %s", name)
}

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

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

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

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

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

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WorkflowContractVersionMutation) EdgeCleared(name string) bool {
	switch name {
	case workflowcontractversion.EdgeContract:
		return m.clearedcontract
	}
	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 *WorkflowContractVersionMutation) ClearEdge(name string) error {
	switch name {
	case workflowcontractversion.EdgeContract:
		m.ClearContract()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContractVersion 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 *WorkflowContractVersionMutation) ResetEdge(name string) error {
	switch name {
	case workflowcontractversion.EdgeContract:
		m.ResetContract()
		return nil
	}
	return fmt.Errorf("unknown WorkflowContractVersion edge %s", name)
}

// WorkflowRunMutation represents an operation that mutates the WorkflowRun nodes in the graph.
type WorkflowRunMutation struct {
	config
	op                          Op
	typ                         string
	id                          *uuid.UUID
	created_at                  *time.Time
	finished_at                 *time.Time
	state                       *biz.WorkflowRunStatus
	reason                      *string
	run_url                     *string
	runner_type                 *string
	attestation                 **dsse.Envelope
	attestation_digest          *string
	attestation_state           *[]byte
	contract_revision_used      *int
	addcontract_revision_used   *int
	contract_revision_latest    *int
	addcontract_revision_latest *int
	clearedFields               map[string]struct{}
	workflow                    *uuid.UUID
	clearedworkflow             bool
	contract_version            *uuid.UUID
	clearedcontract_version     bool
	cas_backends                map[uuid.UUID]struct{}
	removedcas_backends         map[uuid.UUID]struct{}
	clearedcas_backends         bool
	version                     *uuid.UUID
	clearedversion              bool
	attestation_bundle          *uuid.UUID
	clearedattestation_bundle   bool
	done                        bool
	oldValue                    func(context.Context) (*WorkflowRun, error)
	predicates                  []predicate.WorkflowRun
}

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

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

// newWorkflowRunMutation creates new mutation for the WorkflowRun entity.
func newWorkflowRunMutation(c config, op Op, opts ...workflowrunOption) *WorkflowRunMutation {
	m := &WorkflowRunMutation{
		config:        c,
		op:            op,
		typ:           TypeWorkflowRun,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

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

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

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

// SetFinishedAt sets the "finished_at" field.
func (m *WorkflowRunMutation) SetFinishedAt(t time.Time) {
	m.finished_at = &t
}

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

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

// ClearFinishedAt clears the value of the "finished_at" field.
func (m *WorkflowRunMutation) ClearFinishedAt() {
	m.finished_at = nil
	m.clearedFields[workflowrun.FieldFinishedAt] = struct{}{}
}

// FinishedAtCleared returns if the "finished_at" field was cleared in this mutation.
func (m *WorkflowRunMutation) FinishedAtCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldFinishedAt]
	return ok
}

// ResetFinishedAt resets all changes to the "finished_at" field.
func (m *WorkflowRunMutation) ResetFinishedAt() {
	m.finished_at = nil
	delete(m.clearedFields, workflowrun.FieldFinishedAt)
}

// SetState sets the "state" field.
func (m *WorkflowRunMutation) SetState(brs biz.WorkflowRunStatus) {
	m.state = &brs
}

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

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

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

// SetReason sets the "reason" field.
func (m *WorkflowRunMutation) SetReason(s string) {
	m.reason = &s
}

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

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

// ClearReason clears the value of the "reason" field.
func (m *WorkflowRunMutation) ClearReason() {
	m.reason = nil
	m.clearedFields[workflowrun.FieldReason] = struct{}{}
}

// ReasonCleared returns if the "reason" field was cleared in this mutation.
func (m *WorkflowRunMutation) ReasonCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldReason]
	return ok
}

// ResetReason resets all changes to the "reason" field.
func (m *WorkflowRunMutation) ResetReason() {
	m.reason = nil
	delete(m.clearedFields, workflowrun.FieldReason)
}

// SetRunURL sets the "run_url" field.
func (m *WorkflowRunMutation) SetRunURL(s string) {
	m.run_url = &s
}

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

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

// ClearRunURL clears the value of the "run_url" field.
func (m *WorkflowRunMutation) ClearRunURL() {
	m.run_url = nil
	m.clearedFields[workflowrun.FieldRunURL] = struct{}{}
}

// RunURLCleared returns if the "run_url" field was cleared in this mutation.
func (m *WorkflowRunMutation) RunURLCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldRunURL]
	return ok
}

// ResetRunURL resets all changes to the "run_url" field.
func (m *WorkflowRunMutation) ResetRunURL() {
	m.run_url = nil
	delete(m.clearedFields, workflowrun.FieldRunURL)
}

// SetRunnerType sets the "runner_type" field.
func (m *WorkflowRunMutation) SetRunnerType(s string) {
	m.runner_type = &s
}

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

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

// ClearRunnerType clears the value of the "runner_type" field.
func (m *WorkflowRunMutation) ClearRunnerType() {
	m.runner_type = nil
	m.clearedFields[workflowrun.FieldRunnerType] = struct{}{}
}

// RunnerTypeCleared returns if the "runner_type" field was cleared in this mutation.
func (m *WorkflowRunMutation) RunnerTypeCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldRunnerType]
	return ok
}

// ResetRunnerType resets all changes to the "runner_type" field.
func (m *WorkflowRunMutation) ResetRunnerType() {
	m.runner_type = nil
	delete(m.clearedFields, workflowrun.FieldRunnerType)
}

// SetAttestation sets the "attestation" field.
func (m *WorkflowRunMutation) SetAttestation(d *dsse.Envelope) {
	m.attestation = &d
}

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

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

// ClearAttestation clears the value of the "attestation" field.
func (m *WorkflowRunMutation) ClearAttestation() {
	m.attestation = nil
	m.clearedFields[workflowrun.FieldAttestation] = struct{}{}
}

// AttestationCleared returns if the "attestation" field was cleared in this mutation.
func (m *WorkflowRunMutation) AttestationCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldAttestation]
	return ok
}

// ResetAttestation resets all changes to the "attestation" field.
func (m *WorkflowRunMutation) ResetAttestation() {
	m.attestation = nil
	delete(m.clearedFields, workflowrun.FieldAttestation)
}

// SetAttestationDigest sets the "attestation_digest" field.
func (m *WorkflowRunMutation) SetAttestationDigest(s string) {
	m.attestation_digest = &s
}

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

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

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (m *WorkflowRunMutation) ClearAttestationDigest() {
	m.attestation_digest = nil
	m.clearedFields[workflowrun.FieldAttestationDigest] = struct{}{}
}

// AttestationDigestCleared returns if the "attestation_digest" field was cleared in this mutation.
func (m *WorkflowRunMutation) AttestationDigestCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldAttestationDigest]
	return ok
}

// ResetAttestationDigest resets all changes to the "attestation_digest" field.
func (m *WorkflowRunMutation) ResetAttestationDigest() {
	m.attestation_digest = nil
	delete(m.clearedFields, workflowrun.FieldAttestationDigest)
}

// SetAttestationState sets the "attestation_state" field.
func (m *WorkflowRunMutation) SetAttestationState(b []byte) {
	m.attestation_state = &b
}

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

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

// ClearAttestationState clears the value of the "attestation_state" field.
func (m *WorkflowRunMutation) ClearAttestationState() {
	m.attestation_state = nil
	m.clearedFields[workflowrun.FieldAttestationState] = struct{}{}
}

// AttestationStateCleared returns if the "attestation_state" field was cleared in this mutation.
func (m *WorkflowRunMutation) AttestationStateCleared() bool {
	_, ok := m.clearedFields[workflowrun.FieldAttestationState]
	return ok
}

// ResetAttestationState resets all changes to the "attestation_state" field.
func (m *WorkflowRunMutation) ResetAttestationState() {
	m.attestation_state = nil
	delete(m.clearedFields, workflowrun.FieldAttestationState)
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (m *WorkflowRunMutation) SetContractRevisionUsed(i int) {
	m.contract_revision_used = &i
	m.addcontract_revision_used = nil
}

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

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

// AddContractRevisionUsed adds i to the "contract_revision_used" field.
func (m *WorkflowRunMutation) AddContractRevisionUsed(i int) {
	if m.addcontract_revision_used != nil {
		*m.addcontract_revision_used += i
	} else {
		m.addcontract_revision_used = &i
	}
}

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

// ResetContractRevisionUsed resets all changes to the "contract_revision_used" field.
func (m *WorkflowRunMutation) ResetContractRevisionUsed() {
	m.contract_revision_used = nil
	m.addcontract_revision_used = nil
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (m *WorkflowRunMutation) SetContractRevisionLatest(i int) {
	m.contract_revision_latest = &i
	m.addcontract_revision_latest = nil
}

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

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

// AddContractRevisionLatest adds i to the "contract_revision_latest" field.
func (m *WorkflowRunMutation) AddContractRevisionLatest(i int) {
	if m.addcontract_revision_latest != nil {
		*m.addcontract_revision_latest += i
	} else {
		m.addcontract_revision_latest = &i
	}
}

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

// ResetContractRevisionLatest resets all changes to the "contract_revision_latest" field.
func (m *WorkflowRunMutation) ResetContractRevisionLatest() {
	m.contract_revision_latest = nil
	m.addcontract_revision_latest = nil
}

// SetVersionID sets the "version_id" field.
func (m *WorkflowRunMutation) SetVersionID(u uuid.UUID) {
	m.version = &u
}

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

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

// ResetVersionID resets all changes to the "version_id" field.
func (m *WorkflowRunMutation) ResetVersionID() {
	m.version = nil
}

// SetWorkflowID sets the "workflow_id" field.
func (m *WorkflowRunMutation) SetWorkflowID(u uuid.UUID) {
	m.workflow = &u
}

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

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

// ResetWorkflowID resets all changes to the "workflow_id" field.
func (m *WorkflowRunMutation) ResetWorkflowID() {
	m.workflow = nil
}

// ClearWorkflow clears the "workflow" edge to the Workflow entity.
func (m *WorkflowRunMutation) ClearWorkflow() {
	m.clearedworkflow = true
	m.clearedFields[workflowrun.FieldWorkflowID] = struct{}{}
}

// WorkflowCleared reports if the "workflow" edge to the Workflow entity was cleared.
func (m *WorkflowRunMutation) WorkflowCleared() bool {
	return m.clearedworkflow
}

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

// ResetWorkflow resets all changes to the "workflow" edge.
func (m *WorkflowRunMutation) ResetWorkflow() {
	m.workflow = nil
	m.clearedworkflow = false
}

// SetContractVersionID sets the "contract_version" edge to the WorkflowContractVersion entity by id.
func (m *WorkflowRunMutation) SetContractVersionID(id uuid.UUID) {
	m.contract_version = &id
}

// ClearContractVersion clears the "contract_version" edge to the WorkflowContractVersion entity.
func (m *WorkflowRunMutation) ClearContractVersion() {
	m.clearedcontract_version = true
}

// ContractVersionCleared reports if the "contract_version" edge to the WorkflowContractVersion entity was cleared.
func (m *WorkflowRunMutation) ContractVersionCleared() bool {
	return m.clearedcontract_version
}

// ContractVersionID returns the "contract_version" edge ID in the mutation.
func (m *WorkflowRunMutation) ContractVersionID() (id uuid.UUID, exists bool) {
	if m.contract_version != nil {
		return *m.contract_version, true
	}
	return
}

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

// ResetContractVersion resets all changes to the "contract_version" edge.
func (m *WorkflowRunMutation) ResetContractVersion() {
	m.contract_version = nil
	m.clearedcontract_version = false
}

// AddCasBackendIDs adds the "cas_backends" edge to the CASBackend entity by ids.
func (m *WorkflowRunMutation) AddCasBackendIDs(ids ...uuid.UUID) {
	if m.cas_backends == nil {
		m.cas_backends = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.cas_backends[ids[i]] = struct{}{}
	}
}

// ClearCasBackends clears the "cas_backends" edge to the CASBackend entity.
func (m *WorkflowRunMutation) ClearCasBackends() {
	m.clearedcas_backends = true
}

// CasBackendsCleared reports if the "cas_backends" edge to the CASBackend entity was cleared.
func (m *WorkflowRunMutation) CasBackendsCleared() bool {
	return m.clearedcas_backends
}

// RemoveCasBackendIDs removes the "cas_backends" edge to the CASBackend entity by IDs.
func (m *WorkflowRunMutation) RemoveCasBackendIDs(ids ...uuid.UUID) {
	if m.removedcas_backends == nil {
		m.removedcas_backends = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.cas_backends, ids[i])
		m.removedcas_backends[ids[i]] = struct{}{}
	}
}

// RemovedCasBackends returns the removed IDs of the "cas_backends" edge to the CASBackend entity.
func (m *WorkflowRunMutation) RemovedCasBackendsIDs() (ids []uuid.UUID) {
	for id := range m.removedcas_backends {
		ids = append(ids, id)
	}
	return
}

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

// ResetCasBackends resets all changes to the "cas_backends" edge.
func (m *WorkflowRunMutation) ResetCasBackends() {
	m.cas_backends = nil
	m.clearedcas_backends = false
	m.removedcas_backends = nil
}

// ClearVersion clears the "version" edge to the ProjectVersion entity.
func (m *WorkflowRunMutation) ClearVersion() {
	m.clearedversion = true
	m.clearedFields[workflowrun.FieldVersionID] = struct{}{}
}

// VersionCleared reports if the "version" edge to the ProjectVersion entity was cleared.
func (m *WorkflowRunMutation) VersionCleared() bool {
	return m.clearedversion
}

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

// ResetVersion resets all changes to the "version" edge.
func (m *WorkflowRunMutation) ResetVersion() {
	m.version = nil
	m.clearedversion = false
}

// SetAttestationBundleID sets the "attestation_bundle" edge to the Attestation entity by id.
func (m *WorkflowRunMutation) SetAttestationBundleID(id uuid.UUID) {
	m.attestation_bundle = &id
}

// ClearAttestationBundle clears the "attestation_bundle" edge to the Attestation entity.
func (m *WorkflowRunMutation) ClearAttestationBundle() {
	m.clearedattestation_bundle = true
}

// AttestationBundleCleared reports if the "attestation_bundle" edge to the Attestation entity was cleared.
func (m *WorkflowRunMutation) AttestationBundleCleared() bool {
	return m.clearedattestation_bundle
}

// AttestationBundleID returns the "attestation_bundle" edge ID in the mutation.
func (m *WorkflowRunMutation) AttestationBundleID() (id uuid.UUID, exists bool) {
	if m.attestation_bundle != nil {
		return *m.attestation_bundle, true
	}
	return
}

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

// ResetAttestationBundle resets all changes to the "attestation_bundle" edge.
func (m *WorkflowRunMutation) ResetAttestationBundle() {
	m.attestation_bundle = nil
	m.clearedattestation_bundle = false
}

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

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

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

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

// Type returns the node type of this mutation (WorkflowRun).
func (m *WorkflowRunMutation) 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 *WorkflowRunMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.created_at != nil {
		fields = append(fields, workflowrun.FieldCreatedAt)
	}
	if m.finished_at != nil {
		fields = append(fields, workflowrun.FieldFinishedAt)
	}
	if m.state != nil {
		fields = append(fields, workflowrun.FieldState)
	}
	if m.reason != nil {
		fields = append(fields, workflowrun.FieldReason)
	}
	if m.run_url != nil {
		fields = append(fields, workflowrun.FieldRunURL)
	}
	if m.runner_type != nil {
		fields = append(fields, workflowrun.FieldRunnerType)
	}
	if m.attestation != nil {
		fields = append(fields, workflowrun.FieldAttestation)
	}
	if m.attestation_digest != nil {
		fields = append(fields, workflowrun.FieldAttestationDigest)
	}
	if m.attestation_state != nil {
		fields = append(fields, workflowrun.FieldAttestationState)
	}
	if m.contract_revision_used != nil {
		fields = append(fields, workflowrun.FieldContractRevisionUsed)
	}
	if m.contract_revision_latest != nil {
		fields = append(fields, workflowrun.FieldContractRevisionLatest)
	}
	if m.version != nil {
		fields = append(fields, workflowrun.FieldVersionID)
	}
	if m.workflow != nil {
		fields = append(fields, workflowrun.FieldWorkflowID)
	}
	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 *WorkflowRunMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case workflowrun.FieldCreatedAt:
		return m.CreatedAt()
	case workflowrun.FieldFinishedAt:
		return m.FinishedAt()
	case workflowrun.FieldState:
		return m.State()
	case workflowrun.FieldReason:
		return m.Reason()
	case workflowrun.FieldRunURL:
		return m.RunURL()
	case workflowrun.FieldRunnerType:
		return m.RunnerType()
	case workflowrun.FieldAttestation:
		return m.Attestation()
	case workflowrun.FieldAttestationDigest:
		return m.AttestationDigest()
	case workflowrun.FieldAttestationState:
		return m.AttestationState()
	case workflowrun.FieldContractRevisionUsed:
		return m.ContractRevisionUsed()
	case workflowrun.FieldContractRevisionLatest:
		return m.ContractRevisionLatest()
	case workflowrun.FieldVersionID:
		return m.VersionID()
	case workflowrun.FieldWorkflowID:
		return m.WorkflowID()
	}
	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 *WorkflowRunMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case workflowrun.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case workflowrun.FieldFinishedAt:
		return m.OldFinishedAt(ctx)
	case workflowrun.FieldState:
		return m.OldState(ctx)
	case workflowrun.FieldReason:
		return m.OldReason(ctx)
	case workflowrun.FieldRunURL:
		return m.OldRunURL(ctx)
	case workflowrun.FieldRunnerType:
		return m.OldRunnerType(ctx)
	case workflowrun.FieldAttestation:
		return m.OldAttestation(ctx)
	case workflowrun.FieldAttestationDigest:
		return m.OldAttestationDigest(ctx)
	case workflowrun.FieldAttestationState:
		return m.OldAttestationState(ctx)
	case workflowrun.FieldContractRevisionUsed:
		return m.OldContractRevisionUsed(ctx)
	case workflowrun.FieldContractRevisionLatest:
		return m.OldContractRevisionLatest(ctx)
	case workflowrun.FieldVersionID:
		return m.OldVersionID(ctx)
	case workflowrun.FieldWorkflowID:
		return m.OldWorkflowID(ctx)
	}
	return nil, fmt.Errorf("unknown WorkflowRun 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 *WorkflowRunMutation) SetField(name string, value ent.Value) error {
	switch name {
	case workflowrun.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case workflowrun.FieldFinishedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFinishedAt(v)
		return nil
	case workflowrun.FieldState:
		v, ok := value.(biz.WorkflowRunStatus)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetState(v)
		return nil
	case workflowrun.FieldReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReason(v)
		return nil
	case workflowrun.FieldRunURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRunURL(v)
		return nil
	case workflowrun.FieldRunnerType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRunnerType(v)
		return nil
	case workflowrun.FieldAttestation:
		v, ok := value.(*dsse.Envelope)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAttestation(v)
		return nil
	case workflowrun.FieldAttestationDigest:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAttestationDigest(v)
		return nil
	case workflowrun.FieldAttestationState:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAttestationState(v)
		return nil
	case workflowrun.FieldContractRevisionUsed:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetContractRevisionUsed(v)
		return nil
	case workflowrun.FieldContractRevisionLatest:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetContractRevisionLatest(v)
		return nil
	case workflowrun.FieldVersionID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetVersionID(v)
		return nil
	case workflowrun.FieldWorkflowID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWorkflowID(v)
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *WorkflowRunMutation) AddedFields() []string {
	var fields []string
	if m.addcontract_revision_used != nil {
		fields = append(fields, workflowrun.FieldContractRevisionUsed)
	}
	if m.addcontract_revision_latest != nil {
		fields = append(fields, workflowrun.FieldContractRevisionLatest)
	}
	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 *WorkflowRunMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case workflowrun.FieldContractRevisionUsed:
		return m.AddedContractRevisionUsed()
	case workflowrun.FieldContractRevisionLatest:
		return m.AddedContractRevisionLatest()
	}
	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 *WorkflowRunMutation) AddField(name string, value ent.Value) error {
	switch name {
	case workflowrun.FieldContractRevisionUsed:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddContractRevisionUsed(v)
		return nil
	case workflowrun.FieldContractRevisionLatest:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddContractRevisionLatest(v)
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WorkflowRunMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(workflowrun.FieldFinishedAt) {
		fields = append(fields, workflowrun.FieldFinishedAt)
	}
	if m.FieldCleared(workflowrun.FieldReason) {
		fields = append(fields, workflowrun.FieldReason)
	}
	if m.FieldCleared(workflowrun.FieldRunURL) {
		fields = append(fields, workflowrun.FieldRunURL)
	}
	if m.FieldCleared(workflowrun.FieldRunnerType) {
		fields = append(fields, workflowrun.FieldRunnerType)
	}
	if m.FieldCleared(workflowrun.FieldAttestation) {
		fields = append(fields, workflowrun.FieldAttestation)
	}
	if m.FieldCleared(workflowrun.FieldAttestationDigest) {
		fields = append(fields, workflowrun.FieldAttestationDigest)
	}
	if m.FieldCleared(workflowrun.FieldAttestationState) {
		fields = append(fields, workflowrun.FieldAttestationState)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WorkflowRunMutation) 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 *WorkflowRunMutation) ClearField(name string) error {
	switch name {
	case workflowrun.FieldFinishedAt:
		m.ClearFinishedAt()
		return nil
	case workflowrun.FieldReason:
		m.ClearReason()
		return nil
	case workflowrun.FieldRunURL:
		m.ClearRunURL()
		return nil
	case workflowrun.FieldRunnerType:
		m.ClearRunnerType()
		return nil
	case workflowrun.FieldAttestation:
		m.ClearAttestation()
		return nil
	case workflowrun.FieldAttestationDigest:
		m.ClearAttestationDigest()
		return nil
	case workflowrun.FieldAttestationState:
		m.ClearAttestationState()
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun 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 *WorkflowRunMutation) ResetField(name string) error {
	switch name {
	case workflowrun.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case workflowrun.FieldFinishedAt:
		m.ResetFinishedAt()
		return nil
	case workflowrun.FieldState:
		m.ResetState()
		return nil
	case workflowrun.FieldReason:
		m.ResetReason()
		return nil
	case workflowrun.FieldRunURL:
		m.ResetRunURL()
		return nil
	case workflowrun.FieldRunnerType:
		m.ResetRunnerType()
		return nil
	case workflowrun.FieldAttestation:
		m.ResetAttestation()
		return nil
	case workflowrun.FieldAttestationDigest:
		m.ResetAttestationDigest()
		return nil
	case workflowrun.FieldAttestationState:
		m.ResetAttestationState()
		return nil
	case workflowrun.FieldContractRevisionUsed:
		m.ResetContractRevisionUsed()
		return nil
	case workflowrun.FieldContractRevisionLatest:
		m.ResetContractRevisionLatest()
		return nil
	case workflowrun.FieldVersionID:
		m.ResetVersionID()
		return nil
	case workflowrun.FieldWorkflowID:
		m.ResetWorkflowID()
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WorkflowRunMutation) AddedEdges() []string {
	edges := make([]string, 0, 5)
	if m.workflow != nil {
		edges = append(edges, workflowrun.EdgeWorkflow)
	}
	if m.contract_version != nil {
		edges = append(edges, workflowrun.EdgeContractVersion)
	}
	if m.cas_backends != nil {
		edges = append(edges, workflowrun.EdgeCasBackends)
	}
	if m.version != nil {
		edges = append(edges, workflowrun.EdgeVersion)
	}
	if m.attestation_bundle != nil {
		edges = append(edges, workflowrun.EdgeAttestationBundle)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WorkflowRunMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case workflowrun.EdgeWorkflow:
		if id := m.workflow; id != nil {
			return []ent.Value{*id}
		}
	case workflowrun.EdgeContractVersion:
		if id := m.contract_version; id != nil {
			return []ent.Value{*id}
		}
	case workflowrun.EdgeCasBackends:
		ids := make([]ent.Value, 0, len(m.cas_backends))
		for id := range m.cas_backends {
			ids = append(ids, id)
		}
		return ids
	case workflowrun.EdgeVersion:
		if id := m.version; id != nil {
			return []ent.Value{*id}
		}
	case workflowrun.EdgeAttestationBundle:
		if id := m.attestation_bundle; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WorkflowRunMutation) RemovedEdges() []string {
	edges := make([]string, 0, 5)
	if m.removedcas_backends != nil {
		edges = append(edges, workflowrun.EdgeCasBackends)
	}
	return edges
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WorkflowRunMutation) ClearedEdges() []string {
	edges := make([]string, 0, 5)
	if m.clearedworkflow {
		edges = append(edges, workflowrun.EdgeWorkflow)
	}
	if m.clearedcontract_version {
		edges = append(edges, workflowrun.EdgeContractVersion)
	}
	if m.clearedcas_backends {
		edges = append(edges, workflowrun.EdgeCasBackends)
	}
	if m.clearedversion {
		edges = append(edges, workflowrun.EdgeVersion)
	}
	if m.clearedattestation_bundle {
		edges = append(edges, workflowrun.EdgeAttestationBundle)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WorkflowRunMutation) EdgeCleared(name string) bool {
	switch name {
	case workflowrun.EdgeWorkflow:
		return m.clearedworkflow
	case workflowrun.EdgeContractVersion:
		return m.clearedcontract_version
	case workflowrun.EdgeCasBackends:
		return m.clearedcas_backends
	case workflowrun.EdgeVersion:
		return m.clearedversion
	case workflowrun.EdgeAttestationBundle:
		return m.clearedattestation_bundle
	}
	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 *WorkflowRunMutation) ClearEdge(name string) error {
	switch name {
	case workflowrun.EdgeWorkflow:
		m.ClearWorkflow()
		return nil
	case workflowrun.EdgeContractVersion:
		m.ClearContractVersion()
		return nil
	case workflowrun.EdgeVersion:
		m.ClearVersion()
		return nil
	case workflowrun.EdgeAttestationBundle:
		m.ClearAttestationBundle()
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun 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 *WorkflowRunMutation) ResetEdge(name string) error {
	switch name {
	case workflowrun.EdgeWorkflow:
		m.ResetWorkflow()
		return nil
	case workflowrun.EdgeContractVersion:
		m.ResetContractVersion()
		return nil
	case workflowrun.EdgeCasBackends:
		m.ResetCasBackends()
		return nil
	case workflowrun.EdgeVersion:
		m.ResetVersion()
		return nil
	case workflowrun.EdgeAttestationBundle:
		m.ResetAttestationBundle()
		return nil
	}
	return fmt.Errorf("unknown WorkflowRun edge %s", name)
}
