// Code generated by entc, DO NOT EDIT.

package ent

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

	"github.com/pingcap/test-infra/common/model"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/casetriage"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/predicate"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/resourceduration"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/testbedinfo"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/triage"

	"entgo.io/ent"
)

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

	// Node types.
	TypeCaseTriage       = "CaseTriage"
	TypeResourceDuration = "ResourceDuration"
	TypeTestbedInfo      = "TestbedInfo"
	TypeTriage           = "Triage"
)

// CaseTriageMutation represents an operation that mutates the CaseTriage nodes in the graph.
type CaseTriageMutation struct {
	config
	op                 Op
	typ                string
	id                 *model.ID
	createdAt          *time.Time
	updatedAt          *time.Time
	planExecutionID    *model.ID
	addplanExecutionID *model.ID
	planID             *model.ID
	addplanID          *model.ID
	caseExecutionID    *model.ID
	addcaseExecutionID *model.ID
	caseID             *model.ID
	addcaseID          *model.ID
	reason             *model.CaseExecFailReason
	solution           *model.ExecFailSolution
	issueLink          *string
	note               *string
	forkedFrom         *model.ID
	addforkedFrom      *model.ID
	clearedFields      map[string]struct{}
	done               bool
	oldValue           func(context.Context) (*CaseTriage, error)
	predicates         []predicate.CaseTriage
}

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

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

