// Code generated by ent, DO NOT EDIT.

package models

import (
	"context"
	"errors"
	"fmt"
	"juwan-backend/app/dispute/rpc/internal/models/disputes"
	"juwan-backend/app/dispute/rpc/internal/models/disputetimeline"
	"juwan-backend/app/dispute/rpc/internal/models/predicate"
	"juwan-backend/pkg/types"
	"sync"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

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

	// Node types.
	TypeDisputeTimeline = "DisputeTimeline"
	TypeDisputes        = "Disputes"
)

// DisputeTimelineMutation represents an operation that mutates the DisputeTimeline nodes in the graph.
type DisputeTimelineMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	dispute_id    *int64
	adddispute_id *int64
	event_type    *string
	actor_id      *int64
	addactor_id   *int64
	actor_name    *string
	details       *map[string]interface{}
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*DisputeTimeline, error)
	predicates    []predicate.DisputeTimeline
}

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

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

// newDisputeTimelineMutation creates new mutation for the DisputeTimeline entity.
func newDisputeTimelineMutation(c config, op Op, opts ...disputetimelineOption) *DisputeTimelineMutation {
	m := &DisputeTimelineMutation{
		config:        c,
		op:            op,
		typ:           TypeDisputeTimeline,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withDisputeTimeline sets the old DisputeTimeline of the mutation.
func withDisputeTimeline(node *DisputeTimeline) disputetimelineOption {
	return func(m *DisputeTimelineMutation) {
		m.oldValue = func(context.Context) (*DisputeTimeline, 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 DisputeTimelineMutation) 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 DisputeTimelineMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("models: 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 DisputeTimeline entities.
func (m *DisputeTimelineMutation) SetID(id int64) {
	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 *DisputeTimelineMutation) ID() (id int64, 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 *DisputeTimelineMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().DisputeTimeline.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetDisputeID sets the "dispute_id" field.
func (m *DisputeTimelineMutation) SetDisputeID(i int64) {
	m.dispute_id = &i
	m.adddispute_id = nil
}

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

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

// AddDisputeID adds i to the "dispute_id" field.
func (m *DisputeTimelineMutation) AddDisputeID(i int64) {
	if m.adddispute_id != nil {
		*m.adddispute_id += i
	} else {
		m.adddispute_id = &i
	}
}

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

// ResetDisputeID resets all changes to the "dispute_id" field.
func (m *DisputeTimelineMutation) ResetDisputeID() {
	m.dispute_id = nil
	m.adddispute_id = nil
}

// SetEventType sets the "event_type" field.
func (m *DisputeTimelineMutation) SetEventType(s string) {
	m.event_type = &s
}

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

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

// ResetEventType resets all changes to the "event_type" field.
func (m *DisputeTimelineMutation) ResetEventType() {
	m.event_type = nil
}

// SetActorID sets the "actor_id" field.
func (m *DisputeTimelineMutation) SetActorID(i int64) {
	m.actor_id = &i
	m.addactor_id = nil
}

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

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

// AddActorID adds i to the "actor_id" field.
func (m *DisputeTimelineMutation) AddActorID(i int64) {
	if m.addactor_id != nil {
		*m.addactor_id += i
	} else {
		m.addactor_id = &i
	}
}

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

// ClearActorID clears the value of the "actor_id" field.
func (m *DisputeTimelineMutation) ClearActorID() {
	m.actor_id = nil
	m.addactor_id = nil
	m.clearedFields[disputetimeline.FieldActorID] = struct{}{}
}

// ActorIDCleared returns if the "actor_id" field was cleared in this mutation.
func (m *DisputeTimelineMutation) ActorIDCleared() bool {
	_, ok := m.clearedFields[disputetimeline.FieldActorID]
	return ok
}

// ResetActorID resets all changes to the "actor_id" field.
func (m *DisputeTimelineMutation) ResetActorID() {
	m.actor_id = nil
	m.addactor_id = nil
	delete(m.clearedFields, disputetimeline.FieldActorID)
}

// SetActorName sets the "actor_name" field.
func (m *DisputeTimelineMutation) SetActorName(s string) {
	m.actor_name = &s
}

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

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

// ClearActorName clears the value of the "actor_name" field.
func (m *DisputeTimelineMutation) ClearActorName() {
	m.actor_name = nil
	m.clearedFields[disputetimeline.FieldActorName] = struct{}{}
}

// ActorNameCleared returns if the "actor_name" field was cleared in this mutation.
func (m *DisputeTimelineMutation) ActorNameCleared() bool {
	_, ok := m.clearedFields[disputetimeline.FieldActorName]
	return ok
}

// ResetActorName resets all changes to the "actor_name" field.
func (m *DisputeTimelineMutation) ResetActorName() {
	m.actor_name = nil
	delete(m.clearedFields, disputetimeline.FieldActorName)
}

// SetDetails sets the "details" field.
func (m *DisputeTimelineMutation) SetDetails(value map[string]interface{}) {
	m.details = &value
}

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

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

// ClearDetails clears the value of the "details" field.
func (m *DisputeTimelineMutation) ClearDetails() {
	m.details = nil
	m.clearedFields[disputetimeline.FieldDetails] = struct{}{}
}

// DetailsCleared returns if the "details" field was cleared in this mutation.
func (m *DisputeTimelineMutation) DetailsCleared() bool {
	_, ok := m.clearedFields[disputetimeline.FieldDetails]
	return ok
}

// ResetDetails resets all changes to the "details" field.
func (m *DisputeTimelineMutation) ResetDetails() {
	m.details = nil
	delete(m.clearedFields, disputetimeline.FieldDetails)
}

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

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

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

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

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

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

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

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

// Type returns the node type of this mutation (DisputeTimeline).
func (m *DisputeTimelineMutation) 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 *DisputeTimelineMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.dispute_id != nil {
		fields = append(fields, disputetimeline.FieldDisputeID)
	}
	if m.event_type != nil {
		fields = append(fields, disputetimeline.FieldEventType)
	}
	if m.actor_id != nil {
		fields = append(fields, disputetimeline.FieldActorID)
	}
	if m.actor_name != nil {
		fields = append(fields, disputetimeline.FieldActorName)
	}
	if m.details != nil {
		fields = append(fields, disputetimeline.FieldDetails)
	}
	if m.created_at != nil {
		fields = append(fields, disputetimeline.FieldCreatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *DisputeTimelineMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case disputetimeline.FieldDisputeID:
		return m.DisputeID()
	case disputetimeline.FieldEventType:
		return m.EventType()
	case disputetimeline.FieldActorID:
		return m.ActorID()
	case disputetimeline.FieldActorName:
		return m.ActorName()
	case disputetimeline.FieldDetails:
		return m.Details()
	case disputetimeline.FieldCreatedAt:
		return m.CreatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *DisputeTimelineMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case disputetimeline.FieldDisputeID:
		return m.OldDisputeID(ctx)
	case disputetimeline.FieldEventType:
		return m.OldEventType(ctx)
	case disputetimeline.FieldActorID:
		return m.OldActorID(ctx)
	case disputetimeline.FieldActorName:
		return m.OldActorName(ctx)
	case disputetimeline.FieldDetails:
		return m.OldDetails(ctx)
	case disputetimeline.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown DisputeTimeline 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 *DisputeTimelineMutation) SetField(name string, value ent.Value) error {
	switch name {
	case disputetimeline.FieldDisputeID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDisputeID(v)
		return nil
	case disputetimeline.FieldEventType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEventType(v)
		return nil
	case disputetimeline.FieldActorID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetActorID(v)
		return nil
	case disputetimeline.FieldActorName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetActorName(v)
		return nil
	case disputetimeline.FieldDetails:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDetails(v)
		return nil
	case disputetimeline.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown DisputeTimeline field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *DisputeTimelineMutation) AddedFields() []string {
	var fields []string
	if m.adddispute_id != nil {
		fields = append(fields, disputetimeline.FieldDisputeID)
	}
	if m.addactor_id != nil {
		fields = append(fields, disputetimeline.FieldActorID)
	}
	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 *DisputeTimelineMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case disputetimeline.FieldDisputeID:
		return m.AddedDisputeID()
	case disputetimeline.FieldActorID:
		return m.AddedActorID()
	}
	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 *DisputeTimelineMutation) AddField(name string, value ent.Value) error {
	switch name {
	case disputetimeline.FieldDisputeID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDisputeID(v)
		return nil
	case disputetimeline.FieldActorID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddActorID(v)
		return nil
	}
	return fmt.Errorf("unknown DisputeTimeline numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *DisputeTimelineMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(disputetimeline.FieldActorID) {
		fields = append(fields, disputetimeline.FieldActorID)
	}
	if m.FieldCleared(disputetimeline.FieldActorName) {
		fields = append(fields, disputetimeline.FieldActorName)
	}
	if m.FieldCleared(disputetimeline.FieldDetails) {
		fields = append(fields, disputetimeline.FieldDetails)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *DisputeTimelineMutation) 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 *DisputeTimelineMutation) ClearField(name string) error {
	switch name {
	case disputetimeline.FieldActorID:
		m.ClearActorID()
		return nil
	case disputetimeline.FieldActorName:
		m.ClearActorName()
		return nil
	case disputetimeline.FieldDetails:
		m.ClearDetails()
		return nil
	}
	return fmt.Errorf("unknown DisputeTimeline 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 *DisputeTimelineMutation) ResetField(name string) error {
	switch name {
	case disputetimeline.FieldDisputeID:
		m.ResetDisputeID()
		return nil
	case disputetimeline.FieldEventType:
		m.ResetEventType()
		return nil
	case disputetimeline.FieldActorID:
		m.ResetActorID()
		return nil
	case disputetimeline.FieldActorName:
		m.ResetActorName()
		return nil
	case disputetimeline.FieldDetails:
		m.ResetDetails()
		return nil
	case disputetimeline.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown DisputeTimeline field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *DisputeTimelineMutation) 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 *DisputeTimelineMutation) AddedIDs(name string) []ent.Value {
	return nil
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *DisputeTimelineMutation) 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 *DisputeTimelineMutation) 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 *DisputeTimelineMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown DisputeTimeline 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 *DisputeTimelineMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown DisputeTimeline edge %s", name)
}

// DisputesMutation represents an operation that mutates the Disputes nodes in the graph.
type DisputesMutation struct {
	config
	op                  Op
	typ                 string
	id                  *int64
	order_id            *int64
	addorder_id         *int64
	initiator_id        *int64
	addinitiator_id     *int64
	initiator_name      *string
	respondent_id       *int64
	addrespondent_id    *int64
	reason              *string
	evidence            *types.TextArray
	status              *string
	result              *string
	respondent_reason   *string
	respondent_evidence *types.TextArray
	appeal_reason       *string
	appealed_at         *time.Time
	resolved_by         *int64
	addresolved_by      *int64
	resolved_at         *time.Time
	created_at          *time.Time
	updated_at          *time.Time
	clearedFields       map[string]struct{}
	done                bool
	oldValue            func(context.Context) (*Disputes, error)
	predicates          []predicate.Disputes
}

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

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

// newDisputesMutation creates new mutation for the Disputes entity.
func newDisputesMutation(c config, op Op, opts ...disputesOption) *DisputesMutation {
	m := &DisputesMutation{
		config:        c,
		op:            op,
		typ:           TypeDisputes,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withDisputes sets the old Disputes of the mutation.
func withDisputes(node *Disputes) disputesOption {
	return func(m *DisputesMutation) {
		m.oldValue = func(context.Context) (*Disputes, 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 DisputesMutation) 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 DisputesMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("models: 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 Disputes entities.
func (m *DisputesMutation) SetID(id int64) {
	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 *DisputesMutation) ID() (id int64, 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 *DisputesMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Disputes.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetOrderID sets the "order_id" field.
func (m *DisputesMutation) SetOrderID(i int64) {
	m.order_id = &i
	m.addorder_id = nil
}

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

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

// AddOrderID adds i to the "order_id" field.
func (m *DisputesMutation) AddOrderID(i int64) {
	if m.addorder_id != nil {
		*m.addorder_id += i
	} else {
		m.addorder_id = &i
	}
}

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

// ResetOrderID resets all changes to the "order_id" field.
func (m *DisputesMutation) ResetOrderID() {
	m.order_id = nil
	m.addorder_id = nil
}

// SetInitiatorID sets the "initiator_id" field.
func (m *DisputesMutation) SetInitiatorID(i int64) {
	m.initiator_id = &i
	m.addinitiator_id = nil
}

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

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

// AddInitiatorID adds i to the "initiator_id" field.
func (m *DisputesMutation) AddInitiatorID(i int64) {
	if m.addinitiator_id != nil {
		*m.addinitiator_id += i
	} else {
		m.addinitiator_id = &i
	}
}

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

// ResetInitiatorID resets all changes to the "initiator_id" field.
func (m *DisputesMutation) ResetInitiatorID() {
	m.initiator_id = nil
	m.addinitiator_id = nil
}

// SetInitiatorName sets the "initiator_name" field.
func (m *DisputesMutation) SetInitiatorName(s string) {
	m.initiator_name = &s
}

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

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

// ResetInitiatorName resets all changes to the "initiator_name" field.
func (m *DisputesMutation) ResetInitiatorName() {
	m.initiator_name = nil
}

// SetRespondentID sets the "respondent_id" field.
func (m *DisputesMutation) SetRespondentID(i int64) {
	m.respondent_id = &i
	m.addrespondent_id = nil
}

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

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

// AddRespondentID adds i to the "respondent_id" field.
func (m *DisputesMutation) AddRespondentID(i int64) {
	if m.addrespondent_id != nil {
		*m.addrespondent_id += i
	} else {
		m.addrespondent_id = &i
	}
}

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

// ResetRespondentID resets all changes to the "respondent_id" field.
func (m *DisputesMutation) ResetRespondentID() {
	m.respondent_id = nil
	m.addrespondent_id = nil
}

// SetReason sets the "reason" field.
func (m *DisputesMutation) SetReason(s string) {
	m.reason = &s
}

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

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

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

// SetEvidence sets the "evidence" field.
func (m *DisputesMutation) SetEvidence(ta types.TextArray) {
	m.evidence = &ta
}

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

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

// ClearEvidence clears the value of the "evidence" field.
func (m *DisputesMutation) ClearEvidence() {
	m.evidence = nil
	m.clearedFields[disputes.FieldEvidence] = struct{}{}
}

// EvidenceCleared returns if the "evidence" field was cleared in this mutation.
func (m *DisputesMutation) EvidenceCleared() bool {
	_, ok := m.clearedFields[disputes.FieldEvidence]
	return ok
}

// ResetEvidence resets all changes to the "evidence" field.
func (m *DisputesMutation) ResetEvidence() {
	m.evidence = nil
	delete(m.clearedFields, disputes.FieldEvidence)
}

// SetStatus sets the "status" field.
func (m *DisputesMutation) SetStatus(s string) {
	m.status = &s
}

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

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

// SetResult sets the "result" field.
func (m *DisputesMutation) SetResult(s string) {
	m.result = &s
}

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

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

// ClearResult clears the value of the "result" field.
func (m *DisputesMutation) ClearResult() {
	m.result = nil
	m.clearedFields[disputes.FieldResult] = struct{}{}
}

// ResultCleared returns if the "result" field was cleared in this mutation.
func (m *DisputesMutation) ResultCleared() bool {
	_, ok := m.clearedFields[disputes.FieldResult]
	return ok
}

// ResetResult resets all changes to the "result" field.
func (m *DisputesMutation) ResetResult() {
	m.result = nil
	delete(m.clearedFields, disputes.FieldResult)
}

// SetRespondentReason sets the "respondent_reason" field.
func (m *DisputesMutation) SetRespondentReason(s string) {
	m.respondent_reason = &s
}

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

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

// ClearRespondentReason clears the value of the "respondent_reason" field.
func (m *DisputesMutation) ClearRespondentReason() {
	m.respondent_reason = nil
	m.clearedFields[disputes.FieldRespondentReason] = struct{}{}
}

// RespondentReasonCleared returns if the "respondent_reason" field was cleared in this mutation.
func (m *DisputesMutation) RespondentReasonCleared() bool {
	_, ok := m.clearedFields[disputes.FieldRespondentReason]
	return ok
}

// ResetRespondentReason resets all changes to the "respondent_reason" field.
func (m *DisputesMutation) ResetRespondentReason() {
	m.respondent_reason = nil
	delete(m.clearedFields, disputes.FieldRespondentReason)
}

// SetRespondentEvidence sets the "respondent_evidence" field.
func (m *DisputesMutation) SetRespondentEvidence(ta types.TextArray) {
	m.respondent_evidence = &ta
}

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

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

// ClearRespondentEvidence clears the value of the "respondent_evidence" field.
func (m *DisputesMutation) ClearRespondentEvidence() {
	m.respondent_evidence = nil
	m.clearedFields[disputes.FieldRespondentEvidence] = struct{}{}
}

// RespondentEvidenceCleared returns if the "respondent_evidence" field was cleared in this mutation.
func (m *DisputesMutation) RespondentEvidenceCleared() bool {
	_, ok := m.clearedFields[disputes.FieldRespondentEvidence]
	return ok
}

// ResetRespondentEvidence resets all changes to the "respondent_evidence" field.
func (m *DisputesMutation) ResetRespondentEvidence() {
	m.respondent_evidence = nil
	delete(m.clearedFields, disputes.FieldRespondentEvidence)
}

// SetAppealReason sets the "appeal_reason" field.
func (m *DisputesMutation) SetAppealReason(s string) {
	m.appeal_reason = &s
}

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

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

// ClearAppealReason clears the value of the "appeal_reason" field.
func (m *DisputesMutation) ClearAppealReason() {
	m.appeal_reason = nil
	m.clearedFields[disputes.FieldAppealReason] = struct{}{}
}

// AppealReasonCleared returns if the "appeal_reason" field was cleared in this mutation.
func (m *DisputesMutation) AppealReasonCleared() bool {
	_, ok := m.clearedFields[disputes.FieldAppealReason]
	return ok
}

// ResetAppealReason resets all changes to the "appeal_reason" field.
func (m *DisputesMutation) ResetAppealReason() {
	m.appeal_reason = nil
	delete(m.clearedFields, disputes.FieldAppealReason)
}

// SetAppealedAt sets the "appealed_at" field.
func (m *DisputesMutation) SetAppealedAt(t time.Time) {
	m.appealed_at = &t
}

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

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

// ClearAppealedAt clears the value of the "appealed_at" field.
func (m *DisputesMutation) ClearAppealedAt() {
	m.appealed_at = nil
	m.clearedFields[disputes.FieldAppealedAt] = struct{}{}
}

// AppealedAtCleared returns if the "appealed_at" field was cleared in this mutation.
func (m *DisputesMutation) AppealedAtCleared() bool {
	_, ok := m.clearedFields[disputes.FieldAppealedAt]
	return ok
}

// ResetAppealedAt resets all changes to the "appealed_at" field.
func (m *DisputesMutation) ResetAppealedAt() {
	m.appealed_at = nil
	delete(m.clearedFields, disputes.FieldAppealedAt)
}

// SetResolvedBy sets the "resolved_by" field.
func (m *DisputesMutation) SetResolvedBy(i int64) {
	m.resolved_by = &i
	m.addresolved_by = nil
}

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

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

// AddResolvedBy adds i to the "resolved_by" field.
func (m *DisputesMutation) AddResolvedBy(i int64) {
	if m.addresolved_by != nil {
		*m.addresolved_by += i
	} else {
		m.addresolved_by = &i
	}
}

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

// ClearResolvedBy clears the value of the "resolved_by" field.
func (m *DisputesMutation) ClearResolvedBy() {
	m.resolved_by = nil
	m.addresolved_by = nil
	m.clearedFields[disputes.FieldResolvedBy] = struct{}{}
}

// ResolvedByCleared returns if the "resolved_by" field was cleared in this mutation.
func (m *DisputesMutation) ResolvedByCleared() bool {
	_, ok := m.clearedFields[disputes.FieldResolvedBy]
	return ok
}

// ResetResolvedBy resets all changes to the "resolved_by" field.
func (m *DisputesMutation) ResetResolvedBy() {
	m.resolved_by = nil
	m.addresolved_by = nil
	delete(m.clearedFields, disputes.FieldResolvedBy)
}

// SetResolvedAt sets the "resolved_at" field.
func (m *DisputesMutation) SetResolvedAt(t time.Time) {
	m.resolved_at = &t
}

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

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

// ClearResolvedAt clears the value of the "resolved_at" field.
func (m *DisputesMutation) ClearResolvedAt() {
	m.resolved_at = nil
	m.clearedFields[disputes.FieldResolvedAt] = struct{}{}
}

// ResolvedAtCleared returns if the "resolved_at" field was cleared in this mutation.
func (m *DisputesMutation) ResolvedAtCleared() bool {
	_, ok := m.clearedFields[disputes.FieldResolvedAt]
	return ok
}

// ResetResolvedAt resets all changes to the "resolved_at" field.
func (m *DisputesMutation) ResetResolvedAt() {
	m.resolved_at = nil
	delete(m.clearedFields, disputes.FieldResolvedAt)
}

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

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

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

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

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

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

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

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

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

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

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

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

// Type returns the node type of this mutation (Disputes).
func (m *DisputesMutation) 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 *DisputesMutation) Fields() []string {
	fields := make([]string, 0, 16)
	if m.order_id != nil {
		fields = append(fields, disputes.FieldOrderID)
	}
	if m.initiator_id != nil {
		fields = append(fields, disputes.FieldInitiatorID)
	}
	if m.initiator_name != nil {
		fields = append(fields, disputes.FieldInitiatorName)
	}
	if m.respondent_id != nil {
		fields = append(fields, disputes.FieldRespondentID)
	}
	if m.reason != nil {
		fields = append(fields, disputes.FieldReason)
	}
	if m.evidence != nil {
		fields = append(fields, disputes.FieldEvidence)
	}
	if m.status != nil {
		fields = append(fields, disputes.FieldStatus)
	}
	if m.result != nil {
		fields = append(fields, disputes.FieldResult)
	}
	if m.respondent_reason != nil {
		fields = append(fields, disputes.FieldRespondentReason)
	}
	if m.respondent_evidence != nil {
		fields = append(fields, disputes.FieldRespondentEvidence)
	}
	if m.appeal_reason != nil {
		fields = append(fields, disputes.FieldAppealReason)
	}
	if m.appealed_at != nil {
		fields = append(fields, disputes.FieldAppealedAt)
	}
	if m.resolved_by != nil {
		fields = append(fields, disputes.FieldResolvedBy)
	}
	if m.resolved_at != nil {
		fields = append(fields, disputes.FieldResolvedAt)
	}
	if m.created_at != nil {
		fields = append(fields, disputes.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, disputes.FieldUpdatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *DisputesMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case disputes.FieldOrderID:
		return m.OrderID()
	case disputes.FieldInitiatorID:
		return m.InitiatorID()
	case disputes.FieldInitiatorName:
		return m.InitiatorName()
	case disputes.FieldRespondentID:
		return m.RespondentID()
	case disputes.FieldReason:
		return m.Reason()
	case disputes.FieldEvidence:
		return m.Evidence()
	case disputes.FieldStatus:
		return m.Status()
	case disputes.FieldResult:
		return m.Result()
	case disputes.FieldRespondentReason:
		return m.RespondentReason()
	case disputes.FieldRespondentEvidence:
		return m.RespondentEvidence()
	case disputes.FieldAppealReason:
		return m.AppealReason()
	case disputes.FieldAppealedAt:
		return m.AppealedAt()
	case disputes.FieldResolvedBy:
		return m.ResolvedBy()
	case disputes.FieldResolvedAt:
		return m.ResolvedAt()
	case disputes.FieldCreatedAt:
		return m.CreatedAt()
	case disputes.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *DisputesMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case disputes.FieldOrderID:
		return m.OldOrderID(ctx)
	case disputes.FieldInitiatorID:
		return m.OldInitiatorID(ctx)
	case disputes.FieldInitiatorName:
		return m.OldInitiatorName(ctx)
	case disputes.FieldRespondentID:
		return m.OldRespondentID(ctx)
	case disputes.FieldReason:
		return m.OldReason(ctx)
	case disputes.FieldEvidence:
		return m.OldEvidence(ctx)
	case disputes.FieldStatus:
		return m.OldStatus(ctx)
	case disputes.FieldResult:
		return m.OldResult(ctx)
	case disputes.FieldRespondentReason:
		return m.OldRespondentReason(ctx)
	case disputes.FieldRespondentEvidence:
		return m.OldRespondentEvidence(ctx)
	case disputes.FieldAppealReason:
		return m.OldAppealReason(ctx)
	case disputes.FieldAppealedAt:
		return m.OldAppealedAt(ctx)
	case disputes.FieldResolvedBy:
		return m.OldResolvedBy(ctx)
	case disputes.FieldResolvedAt:
		return m.OldResolvedAt(ctx)
	case disputes.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case disputes.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Disputes 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 *DisputesMutation) SetField(name string, value ent.Value) error {
	switch name {
	case disputes.FieldOrderID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderID(v)
		return nil
	case disputes.FieldInitiatorID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInitiatorID(v)
		return nil
	case disputes.FieldInitiatorName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInitiatorName(v)
		return nil
	case disputes.FieldRespondentID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRespondentID(v)
		return nil
	case disputes.FieldReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReason(v)
		return nil
	case disputes.FieldEvidence:
		v, ok := value.(types.TextArray)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEvidence(v)
		return nil
	case disputes.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case disputes.FieldResult:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResult(v)
		return nil
	case disputes.FieldRespondentReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRespondentReason(v)
		return nil
	case disputes.FieldRespondentEvidence:
		v, ok := value.(types.TextArray)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRespondentEvidence(v)
		return nil
	case disputes.FieldAppealReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAppealReason(v)
		return nil
	case disputes.FieldAppealedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAppealedAt(v)
		return nil
	case disputes.FieldResolvedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResolvedBy(v)
		return nil
	case disputes.FieldResolvedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResolvedAt(v)
		return nil
	case disputes.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 disputes.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Disputes field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *DisputesMutation) AddedFields() []string {
	var fields []string
	if m.addorder_id != nil {
		fields = append(fields, disputes.FieldOrderID)
	}
	if m.addinitiator_id != nil {
		fields = append(fields, disputes.FieldInitiatorID)
	}
	if m.addrespondent_id != nil {
		fields = append(fields, disputes.FieldRespondentID)
	}
	if m.addresolved_by != nil {
		fields = append(fields, disputes.FieldResolvedBy)
	}
	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 *DisputesMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case disputes.FieldOrderID:
		return m.AddedOrderID()
	case disputes.FieldInitiatorID:
		return m.AddedInitiatorID()
	case disputes.FieldRespondentID:
		return m.AddedRespondentID()
	case disputes.FieldResolvedBy:
		return m.AddedResolvedBy()
	}
	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 *DisputesMutation) AddField(name string, value ent.Value) error {
	switch name {
	case disputes.FieldOrderID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOrderID(v)
		return nil
	case disputes.FieldInitiatorID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInitiatorID(v)
		return nil
	case disputes.FieldRespondentID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRespondentID(v)
		return nil
	case disputes.FieldResolvedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddResolvedBy(v)
		return nil
	}
	return fmt.Errorf("unknown Disputes numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *DisputesMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(disputes.FieldEvidence) {
		fields = append(fields, disputes.FieldEvidence)
	}
	if m.FieldCleared(disputes.FieldResult) {
		fields = append(fields, disputes.FieldResult)
	}
	if m.FieldCleared(disputes.FieldRespondentReason) {
		fields = append(fields, disputes.FieldRespondentReason)
	}
	if m.FieldCleared(disputes.FieldRespondentEvidence) {
		fields = append(fields, disputes.FieldRespondentEvidence)
	}
	if m.FieldCleared(disputes.FieldAppealReason) {
		fields = append(fields, disputes.FieldAppealReason)
	}
	if m.FieldCleared(disputes.FieldAppealedAt) {
		fields = append(fields, disputes.FieldAppealedAt)
	}
	if m.FieldCleared(disputes.FieldResolvedBy) {
		fields = append(fields, disputes.FieldResolvedBy)
	}
	if m.FieldCleared(disputes.FieldResolvedAt) {
		fields = append(fields, disputes.FieldResolvedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *DisputesMutation) 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 *DisputesMutation) ClearField(name string) error {
	switch name {
	case disputes.FieldEvidence:
		m.ClearEvidence()
		return nil
	case disputes.FieldResult:
		m.ClearResult()
		return nil
	case disputes.FieldRespondentReason:
		m.ClearRespondentReason()
		return nil
	case disputes.FieldRespondentEvidence:
		m.ClearRespondentEvidence()
		return nil
	case disputes.FieldAppealReason:
		m.ClearAppealReason()
		return nil
	case disputes.FieldAppealedAt:
		m.ClearAppealedAt()
		return nil
	case disputes.FieldResolvedBy:
		m.ClearResolvedBy()
		return nil
	case disputes.FieldResolvedAt:
		m.ClearResolvedAt()
		return nil
	}
	return fmt.Errorf("unknown Disputes 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 *DisputesMutation) ResetField(name string) error {
	switch name {
	case disputes.FieldOrderID:
		m.ResetOrderID()
		return nil
	case disputes.FieldInitiatorID:
		m.ResetInitiatorID()
		return nil
	case disputes.FieldInitiatorName:
		m.ResetInitiatorName()
		return nil
	case disputes.FieldRespondentID:
		m.ResetRespondentID()
		return nil
	case disputes.FieldReason:
		m.ResetReason()
		return nil
	case disputes.FieldEvidence:
		m.ResetEvidence()
		return nil
	case disputes.FieldStatus:
		m.ResetStatus()
		return nil
	case disputes.FieldResult:
		m.ResetResult()
		return nil
	case disputes.FieldRespondentReason:
		m.ResetRespondentReason()
		return nil
	case disputes.FieldRespondentEvidence:
		m.ResetRespondentEvidence()
		return nil
	case disputes.FieldAppealReason:
		m.ResetAppealReason()
		return nil
	case disputes.FieldAppealedAt:
		m.ResetAppealedAt()
		return nil
	case disputes.FieldResolvedBy:
		m.ResetResolvedBy()
		return nil
	case disputes.FieldResolvedAt:
		m.ResetResolvedAt()
		return nil
	case disputes.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case disputes.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Disputes field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *DisputesMutation) 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 *DisputesMutation) AddedIDs(name string) []ent.Value {
	return nil
}

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

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *DisputesMutation) 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 *DisputesMutation) 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 *DisputesMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Disputes 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 *DisputesMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Disputes edge %s", name)
}