// newCaseTriageMutation creates new mutation for the CaseTriage entity.
func newCaseTriageMutation(c config, op Op, opts ...casetriageOption) *CaseTriageMutation {
	m := &CaseTriageMutation{
		config:        c,
		op:            op,
		typ:           TypeCaseTriage,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

// OldCreatedAt returns the old "createdAt" field's value of the CaseTriage entity.
// If the CaseTriage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CaseTriageMutation) 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 "createdAt" field.
func (m *CaseTriageMutation) ResetCreatedAt() {
	m.createdAt = nil
}

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

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

// OldUpdatedAt returns the old "updatedAt" field's value of the CaseTriage entity.
// If the CaseTriage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CaseTriageMutation) 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 "updatedAt" field.
func (m *CaseTriageMutation) ResetUpdatedAt() {
	m.updatedAt = nil
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (m *CaseTriageMutation) SetPlanExecutionID(value model.ID) {
	m.planExecutionID = &value
	m.addplanExecutionID = nil
}

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

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

// AddPlanExecutionID adds value to the "planExecutionID" field.
func (m *CaseTriageMutation) AddPlanExecutionID(value model.ID) {
	if m.addplanExecutionID != nil {
		*m.addplanExecutionID += value
	} else {
		m.addplanExecutionID = &value
	}
}

// AddedPlanExecutionID returns the value that was added to the "planExecutionID" field in this mutation.
func (m *CaseTriageMutation) AddedPlanExecutionID() (r model.ID, exists bool) {
	v := m.addplanExecutionID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanExecutionID resets all changes to the "planExecutionID" field.
func (m *CaseTriageMutation) ResetPlanExecutionID() {
	m.planExecutionID = nil
	m.addplanExecutionID = nil
}

// SetPlanID sets the "planID" field.
func (m *CaseTriageMutation) SetPlanID(value model.ID) {
	m.planID = &value
	m.addplanID = nil
}

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

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

// AddPlanID adds value to the "planID" field.
func (m *CaseTriageMutation) AddPlanID(value model.ID) {
	if m.addplanID != nil {
		*m.addplanID += value
	} else {
		m.addplanID = &value
	}
}

// AddedPlanID returns the value that was added to the "planID" field in this mutation.
func (m *CaseTriageMutation) AddedPlanID() (r model.ID, exists bool) {
	v := m.addplanID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanID resets all changes to the "planID" field.
func (m *CaseTriageMutation) ResetPlanID() {
	m.planID = nil
	m.addplanID = nil
}

// SetCaseExecutionID sets the "caseExecutionID" field.
func (m *CaseTriageMutation) SetCaseExecutionID(value model.ID) {
	m.caseExecutionID = &value
	m.addcaseExecutionID = nil
}

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

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

// AddCaseExecutionID adds value to the "caseExecutionID" field.
func (m *CaseTriageMutation) AddCaseExecutionID(value model.ID) {
	if m.addcaseExecutionID != nil {
		*m.addcaseExecutionID += value
	} else {
		m.addcaseExecutionID = &value
	}
}

// AddedCaseExecutionID returns the value that was added to the "caseExecutionID" field in this mutation.
func (m *CaseTriageMutation) AddedCaseExecutionID() (r model.ID, exists bool) {
	v := m.addcaseExecutionID
	if v == nil {
		return
	}
	return *v, true
}

// ResetCaseExecutionID resets all changes to the "caseExecutionID" field.
func (m *CaseTriageMutation) ResetCaseExecutionID() {
	m.caseExecutionID = nil
	m.addcaseExecutionID = nil
}

// SetCaseID sets the "caseID" field.
func (m *CaseTriageMutation) SetCaseID(value model.ID) {
	m.caseID = &value
	m.addcaseID = nil
}

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

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

// AddCaseID adds value to the "caseID" field.
func (m *CaseTriageMutation) AddCaseID(value model.ID) {
	if m.addcaseID != nil {
		*m.addcaseID += value
	} else {
		m.addcaseID = &value
	}
}

// AddedCaseID returns the value that was added to the "caseID" field in this mutation.
func (m *CaseTriageMutation) AddedCaseID() (r model.ID, exists bool) {
	v := m.addcaseID
	if v == nil {
		return
	}
	return *v, true
}

// ResetCaseID resets all changes to the "caseID" field.
func (m *CaseTriageMutation) ResetCaseID() {
	m.caseID = nil
	m.addcaseID = nil
}

// SetReason sets the "reason" field.
func (m *CaseTriageMutation) SetReason(mefr model.CaseExecFailReason) {
	m.reason = &mefr
}

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

// OldReason returns the old "reason" field's value of the CaseTriage entity.
// If the CaseTriage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CaseTriageMutation) OldReason(ctx context.Context) (v model.CaseExecFailReason, 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
}

// ResetReason resets all changes to the "reason" field.
func (m *CaseTriageMutation) ResetReason() {
	m.reason = nil
}

// SetSolution sets the "solution" field.
func (m *CaseTriageMutation) SetSolution(mfs model.ExecFailSolution) {
	m.solution = &mfs
}

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

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

// ResetSolution resets all changes to the "solution" field.
func (m *CaseTriageMutation) ResetSolution() {
	m.solution = nil
}

// SetIssueLink sets the "issueLink" field.
func (m *CaseTriageMutation) SetIssueLink(s string) {
	m.issueLink = &s
}

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

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

// ResetIssueLink resets all changes to the "issueLink" field.
func (m *CaseTriageMutation) ResetIssueLink() {
	m.issueLink = nil
}

// SetNote sets the "note" field.
func (m *CaseTriageMutation) SetNote(s string) {
	m.note = &s
}

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

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

// ResetNote resets all changes to the "note" field.
func (m *CaseTriageMutation) ResetNote() {
	m.note = nil
}

// SetForkedFrom sets the "forkedFrom" field.
func (m *CaseTriageMutation) SetForkedFrom(value model.ID) {
	m.forkedFrom = &value
	m.addforkedFrom = nil
}

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

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

// AddForkedFrom adds value to the "forkedFrom" field.
func (m *CaseTriageMutation) AddForkedFrom(value model.ID) {
	if m.addforkedFrom != nil {
		*m.addforkedFrom += value
	} else {
		m.addforkedFrom = &value
	}
}

// AddedForkedFrom returns the value that was added to the "forkedFrom" field in this mutation.
func (m *CaseTriageMutation) AddedForkedFrom() (r model.ID, exists bool) {
	v := m.addforkedFrom
	if v == nil {
		return
	}
	return *v, true
}

// ResetForkedFrom resets all changes to the "forkedFrom" field.
func (m *CaseTriageMutation) ResetForkedFrom() {
	m.forkedFrom = nil
	m.addforkedFrom = nil
}

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

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

// Type returns the node type of this mutation (CaseTriage).
func (m *CaseTriageMutation) 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 *CaseTriageMutation) Fields() []string {
	fields := make([]string, 0, 11)
	if m.createdAt != nil {
		fields = append(fields, casetriage.FieldCreatedAt)
	}
	if m.updatedAt != nil {
		fields = append(fields, casetriage.FieldUpdatedAt)
	}
	if m.planExecutionID != nil {
		fields = append(fields, casetriage.FieldPlanExecutionID)
	}
	if m.planID != nil {
		fields = append(fields, casetriage.FieldPlanID)
	}
	if m.caseExecutionID != nil {
		fields = append(fields, casetriage.FieldCaseExecutionID)
	}
	if m.caseID != nil {
		fields = append(fields, casetriage.FieldCaseID)
	}
	if m.reason != nil {
		fields = append(fields, casetriage.FieldReason)
	}
	if m.solution != nil {
		fields = append(fields, casetriage.FieldSolution)
	}
	if m.issueLink != nil {
		fields = append(fields, casetriage.FieldIssueLink)
	}
	if m.note != nil {
		fields = append(fields, casetriage.FieldNote)
	}
	if m.forkedFrom != nil {
		fields = append(fields, casetriage.FieldForkedFrom)
	}
	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 *CaseTriageMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case casetriage.FieldCreatedAt:
		return m.CreatedAt()
	case casetriage.FieldUpdatedAt:
		return m.UpdatedAt()
	case casetriage.FieldPlanExecutionID:
		return m.PlanExecutionID()
	case casetriage.FieldPlanID:
		return m.PlanID()
	case casetriage.FieldCaseExecutionID:
		return m.CaseExecutionID()
	case casetriage.FieldCaseID:
		return m.CaseID()
	case casetriage.FieldReason:
		return m.Reason()
	case casetriage.FieldSolution:
		return m.Solution()
	case casetriage.FieldIssueLink:
		return m.IssueLink()
	case casetriage.FieldNote:
		return m.Note()
	case casetriage.FieldForkedFrom:
		return m.ForkedFrom()
	}
	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 *CaseTriageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case casetriage.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case casetriage.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case casetriage.FieldPlanExecutionID:
		return m.OldPlanExecutionID(ctx)
	case casetriage.FieldPlanID:
		return m.OldPlanID(ctx)
	case casetriage.FieldCaseExecutionID:
		return m.OldCaseExecutionID(ctx)
	case casetriage.FieldCaseID:
		return m.OldCaseID(ctx)
	case casetriage.FieldReason:
		return m.OldReason(ctx)
	case casetriage.FieldSolution:
		return m.OldSolution(ctx)
	case casetriage.FieldIssueLink:
		return m.OldIssueLink(ctx)
	case casetriage.FieldNote:
		return m.OldNote(ctx)
	case casetriage.FieldForkedFrom:
		return m.OldForkedFrom(ctx)
	}
	return nil, fmt.Errorf("unknown CaseTriage 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 *CaseTriageMutation) SetField(name string, value ent.Value) error {
	switch name {
	case casetriage.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 casetriage.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 casetriage.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanExecutionID(v)
		return nil
	case casetriage.FieldPlanID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanID(v)
		return nil
	case casetriage.FieldCaseExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCaseExecutionID(v)
		return nil
	case casetriage.FieldCaseID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCaseID(v)
		return nil
	case casetriage.FieldReason:
		v, ok := value.(model.CaseExecFailReason)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReason(v)
		return nil
	case casetriage.FieldSolution:
		v, ok := value.(model.ExecFailSolution)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSolution(v)
		return nil
	case casetriage.FieldIssueLink:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIssueLink(v)
		return nil
	case casetriage.FieldNote:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNote(v)
		return nil
	case casetriage.FieldForkedFrom:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetForkedFrom(v)
		return nil
	}
	return fmt.Errorf("unknown CaseTriage field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CaseTriageMutation) AddedFields() []string {
	var fields []string
	if m.addplanExecutionID != nil {
		fields = append(fields, casetriage.FieldPlanExecutionID)
	}
	if m.addplanID != nil {
		fields = append(fields, casetriage.FieldPlanID)
	}
	if m.addcaseExecutionID != nil {
		fields = append(fields, casetriage.FieldCaseExecutionID)
	}
	if m.addcaseID != nil {
		fields = append(fields, casetriage.FieldCaseID)
	}
	if m.addforkedFrom != nil {
		fields = append(fields, casetriage.FieldForkedFrom)
	}
	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 *CaseTriageMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case casetriage.FieldPlanExecutionID:
		return m.AddedPlanExecutionID()
	case casetriage.FieldPlanID:
		return m.AddedPlanID()
	case casetriage.FieldCaseExecutionID:
		return m.AddedCaseExecutionID()
	case casetriage.FieldCaseID:
		return m.AddedCaseID()
	case casetriage.FieldForkedFrom:
		return m.AddedForkedFrom()
	}
	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 *CaseTriageMutation) AddField(name string, value ent.Value) error {
	switch name {
	case casetriage.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanExecutionID(v)
		return nil
	case casetriage.FieldPlanID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanID(v)
		return nil
	case casetriage.FieldCaseExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCaseExecutionID(v)
		return nil
	case casetriage.FieldCaseID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCaseID(v)
		return nil
	case casetriage.FieldForkedFrom:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddForkedFrom(v)
		return nil
	}
	return fmt.Errorf("unknown CaseTriage numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CaseTriageMutation) 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 *CaseTriageMutation) ClearField(name string) error {
	return fmt.Errorf("unknown CaseTriage 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 *CaseTriageMutation) ResetField(name string) error {
	switch name {
	case casetriage.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case casetriage.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case casetriage.FieldPlanExecutionID:
		m.ResetPlanExecutionID()
		return nil
	case casetriage.FieldPlanID:
		m.ResetPlanID()
		return nil
	case casetriage.FieldCaseExecutionID:
		m.ResetCaseExecutionID()
		return nil
	case casetriage.FieldCaseID:
		m.ResetCaseID()
		return nil
	case casetriage.FieldReason:
		m.ResetReason()
		return nil
	case casetriage.FieldSolution:
		m.ResetSolution()
		return nil
	case casetriage.FieldIssueLink:
		m.ResetIssueLink()
		return nil
	case casetriage.FieldNote:
		m.ResetNote()
		return nil
	case casetriage.FieldForkedFrom:
		m.ResetForkedFrom()
		return nil
	}
	return fmt.Errorf("unknown CaseTriage field %s", name)
}

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

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

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

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

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

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

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

// ResourceDurationMutation represents an operation that mutates the ResourceDuration nodes in the graph.
type ResourceDurationMutation struct {
	config
	op                 Op
	typ                string
	id                 *model.ID
	createdAt          *time.Time
	updatedAt          *time.Time
	planExecutionID    *model.ID
	addplanExecutionID *model.ID
	_type              *model.ResourceDurationType
	cpuDuration        *uint64
	addcpuDuration     *int64
	memoryDuration     *uint64
	addmemoryDuration  *int64
	clearedFields      map[string]struct{}
	done               bool
	oldValue           func(context.Context) (*ResourceDuration, error)
	predicates         []predicate.ResourceDuration
}

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

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

// newResourceDurationMutation creates new mutation for the ResourceDuration entity.
func newResourceDurationMutation(c config, op Op, opts ...resourcedurationOption) *ResourceDurationMutation {
	m := &ResourceDurationMutation{
		config:        c,
		op:            op,
		typ:           TypeResourceDuration,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

// OldCreatedAt returns the old "createdAt" field's value of the ResourceDuration entity.
// If the ResourceDuration object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ResourceDurationMutation) 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 "createdAt" field.
func (m *ResourceDurationMutation) ResetCreatedAt() {
	m.createdAt = nil
}

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

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

// OldUpdatedAt returns the old "updatedAt" field's value of the ResourceDuration entity.
// If the ResourceDuration object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ResourceDurationMutation) 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 "updatedAt" field.
func (m *ResourceDurationMutation) ResetUpdatedAt() {
	m.updatedAt = nil
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (m *ResourceDurationMutation) SetPlanExecutionID(value model.ID) {
	m.planExecutionID = &value
	m.addplanExecutionID = nil
}

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

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

// AddPlanExecutionID adds value to the "planExecutionID" field.
func (m *ResourceDurationMutation) AddPlanExecutionID(value model.ID) {
	if m.addplanExecutionID != nil {
		*m.addplanExecutionID += value
	} else {
		m.addplanExecutionID = &value
	}
}

// AddedPlanExecutionID returns the value that was added to the "planExecutionID" field in this mutation.
func (m *ResourceDurationMutation) AddedPlanExecutionID() (r model.ID, exists bool) {
	v := m.addplanExecutionID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanExecutionID resets all changes to the "planExecutionID" field.
func (m *ResourceDurationMutation) ResetPlanExecutionID() {
	m.planExecutionID = nil
	m.addplanExecutionID = nil
}

// SetType sets the "type" field.
func (m *ResourceDurationMutation) SetType(mdt model.ResourceDurationType) {
	m._type = &mdt
}

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

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

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

// SetCpuDuration sets the "cpuDuration" field.
func (m *ResourceDurationMutation) SetCpuDuration(u uint64) {
	m.cpuDuration = &u
	m.addcpuDuration = nil
}

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

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

// AddCpuDuration adds u to the "cpuDuration" field.
func (m *ResourceDurationMutation) AddCpuDuration(u int64) {
	if m.addcpuDuration != nil {
		*m.addcpuDuration += u
	} else {
		m.addcpuDuration = &u
	}
}

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

// ResetCpuDuration resets all changes to the "cpuDuration" field.
func (m *ResourceDurationMutation) ResetCpuDuration() {
	m.cpuDuration = nil
	m.addcpuDuration = nil
}

// SetMemoryDuration sets the "memoryDuration" field.
func (m *ResourceDurationMutation) SetMemoryDuration(u uint64) {
	m.memoryDuration = &u
	m.addmemoryDuration = nil
}

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

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

// AddMemoryDuration adds u to the "memoryDuration" field.
func (m *ResourceDurationMutation) AddMemoryDuration(u int64) {
	if m.addmemoryDuration != nil {
		*m.addmemoryDuration += u
	} else {
		m.addmemoryDuration = &u
	}
}

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

// ResetMemoryDuration resets all changes to the "memoryDuration" field.
func (m *ResourceDurationMutation) ResetMemoryDuration() {
	m.memoryDuration = nil
	m.addmemoryDuration = nil
}

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

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

// Type returns the node type of this mutation (ResourceDuration).
func (m *ResourceDurationMutation) 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 *ResourceDurationMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.createdAt != nil {
		fields = append(fields, resourceduration.FieldCreatedAt)
	}
	if m.updatedAt != nil {
		fields = append(fields, resourceduration.FieldUpdatedAt)
	}
	if m.planExecutionID != nil {
		fields = append(fields, resourceduration.FieldPlanExecutionID)
	}
	if m._type != nil {
		fields = append(fields, resourceduration.FieldType)
	}
	if m.cpuDuration != nil {
		fields = append(fields, resourceduration.FieldCpuDuration)
	}
	if m.memoryDuration != nil {
		fields = append(fields, resourceduration.FieldMemoryDuration)
	}
	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 *ResourceDurationMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case resourceduration.FieldCreatedAt:
		return m.CreatedAt()
	case resourceduration.FieldUpdatedAt:
		return m.UpdatedAt()
	case resourceduration.FieldPlanExecutionID:
		return m.PlanExecutionID()
	case resourceduration.FieldType:
		return m.GetType()
	case resourceduration.FieldCpuDuration:
		return m.CpuDuration()
	case resourceduration.FieldMemoryDuration:
		return m.MemoryDuration()
	}
	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 *ResourceDurationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case resourceduration.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case resourceduration.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case resourceduration.FieldPlanExecutionID:
		return m.OldPlanExecutionID(ctx)
	case resourceduration.FieldType:
		return m.OldType(ctx)
	case resourceduration.FieldCpuDuration:
		return m.OldCpuDuration(ctx)
	case resourceduration.FieldMemoryDuration:
		return m.OldMemoryDuration(ctx)
	}
	return nil, fmt.Errorf("unknown ResourceDuration 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 *ResourceDurationMutation) SetField(name string, value ent.Value) error {
	switch name {
	case resourceduration.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 resourceduration.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 resourceduration.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanExecutionID(v)
		return nil
	case resourceduration.FieldType:
		v, ok := value.(model.ResourceDurationType)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case resourceduration.FieldCpuDuration:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCpuDuration(v)
		return nil
	case resourceduration.FieldMemoryDuration:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMemoryDuration(v)
		return nil
	}
	return fmt.Errorf("unknown ResourceDuration field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ResourceDurationMutation) AddedFields() []string {
	var fields []string
	if m.addplanExecutionID != nil {
		fields = append(fields, resourceduration.FieldPlanExecutionID)
	}
	if m.addcpuDuration != nil {
		fields = append(fields, resourceduration.FieldCpuDuration)
	}
	if m.addmemoryDuration != nil {
		fields = append(fields, resourceduration.FieldMemoryDuration)
	}
	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 *ResourceDurationMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case resourceduration.FieldPlanExecutionID:
		return m.AddedPlanExecutionID()
	case resourceduration.FieldCpuDuration:
		return m.AddedCpuDuration()
	case resourceduration.FieldMemoryDuration:
		return m.AddedMemoryDuration()
	}
	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 *ResourceDurationMutation) AddField(name string, value ent.Value) error {
	switch name {
	case resourceduration.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanExecutionID(v)
		return nil
	case resourceduration.FieldCpuDuration:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCpuDuration(v)
		return nil
	case resourceduration.FieldMemoryDuration:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddMemoryDuration(v)
		return nil
	}
	return fmt.Errorf("unknown ResourceDuration numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ResourceDurationMutation) 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 *ResourceDurationMutation) ClearField(name string) error {
	return fmt.Errorf("unknown ResourceDuration 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 *ResourceDurationMutation) ResetField(name string) error {
	switch name {
	case resourceduration.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case resourceduration.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case resourceduration.FieldPlanExecutionID:
		m.ResetPlanExecutionID()
		return nil
	case resourceduration.FieldType:
		m.ResetType()
		return nil
	case resourceduration.FieldCpuDuration:
		m.ResetCpuDuration()
		return nil
	case resourceduration.FieldMemoryDuration:
		m.ResetMemoryDuration()
		return nil
	}
	return fmt.Errorf("unknown ResourceDuration field %s", name)
}

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

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

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

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

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

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

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

// TestbedInfoMutation represents an operation that mutates the TestbedInfo nodes in the graph.
type TestbedInfoMutation struct {
	config
	op                      Op
	typ                     string
	id                      *model.ID
	createdAt               *time.Time
	updatedAt               *time.Time
	name                    *string
	status                  *model.TestBedInfoStatus
	planExecutionID         *model.ID
	addplanExecutionID      *model.ID
	url                     *string
	leaseDDL                *time.Time
	initiatedAt             *time.Time
	releasedAt              *time.Time
	releasedBy              *model.ID
	addreleasedBy           *model.ID
	physicalResourceRequest *model.PhysicalResource
	resourceItems           *[]model.TestBedInfoResourceItem
	_type                   *model.TestBedInfoType
	setUpLogURL             *string
	resourcePoolID          *model.ID
	addresourcePoolID       *model.ID
	clearedFields           map[string]struct{}
	done                    bool
	oldValue                func(context.Context) (*TestbedInfo, error)
	predicates              []predicate.TestbedInfo
}

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

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

// newTestbedInfoMutation creates new mutation for the TestbedInfo entity.
func newTestbedInfoMutation(c config, op Op, opts ...testbedinfoOption) *TestbedInfoMutation {
	m := &TestbedInfoMutation{
		config:        c,
		op:            op,
		typ:           TypeTestbedInfo,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

// OldCreatedAt returns the old "createdAt" field's value of the TestbedInfo entity.
// If the TestbedInfo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TestbedInfoMutation) 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 "createdAt" field.
func (m *TestbedInfoMutation) ResetCreatedAt() {
	m.createdAt = nil
}

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

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

// OldUpdatedAt returns the old "updatedAt" field's value of the TestbedInfo entity.
// If the TestbedInfo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TestbedInfoMutation) 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 "updatedAt" field.
func (m *TestbedInfoMutation) ResetUpdatedAt() {
	m.updatedAt = nil
}

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

// Name returns the value of the "name" field in the mutation.
func (m *TestbedInfoMutation) 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 TestbedInfo entity.
// If the TestbedInfo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TestbedInfoMutation) 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 *TestbedInfoMutation) ResetName() {
	m.name = nil
}

// SetStatus sets the "status" field.
func (m *TestbedInfoMutation) SetStatus(mbis model.TestBedInfoStatus) {
	m.status = &mbis
}

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

// OldStatus returns the old "status" field's value of the TestbedInfo entity.
// If the TestbedInfo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TestbedInfoMutation) OldStatus(ctx context.Context) (v model.TestBedInfoStatus, 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 *TestbedInfoMutation) ResetStatus() {
	m.status = nil
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (m *TestbedInfoMutation) SetPlanExecutionID(value model.ID) {
	m.planExecutionID = &value
	m.addplanExecutionID = nil
}

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

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

// AddPlanExecutionID adds value to the "planExecutionID" field.
func (m *TestbedInfoMutation) AddPlanExecutionID(value model.ID) {
	if m.addplanExecutionID != nil {
		*m.addplanExecutionID += value
	} else {
		m.addplanExecutionID = &value
	}
}

// AddedPlanExecutionID returns the value that was added to the "planExecutionID" field in this mutation.
func (m *TestbedInfoMutation) AddedPlanExecutionID() (r model.ID, exists bool) {
	v := m.addplanExecutionID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanExecutionID resets all changes to the "planExecutionID" field.
func (m *TestbedInfoMutation) ResetPlanExecutionID() {
	m.planExecutionID = nil
	m.addplanExecutionID = nil
}

// SetURL sets the "url" field.
func (m *TestbedInfoMutation) SetURL(s string) {
	m.url = &s
}

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

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

// ResetURL resets all changes to the "url" field.
func (m *TestbedInfoMutation) ResetURL() {
	m.url = nil
}

// SetLeaseDDL sets the "leaseDDL" field.
func (m *TestbedInfoMutation) SetLeaseDDL(t time.Time) {
	m.leaseDDL = &t
}

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

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

// ClearLeaseDDL clears the value of the "leaseDDL" field.
func (m *TestbedInfoMutation) ClearLeaseDDL() {
	m.leaseDDL = nil
	m.clearedFields[testbedinfo.FieldLeaseDDL] = struct{}{}
}

// LeaseDDLCleared returns if the "leaseDDL" field was cleared in this mutation.
func (m *TestbedInfoMutation) LeaseDDLCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldLeaseDDL]
	return ok
}

// ResetLeaseDDL resets all changes to the "leaseDDL" field.
func (m *TestbedInfoMutation) ResetLeaseDDL() {
	m.leaseDDL = nil
	delete(m.clearedFields, testbedinfo.FieldLeaseDDL)
}

// SetInitiatedAt sets the "initiatedAt" field.
func (m *TestbedInfoMutation) SetInitiatedAt(t time.Time) {
	m.initiatedAt = &t
}

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

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

// ClearInitiatedAt clears the value of the "initiatedAt" field.
func (m *TestbedInfoMutation) ClearInitiatedAt() {
	m.initiatedAt = nil
	m.clearedFields[testbedinfo.FieldInitiatedAt] = struct{}{}
}

// InitiatedAtCleared returns if the "initiatedAt" field was cleared in this mutation.
func (m *TestbedInfoMutation) InitiatedAtCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldInitiatedAt]
	return ok
}

// ResetInitiatedAt resets all changes to the "initiatedAt" field.
func (m *TestbedInfoMutation) ResetInitiatedAt() {
	m.initiatedAt = nil
	delete(m.clearedFields, testbedinfo.FieldInitiatedAt)
}

// SetReleasedAt sets the "releasedAt" field.
func (m *TestbedInfoMutation) SetReleasedAt(t time.Time) {
	m.releasedAt = &t
}

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

// OldReleasedAt returns the old "releasedAt" field's value of the TestbedInfo entity.
// If the TestbedInfo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TestbedInfoMutation) 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 "releasedAt" field.
func (m *TestbedInfoMutation) ClearReleasedAt() {
	m.releasedAt = nil
	m.clearedFields[testbedinfo.FieldReleasedAt] = struct{}{}
}

// ReleasedAtCleared returns if the "releasedAt" field was cleared in this mutation.
func (m *TestbedInfoMutation) ReleasedAtCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldReleasedAt]
	return ok
}

// ResetReleasedAt resets all changes to the "releasedAt" field.
func (m *TestbedInfoMutation) ResetReleasedAt() {
	m.releasedAt = nil
	delete(m.clearedFields, testbedinfo.FieldReleasedAt)
}

// SetReleasedBy sets the "releasedBy" field.
func (m *TestbedInfoMutation) SetReleasedBy(value model.ID) {
	m.releasedBy = &value
	m.addreleasedBy = nil
}

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

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

// AddReleasedBy adds value to the "releasedBy" field.
func (m *TestbedInfoMutation) AddReleasedBy(value model.ID) {
	if m.addreleasedBy != nil {
		*m.addreleasedBy += value
	} else {
		m.addreleasedBy = &value
	}
}

// AddedReleasedBy returns the value that was added to the "releasedBy" field in this mutation.
func (m *TestbedInfoMutation) AddedReleasedBy() (r model.ID, exists bool) {
	v := m.addreleasedBy
	if v == nil {
		return
	}
	return *v, true
}

// ClearReleasedBy clears the value of the "releasedBy" field.
func (m *TestbedInfoMutation) ClearReleasedBy() {
	m.releasedBy = nil
	m.addreleasedBy = nil
	m.clearedFields[testbedinfo.FieldReleasedBy] = struct{}{}
}

// ReleasedByCleared returns if the "releasedBy" field was cleared in this mutation.
func (m *TestbedInfoMutation) ReleasedByCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldReleasedBy]
	return ok
}

// ResetReleasedBy resets all changes to the "releasedBy" field.
func (m *TestbedInfoMutation) ResetReleasedBy() {
	m.releasedBy = nil
	m.addreleasedBy = nil
	delete(m.clearedFields, testbedinfo.FieldReleasedBy)
}

// SetPhysicalResourceRequest sets the "physicalResourceRequest" field.
func (m *TestbedInfoMutation) SetPhysicalResourceRequest(mr model.PhysicalResource) {
	m.physicalResourceRequest = &mr
}

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

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

// ClearPhysicalResourceRequest clears the value of the "physicalResourceRequest" field.
func (m *TestbedInfoMutation) ClearPhysicalResourceRequest() {
	m.physicalResourceRequest = nil
	m.clearedFields[testbedinfo.FieldPhysicalResourceRequest] = struct{}{}
}

// PhysicalResourceRequestCleared returns if the "physicalResourceRequest" field was cleared in this mutation.
func (m *TestbedInfoMutation) PhysicalResourceRequestCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldPhysicalResourceRequest]
	return ok
}

// ResetPhysicalResourceRequest resets all changes to the "physicalResourceRequest" field.
func (m *TestbedInfoMutation) ResetPhysicalResourceRequest() {
	m.physicalResourceRequest = nil
	delete(m.clearedFields, testbedinfo.FieldPhysicalResourceRequest)
}

// SetResourceItems sets the "resourceItems" field.
func (m *TestbedInfoMutation) SetResourceItems(mbiri []model.TestBedInfoResourceItem) {
	m.resourceItems = &mbiri
}

// ResourceItems returns the value of the "resourceItems" field in the mutation.
func (m *TestbedInfoMutation) ResourceItems() (r []model.TestBedInfoResourceItem, exists bool) {
	v := m.resourceItems
	if v == nil {
		return
	}
	return *v, true
}

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

// ClearResourceItems clears the value of the "resourceItems" field.
func (m *TestbedInfoMutation) ClearResourceItems() {
	m.resourceItems = nil
	m.clearedFields[testbedinfo.FieldResourceItems] = struct{}{}
}

// ResourceItemsCleared returns if the "resourceItems" field was cleared in this mutation.
func (m *TestbedInfoMutation) ResourceItemsCleared() bool {
	_, ok := m.clearedFields[testbedinfo.FieldResourceItems]
	return ok
}

// ResetResourceItems resets all changes to the "resourceItems" field.
func (m *TestbedInfoMutation) ResetResourceItems() {
	m.resourceItems = nil
	delete(m.clearedFields, testbedinfo.FieldResourceItems)
}

// SetType sets the "type" field.
func (m *TestbedInfoMutation) SetType(mbit model.TestBedInfoType) {
	m._type = &mbit
}

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

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

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

// SetSetUpLogURL sets the "setUpLogURL" field.
func (m *TestbedInfoMutation) SetSetUpLogURL(s string) {
	m.setUpLogURL = &s
}

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

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

// ResetSetUpLogURL resets all changes to the "setUpLogURL" field.
func (m *TestbedInfoMutation) ResetSetUpLogURL() {
	m.setUpLogURL = nil
}

// SetResourcePoolID sets the "resourcePoolID" field.
func (m *TestbedInfoMutation) SetResourcePoolID(value model.ID) {
	m.resourcePoolID = &value
	m.addresourcePoolID = nil
}

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

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

// AddResourcePoolID adds value to the "resourcePoolID" field.
func (m *TestbedInfoMutation) AddResourcePoolID(value model.ID) {
	if m.addresourcePoolID != nil {
		*m.addresourcePoolID += value
	} else {
		m.addresourcePoolID = &value
	}
}

// AddedResourcePoolID returns the value that was added to the "resourcePoolID" field in this mutation.
func (m *TestbedInfoMutation) AddedResourcePoolID() (r model.ID, exists bool) {
	v := m.addresourcePoolID
	if v == nil {
		return
	}
	return *v, true
}

// ResetResourcePoolID resets all changes to the "resourcePoolID" field.
func (m *TestbedInfoMutation) ResetResourcePoolID() {
	m.resourcePoolID = nil
	m.addresourcePoolID = nil
}

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

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

// Type returns the node type of this mutation (TestbedInfo).
func (m *TestbedInfoMutation) 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 *TestbedInfoMutation) Fields() []string {
	fields := make([]string, 0, 15)
	if m.createdAt != nil {
		fields = append(fields, testbedinfo.FieldCreatedAt)
	}
	if m.updatedAt != nil {
		fields = append(fields, testbedinfo.FieldUpdatedAt)
	}
	if m.name != nil {
		fields = append(fields, testbedinfo.FieldName)
	}
	if m.status != nil {
		fields = append(fields, testbedinfo.FieldStatus)
	}
	if m.planExecutionID != nil {
		fields = append(fields, testbedinfo.FieldPlanExecutionID)
	}
	if m.url != nil {
		fields = append(fields, testbedinfo.FieldURL)
	}
	if m.leaseDDL != nil {
		fields = append(fields, testbedinfo.FieldLeaseDDL)
	}
	if m.initiatedAt != nil {
		fields = append(fields, testbedinfo.FieldInitiatedAt)
	}
	if m.releasedAt != nil {
		fields = append(fields, testbedinfo.FieldReleasedAt)
	}
	if m.releasedBy != nil {
		fields = append(fields, testbedinfo.FieldReleasedBy)
	}
	if m.physicalResourceRequest != nil {
		fields = append(fields, testbedinfo.FieldPhysicalResourceRequest)
	}
	if m.resourceItems != nil {
		fields = append(fields, testbedinfo.FieldResourceItems)
	}
	if m._type != nil {
		fields = append(fields, testbedinfo.FieldType)
	}
	if m.setUpLogURL != nil {
		fields = append(fields, testbedinfo.FieldSetUpLogURL)
	}
	if m.resourcePoolID != nil {
		fields = append(fields, testbedinfo.FieldResourcePoolID)
	}
	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 *TestbedInfoMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case testbedinfo.FieldCreatedAt:
		return m.CreatedAt()
	case testbedinfo.FieldUpdatedAt:
		return m.UpdatedAt()
	case testbedinfo.FieldName:
		return m.Name()
	case testbedinfo.FieldStatus:
		return m.Status()
	case testbedinfo.FieldPlanExecutionID:
		return m.PlanExecutionID()
	case testbedinfo.FieldURL:
		return m.URL()
	case testbedinfo.FieldLeaseDDL:
		return m.LeaseDDL()
	case testbedinfo.FieldInitiatedAt:
		return m.InitiatedAt()
	case testbedinfo.FieldReleasedAt:
		return m.ReleasedAt()
	case testbedinfo.FieldReleasedBy:
		return m.ReleasedBy()
	case testbedinfo.FieldPhysicalResourceRequest:
		return m.PhysicalResourceRequest()
	case testbedinfo.FieldResourceItems:
		return m.ResourceItems()
	case testbedinfo.FieldType:
		return m.GetType()
	case testbedinfo.FieldSetUpLogURL:
		return m.SetUpLogURL()
	case testbedinfo.FieldResourcePoolID:
		return m.ResourcePoolID()
	}
	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 *TestbedInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case testbedinfo.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case testbedinfo.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case testbedinfo.FieldName:
		return m.OldName(ctx)
	case testbedinfo.FieldStatus:
		return m.OldStatus(ctx)
	case testbedinfo.FieldPlanExecutionID:
		return m.OldPlanExecutionID(ctx)
	case testbedinfo.FieldURL:
		return m.OldURL(ctx)
	case testbedinfo.FieldLeaseDDL:
		return m.OldLeaseDDL(ctx)
	case testbedinfo.FieldInitiatedAt:
		return m.OldInitiatedAt(ctx)
	case testbedinfo.FieldReleasedAt:
		return m.OldReleasedAt(ctx)
	case testbedinfo.FieldReleasedBy:
		return m.OldReleasedBy(ctx)
	case testbedinfo.FieldPhysicalResourceRequest:
		return m.OldPhysicalResourceRequest(ctx)
	case testbedinfo.FieldResourceItems:
		return m.OldResourceItems(ctx)
	case testbedinfo.FieldType:
		return m.OldType(ctx)
	case testbedinfo.FieldSetUpLogURL:
		return m.OldSetUpLogURL(ctx)
	case testbedinfo.FieldResourcePoolID:
		return m.OldResourcePoolID(ctx)
	}
	return nil, fmt.Errorf("unknown TestbedInfo 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 *TestbedInfoMutation) SetField(name string, value ent.Value) error {
	switch name {
	case testbedinfo.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 testbedinfo.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 testbedinfo.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case testbedinfo.FieldStatus:
		v, ok := value.(model.TestBedInfoStatus)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case testbedinfo.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanExecutionID(v)
		return nil
	case testbedinfo.FieldURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetURL(v)
		return nil
	case testbedinfo.FieldLeaseDDL:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLeaseDDL(v)
		return nil
	case testbedinfo.FieldInitiatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInitiatedAt(v)
		return nil
	case testbedinfo.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 testbedinfo.FieldReleasedBy:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReleasedBy(v)
		return nil
	case testbedinfo.FieldPhysicalResourceRequest:
		v, ok := value.(model.PhysicalResource)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPhysicalResourceRequest(v)
		return nil
	case testbedinfo.FieldResourceItems:
		v, ok := value.([]model.TestBedInfoResourceItem)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResourceItems(v)
		return nil
	case testbedinfo.FieldType:
		v, ok := value.(model.TestBedInfoType)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case testbedinfo.FieldSetUpLogURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSetUpLogURL(v)
		return nil
	case testbedinfo.FieldResourcePoolID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResourcePoolID(v)
		return nil
	}
	return fmt.Errorf("unknown TestbedInfo field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *TestbedInfoMutation) AddedFields() []string {
	var fields []string
	if m.addplanExecutionID != nil {
		fields = append(fields, testbedinfo.FieldPlanExecutionID)
	}
	if m.addreleasedBy != nil {
		fields = append(fields, testbedinfo.FieldReleasedBy)
	}
	if m.addresourcePoolID != nil {
		fields = append(fields, testbedinfo.FieldResourcePoolID)
	}
	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 *TestbedInfoMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case testbedinfo.FieldPlanExecutionID:
		return m.AddedPlanExecutionID()
	case testbedinfo.FieldReleasedBy:
		return m.AddedReleasedBy()
	case testbedinfo.FieldResourcePoolID:
		return m.AddedResourcePoolID()
	}
	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 *TestbedInfoMutation) AddField(name string, value ent.Value) error {
	switch name {
	case testbedinfo.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanExecutionID(v)
		return nil
	case testbedinfo.FieldReleasedBy:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddReleasedBy(v)
		return nil
	case testbedinfo.FieldResourcePoolID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddResourcePoolID(v)
		return nil
	}
	return fmt.Errorf("unknown TestbedInfo numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *TestbedInfoMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(testbedinfo.FieldLeaseDDL) {
		fields = append(fields, testbedinfo.FieldLeaseDDL)
	}
	if m.FieldCleared(testbedinfo.FieldInitiatedAt) {
		fields = append(fields, testbedinfo.FieldInitiatedAt)
	}
	if m.FieldCleared(testbedinfo.FieldReleasedAt) {
		fields = append(fields, testbedinfo.FieldReleasedAt)
	}
	if m.FieldCleared(testbedinfo.FieldReleasedBy) {
		fields = append(fields, testbedinfo.FieldReleasedBy)
	}
	if m.FieldCleared(testbedinfo.FieldPhysicalResourceRequest) {
		fields = append(fields, testbedinfo.FieldPhysicalResourceRequest)
	}
	if m.FieldCleared(testbedinfo.FieldResourceItems) {
		fields = append(fields, testbedinfo.FieldResourceItems)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *TestbedInfoMutation) 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 *TestbedInfoMutation) ClearField(name string) error {
	switch name {
	case testbedinfo.FieldLeaseDDL:
		m.ClearLeaseDDL()
		return nil
	case testbedinfo.FieldInitiatedAt:
		m.ClearInitiatedAt()
		return nil
	case testbedinfo.FieldReleasedAt:
		m.ClearReleasedAt()
		return nil
	case testbedinfo.FieldReleasedBy:
		m.ClearReleasedBy()
		return nil
	case testbedinfo.FieldPhysicalResourceRequest:
		m.ClearPhysicalResourceRequest()
		return nil
	case testbedinfo.FieldResourceItems:
		m.ClearResourceItems()
		return nil
	}
	return fmt.Errorf("unknown TestbedInfo 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 *TestbedInfoMutation) ResetField(name string) error {
	switch name {
	case testbedinfo.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case testbedinfo.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case testbedinfo.FieldName:
		m.ResetName()
		return nil
	case testbedinfo.FieldStatus:
		m.ResetStatus()
		return nil
	case testbedinfo.FieldPlanExecutionID:
		m.ResetPlanExecutionID()
		return nil
	case testbedinfo.FieldURL:
		m.ResetURL()
		return nil
	case testbedinfo.FieldLeaseDDL:
		m.ResetLeaseDDL()
		return nil
	case testbedinfo.FieldInitiatedAt:
		m.ResetInitiatedAt()
		return nil
	case testbedinfo.FieldReleasedAt:
		m.ResetReleasedAt()
		return nil
	case testbedinfo.FieldReleasedBy:
		m.ResetReleasedBy()
		return nil
	case testbedinfo.FieldPhysicalResourceRequest:
		m.ResetPhysicalResourceRequest()
		return nil
	case testbedinfo.FieldResourceItems:
		m.ResetResourceItems()
		return nil
	case testbedinfo.FieldType:
		m.ResetType()
		return nil
	case testbedinfo.FieldSetUpLogURL:
		m.ResetSetUpLogURL()
		return nil
	case testbedinfo.FieldResourcePoolID:
		m.ResetResourcePoolID()
		return nil
	}
	return fmt.Errorf("unknown TestbedInfo field %s", name)
}

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

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

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

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

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

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

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

// TriageMutation represents an operation that mutates the Triage nodes in the graph.
type TriageMutation struct {
	config
	op                  Op
	typ                 string
	id                  *model.ID
	createdAt           *time.Time
	updatedAt           *time.Time
	planExecutionID     *model.ID
	addplanExecutionID  *model.ID
	planID              *model.ID
	addplanID           *model.ID
	triagingUsers       *[]model.ID
	toTriageCaseExecIDs *[]model.ID
	triagedCaseExecIDs  *[]model.ID
	triagePhase         *model.TriagePhase
	startedAt           *time.Time
	triagedAt           *time.Time
	reasons             *[]model.CaseExecFailReason
	solution            *model.ExecFailSolution
	note                *string
	clearedFields       map[string]struct{}
	done                bool
	oldValue            func(context.Context) (*Triage, error)
	predicates          []predicate.Triage
}

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

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

// newTriageMutation creates new mutation for the Triage entity.
func newTriageMutation(c config, op Op, opts ...triageOption) *TriageMutation {
	m := &TriageMutation{
		config:        c,
		op:            op,
		typ:           TypeTriage,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

// OldCreatedAt returns the old "createdAt" field's value of the Triage entity.
// If the Triage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TriageMutation) 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 "createdAt" field.
func (m *TriageMutation) ResetCreatedAt() {
	m.createdAt = nil
}

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

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

// OldUpdatedAt returns the old "updatedAt" field's value of the Triage entity.
// If the Triage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TriageMutation) 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 "updatedAt" field.
func (m *TriageMutation) ResetUpdatedAt() {
	m.updatedAt = nil
}

// SetPlanExecutionID sets the "planExecutionID" field.
func (m *TriageMutation) SetPlanExecutionID(value model.ID) {
	m.planExecutionID = &value
	m.addplanExecutionID = nil
}

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

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

// AddPlanExecutionID adds value to the "planExecutionID" field.
func (m *TriageMutation) AddPlanExecutionID(value model.ID) {
	if m.addplanExecutionID != nil {
		*m.addplanExecutionID += value
	} else {
		m.addplanExecutionID = &value
	}
}

// AddedPlanExecutionID returns the value that was added to the "planExecutionID" field in this mutation.
func (m *TriageMutation) AddedPlanExecutionID() (r model.ID, exists bool) {
	v := m.addplanExecutionID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanExecutionID resets all changes to the "planExecutionID" field.
func (m *TriageMutation) ResetPlanExecutionID() {
	m.planExecutionID = nil
	m.addplanExecutionID = nil
}

// SetPlanID sets the "planID" field.
func (m *TriageMutation) SetPlanID(value model.ID) {
	m.planID = &value
	m.addplanID = nil
}

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

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

// AddPlanID adds value to the "planID" field.
func (m *TriageMutation) AddPlanID(value model.ID) {
	if m.addplanID != nil {
		*m.addplanID += value
	} else {
		m.addplanID = &value
	}
}

// AddedPlanID returns the value that was added to the "planID" field in this mutation.
func (m *TriageMutation) AddedPlanID() (r model.ID, exists bool) {
	v := m.addplanID
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlanID resets all changes to the "planID" field.
func (m *TriageMutation) ResetPlanID() {
	m.planID = nil
	m.addplanID = nil
}

// SetTriagingUsers sets the "triagingUsers" field.
func (m *TriageMutation) SetTriagingUsers(value []model.ID) {
	m.triagingUsers = &value
}

// TriagingUsers returns the value of the "triagingUsers" field in the mutation.
func (m *TriageMutation) TriagingUsers() (r []model.ID, exists bool) {
	v := m.triagingUsers
	if v == nil {
		return
	}
	return *v, true
}

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

// ResetTriagingUsers resets all changes to the "triagingUsers" field.
func (m *TriageMutation) ResetTriagingUsers() {
	m.triagingUsers = nil
}

// SetToTriageCaseExecIDs sets the "toTriageCaseExecIDs" field.
func (m *TriageMutation) SetToTriageCaseExecIDs(value []model.ID) {
	m.toTriageCaseExecIDs = &value
}

// ToTriageCaseExecIDs returns the value of the "toTriageCaseExecIDs" field in the mutation.
func (m *TriageMutation) ToTriageCaseExecIDs() (r []model.ID, exists bool) {
	v := m.toTriageCaseExecIDs
	if v == nil {
		return
	}
	return *v, true
}

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

// ResetToTriageCaseExecIDs resets all changes to the "toTriageCaseExecIDs" field.
func (m *TriageMutation) ResetToTriageCaseExecIDs() {
	m.toTriageCaseExecIDs = nil
}

// SetTriagedCaseExecIDs sets the "triagedCaseExecIDs" field.
func (m *TriageMutation) SetTriagedCaseExecIDs(value []model.ID) {
	m.triagedCaseExecIDs = &value
}

// TriagedCaseExecIDs returns the value of the "triagedCaseExecIDs" field in the mutation.
func (m *TriageMutation) TriagedCaseExecIDs() (r []model.ID, exists bool) {
	v := m.triagedCaseExecIDs
	if v == nil {
		return
	}
	return *v, true
}

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

// ResetTriagedCaseExecIDs resets all changes to the "triagedCaseExecIDs" field.
func (m *TriageMutation) ResetTriagedCaseExecIDs() {
	m.triagedCaseExecIDs = nil
}

// SetTriagePhase sets the "triagePhase" field.
func (m *TriageMutation) SetTriagePhase(mp model.TriagePhase) {
	m.triagePhase = &mp
}

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

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

// ResetTriagePhase resets all changes to the "triagePhase" field.
func (m *TriageMutation) ResetTriagePhase() {
	m.triagePhase = nil
}

// SetStartedAt sets the "startedAt" field.
func (m *TriageMutation) SetStartedAt(t time.Time) {
	m.startedAt = &t
}

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

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

// ClearStartedAt clears the value of the "startedAt" field.
func (m *TriageMutation) ClearStartedAt() {
	m.startedAt = nil
	m.clearedFields[triage.FieldStartedAt] = struct{}{}
}

// StartedAtCleared returns if the "startedAt" field was cleared in this mutation.
func (m *TriageMutation) StartedAtCleared() bool {
	_, ok := m.clearedFields[triage.FieldStartedAt]
	return ok
}

// ResetStartedAt resets all changes to the "startedAt" field.
func (m *TriageMutation) ResetStartedAt() {
	m.startedAt = nil
	delete(m.clearedFields, triage.FieldStartedAt)
}

// SetTriagedAt sets the "triagedAt" field.
func (m *TriageMutation) SetTriagedAt(t time.Time) {
	m.triagedAt = &t
}

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

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

// ClearTriagedAt clears the value of the "triagedAt" field.
func (m *TriageMutation) ClearTriagedAt() {
	m.triagedAt = nil
	m.clearedFields[triage.FieldTriagedAt] = struct{}{}
}

// TriagedAtCleared returns if the "triagedAt" field was cleared in this mutation.
func (m *TriageMutation) TriagedAtCleared() bool {
	_, ok := m.clearedFields[triage.FieldTriagedAt]
	return ok
}

// ResetTriagedAt resets all changes to the "triagedAt" field.
func (m *TriageMutation) ResetTriagedAt() {
	m.triagedAt = nil
	delete(m.clearedFields, triage.FieldTriagedAt)
}

// SetReasons sets the "reasons" field.
func (m *TriageMutation) SetReasons(mefr []model.CaseExecFailReason) {
	m.reasons = &mefr
}

// Reasons returns the value of the "reasons" field in the mutation.
func (m *TriageMutation) Reasons() (r []model.CaseExecFailReason, exists bool) {
	v := m.reasons
	if v == nil {
		return
	}
	return *v, true
}

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

// ResetReasons resets all changes to the "reasons" field.
func (m *TriageMutation) ResetReasons() {
	m.reasons = nil
}

// SetSolution sets the "solution" field.
func (m *TriageMutation) SetSolution(mfs model.ExecFailSolution) {
	m.solution = &mfs
}

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

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

// ResetSolution resets all changes to the "solution" field.
func (m *TriageMutation) ResetSolution() {
	m.solution = nil
}

// SetNote sets the "note" field.
func (m *TriageMutation) SetNote(s string) {
	m.note = &s
}

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

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

// ResetNote resets all changes to the "note" field.
func (m *TriageMutation) ResetNote() {
	m.note = nil
}

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

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

// Type returns the node type of this mutation (Triage).
func (m *TriageMutation) 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 *TriageMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.createdAt != nil {
		fields = append(fields, triage.FieldCreatedAt)
	}
	if m.updatedAt != nil {
		fields = append(fields, triage.FieldUpdatedAt)
	}
	if m.planExecutionID != nil {
		fields = append(fields, triage.FieldPlanExecutionID)
	}
	if m.planID != nil {
		fields = append(fields, triage.FieldPlanID)
	}
	if m.triagingUsers != nil {
		fields = append(fields, triage.FieldTriagingUsers)
	}
	if m.toTriageCaseExecIDs != nil {
		fields = append(fields, triage.FieldToTriageCaseExecIDs)
	}
	if m.triagedCaseExecIDs != nil {
		fields = append(fields, triage.FieldTriagedCaseExecIDs)
	}
	if m.triagePhase != nil {
		fields = append(fields, triage.FieldTriagePhase)
	}
	if m.startedAt != nil {
		fields = append(fields, triage.FieldStartedAt)
	}
	if m.triagedAt != nil {
		fields = append(fields, triage.FieldTriagedAt)
	}
	if m.reasons != nil {
		fields = append(fields, triage.FieldReasons)
	}
	if m.solution != nil {
		fields = append(fields, triage.FieldSolution)
	}
	if m.note != nil {
		fields = append(fields, triage.FieldNote)
	}
	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 *TriageMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case triage.FieldCreatedAt:
		return m.CreatedAt()
	case triage.FieldUpdatedAt:
		return m.UpdatedAt()
	case triage.FieldPlanExecutionID:
		return m.PlanExecutionID()
	case triage.FieldPlanID:
		return m.PlanID()
	case triage.FieldTriagingUsers:
		return m.TriagingUsers()
	case triage.FieldToTriageCaseExecIDs:
		return m.ToTriageCaseExecIDs()
	case triage.FieldTriagedCaseExecIDs:
		return m.TriagedCaseExecIDs()
	case triage.FieldTriagePhase:
		return m.TriagePhase()
	case triage.FieldStartedAt:
		return m.StartedAt()
	case triage.FieldTriagedAt:
		return m.TriagedAt()
	case triage.FieldReasons:
		return m.Reasons()
	case triage.FieldSolution:
		return m.Solution()
	case triage.FieldNote:
		return m.Note()
	}
	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 *TriageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case triage.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case triage.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case triage.FieldPlanExecutionID:
		return m.OldPlanExecutionID(ctx)
	case triage.FieldPlanID:
		return m.OldPlanID(ctx)
	case triage.FieldTriagingUsers:
		return m.OldTriagingUsers(ctx)
	case triage.FieldToTriageCaseExecIDs:
		return m.OldToTriageCaseExecIDs(ctx)
	case triage.FieldTriagedCaseExecIDs:
		return m.OldTriagedCaseExecIDs(ctx)
	case triage.FieldTriagePhase:
		return m.OldTriagePhase(ctx)
	case triage.FieldStartedAt:
		return m.OldStartedAt(ctx)
	case triage.FieldTriagedAt:
		return m.OldTriagedAt(ctx)
	case triage.FieldReasons:
		return m.OldReasons(ctx)
	case triage.FieldSolution:
		return m.OldSolution(ctx)
	case triage.FieldNote:
		return m.OldNote(ctx)
	}
	return nil, fmt.Errorf("unknown Triage 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 *TriageMutation) SetField(name string, value ent.Value) error {
	switch name {
	case triage.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 triage.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 triage.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanExecutionID(v)
		return nil
	case triage.FieldPlanID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanID(v)
		return nil
	case triage.FieldTriagingUsers:
		v, ok := value.([]model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTriagingUsers(v)
		return nil
	case triage.FieldToTriageCaseExecIDs:
		v, ok := value.([]model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetToTriageCaseExecIDs(v)
		return nil
	case triage.FieldTriagedCaseExecIDs:
		v, ok := value.([]model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTriagedCaseExecIDs(v)
		return nil
	case triage.FieldTriagePhase:
		v, ok := value.(model.TriagePhase)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTriagePhase(v)
		return nil
	case triage.FieldStartedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStartedAt(v)
		return nil
	case triage.FieldTriagedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTriagedAt(v)
		return nil
	case triage.FieldReasons:
		v, ok := value.([]model.CaseExecFailReason)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReasons(v)
		return nil
	case triage.FieldSolution:
		v, ok := value.(model.ExecFailSolution)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSolution(v)
		return nil
	case triage.FieldNote:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNote(v)
		return nil
	}
	return fmt.Errorf("unknown Triage field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *TriageMutation) AddedFields() []string {
	var fields []string
	if m.addplanExecutionID != nil {
		fields = append(fields, triage.FieldPlanExecutionID)
	}
	if m.addplanID != nil {
		fields = append(fields, triage.FieldPlanID)
	}
	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 *TriageMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case triage.FieldPlanExecutionID:
		return m.AddedPlanExecutionID()
	case triage.FieldPlanID:
		return m.AddedPlanID()
	}
	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 *TriageMutation) AddField(name string, value ent.Value) error {
	switch name {
	case triage.FieldPlanExecutionID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanExecutionID(v)
		return nil
	case triage.FieldPlanID:
		v, ok := value.(model.ID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanID(v)
		return nil
	}
	return fmt.Errorf("unknown Triage numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *TriageMutation) 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 *TriageMutation) ClearField(name string) error {
	switch name {
	case triage.FieldStartedAt:
		m.ClearStartedAt()
		return nil
	case triage.FieldTriagedAt:
		m.ClearTriagedAt()
		return nil
	}
	return fmt.Errorf("unknown Triage 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 *TriageMutation) ResetField(name string) error {
	switch name {
	case triage.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case triage.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case triage.FieldPlanExecutionID:
		m.ResetPlanExecutionID()
		return nil
	case triage.FieldPlanID:
		m.ResetPlanID()
		return nil
	case triage.FieldTriagingUsers:
		m.ResetTriagingUsers()
		return nil
	case triage.FieldToTriageCaseExecIDs:
		m.ResetToTriageCaseExecIDs()
		return nil
	case triage.FieldTriagedCaseExecIDs:
		m.ResetTriagedCaseExecIDs()
		return nil
	case triage.FieldTriagePhase:
		m.ResetTriagePhase()
		return nil
	case triage.FieldStartedAt:
		m.ResetStartedAt()
		return nil
	case triage.FieldTriagedAt:
		m.ResetTriagedAt()
		return nil
	case triage.FieldReasons:
		m.ResetReasons()
		return nil
	case triage.FieldSolution:
		m.ResetSolution()
		return nil
	case triage.FieldNote:
		m.ResetNote()
		return nil
	}
	return fmt.Errorf("unknown Triage field %s", name)
}

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

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

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

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

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

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

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