// Code generated by ent, DO NOT EDIT.

package models

import (
	"context"
	"errors"
	"fmt"
	"juwan-backend/app/review/rpc/internal/models/predicate"
	"juwan-backend/app/review/rpc/internal/models/reviews"
	"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.
	TypeReviews = "Reviews"
)

// ReviewsMutation represents an operation that mutates the Reviews nodes in the graph.
type ReviewsMutation struct {
	config
	op               Op
	typ              string
	id               *int64
	order_id         *int64
	addorder_id      *int64
	from_user_id     *int64
	addfrom_user_id  *int64
	from_user_name   *string
	from_user_avatar *string
	to_user_id       *int64
	addto_user_id    *int64
	rating           *int16
	addrating        *int16
	content          *string
	sealed           *bool
	created_at       *time.Time
	unsealed_at      *time.Time
	clearedFields    map[string]struct{}
	done             bool
	oldValue         func(context.Context) (*Reviews, error)
	predicates       []predicate.Reviews
}

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

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

// newReviewsMutation creates new mutation for the Reviews entity.
func newReviewsMutation(c config, op Op, opts ...reviewsOption) *ReviewsMutation {
	m := &ReviewsMutation{
		config:        c,
		op:            op,
		typ:           TypeReviews,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

// withReviews sets the old Reviews of the mutation.
func withReviews(node *Reviews) reviewsOption {
	return func(m *ReviewsMutation) {
		m.oldValue = func(context.Context) (*Reviews, 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 ReviewsMutation) 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 ReviewsMutation) 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 Reviews entities.
func (m *ReviewsMutation) 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 *ReviewsMutation) 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 *ReviewsMutation) 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().Reviews.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 *ReviewsMutation) 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 *ReviewsMutation) 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 Reviews entity.
// If the Reviews object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ReviewsMutation) 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 *ReviewsMutation) 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 *ReviewsMutation) 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 *ReviewsMutation) ResetOrderID() {
	m.order_id = nil
	m.addorder_id = nil
}

// SetFromUserID sets the "from_user_id" field.
func (m *ReviewsMutation) SetFromUserID(i int64) {
	m.from_user_id = &i
	m.addfrom_user_id = nil
}

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

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

// AddFromUserID adds i to the "from_user_id" field.
func (m *ReviewsMutation) AddFromUserID(i int64) {
	if m.addfrom_user_id != nil {
		*m.addfrom_user_id += i
	} else {
		m.addfrom_user_id = &i
	}
}

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

// ResetFromUserID resets all changes to the "from_user_id" field.
func (m *ReviewsMutation) ResetFromUserID() {
	m.from_user_id = nil
	m.addfrom_user_id = nil
}

// SetFromUserName sets the "from_user_name" field.
func (m *ReviewsMutation) SetFromUserName(s string) {
	m.from_user_name = &s
}

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

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

// ResetFromUserName resets all changes to the "from_user_name" field.
func (m *ReviewsMutation) ResetFromUserName() {
	m.from_user_name = nil
}

// SetFromUserAvatar sets the "from_user_avatar" field.
func (m *ReviewsMutation) SetFromUserAvatar(s string) {
	m.from_user_avatar = &s
}

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

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

// ClearFromUserAvatar clears the value of the "from_user_avatar" field.
func (m *ReviewsMutation) ClearFromUserAvatar() {
	m.from_user_avatar = nil
	m.clearedFields[reviews.FieldFromUserAvatar] = struct{}{}
}

// FromUserAvatarCleared returns if the "from_user_avatar" field was cleared in this mutation.
func (m *ReviewsMutation) FromUserAvatarCleared() bool {
	_, ok := m.clearedFields[reviews.FieldFromUserAvatar]
	return ok
}

// ResetFromUserAvatar resets all changes to the "from_user_avatar" field.
func (m *ReviewsMutation) ResetFromUserAvatar() {
	m.from_user_avatar = nil
	delete(m.clearedFields, reviews.FieldFromUserAvatar)
}

// SetToUserID sets the "to_user_id" field.
func (m *ReviewsMutation) SetToUserID(i int64) {
	m.to_user_id = &i
	m.addto_user_id = nil
}

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

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

// AddToUserID adds i to the "to_user_id" field.
func (m *ReviewsMutation) AddToUserID(i int64) {
	if m.addto_user_id != nil {
		*m.addto_user_id += i
	} else {
		m.addto_user_id = &i
	}
}

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

// ResetToUserID resets all changes to the "to_user_id" field.
func (m *ReviewsMutation) ResetToUserID() {
	m.to_user_id = nil
	m.addto_user_id = nil
}

// SetRating sets the "rating" field.
func (m *ReviewsMutation) SetRating(i int16) {
	m.rating = &i
	m.addrating = nil
}

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

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

// AddRating adds i to the "rating" field.
func (m *ReviewsMutation) AddRating(i int16) {
	if m.addrating != nil {
		*m.addrating += i
	} else {
		m.addrating = &i
	}
}

// AddedRating returns the value that was added to the "rating" field in this mutation.
func (m *ReviewsMutation) AddedRating() (r int16, exists bool) {
	v := m.addrating
	if v == nil {
		return
	}
	return *v, true
}

// ResetRating resets all changes to the "rating" field.
func (m *ReviewsMutation) ResetRating() {
	m.rating = nil
	m.addrating = nil
}

// SetContent sets the "content" field.
func (m *ReviewsMutation) SetContent(s string) {
	m.content = &s
}

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

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

// ClearContent clears the value of the "content" field.
func (m *ReviewsMutation) ClearContent() {
	m.content = nil
	m.clearedFields[reviews.FieldContent] = struct{}{}
}

// ContentCleared returns if the "content" field was cleared in this mutation.
func (m *ReviewsMutation) ContentCleared() bool {
	_, ok := m.clearedFields[reviews.FieldContent]
	return ok
}

// ResetContent resets all changes to the "content" field.
func (m *ReviewsMutation) ResetContent() {
	m.content = nil
	delete(m.clearedFields, reviews.FieldContent)
}

// SetSealed sets the "sealed" field.
func (m *ReviewsMutation) SetSealed(b bool) {
	m.sealed = &b
}

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

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

// ResetSealed resets all changes to the "sealed" field.
func (m *ReviewsMutation) ResetSealed() {
	m.sealed = nil
}

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

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

// SetUnsealedAt sets the "unsealed_at" field.
func (m *ReviewsMutation) SetUnsealedAt(t time.Time) {
	m.unsealed_at = &t
}

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

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

// ClearUnsealedAt clears the value of the "unsealed_at" field.
func (m *ReviewsMutation) ClearUnsealedAt() {
	m.unsealed_at = nil
	m.clearedFields[reviews.FieldUnsealedAt] = struct{}{}
}

// UnsealedAtCleared returns if the "unsealed_at" field was cleared in this mutation.
func (m *ReviewsMutation) UnsealedAtCleared() bool {
	_, ok := m.clearedFields[reviews.FieldUnsealedAt]
	return ok
}

// ResetUnsealedAt resets all changes to the "unsealed_at" field.
func (m *ReviewsMutation) ResetUnsealedAt() {
	m.unsealed_at = nil
	delete(m.clearedFields, reviews.FieldUnsealedAt)
}

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

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

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

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

// Type returns the node type of this mutation (Reviews).
func (m *ReviewsMutation) 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 *ReviewsMutation) Fields() []string {
	fields := make([]string, 0, 10)
	if m.order_id != nil {
		fields = append(fields, reviews.FieldOrderID)
	}
	if m.from_user_id != nil {
		fields = append(fields, reviews.FieldFromUserID)
	}
	if m.from_user_name != nil {
		fields = append(fields, reviews.FieldFromUserName)
	}
	if m.from_user_avatar != nil {
		fields = append(fields, reviews.FieldFromUserAvatar)
	}
	if m.to_user_id != nil {
		fields = append(fields, reviews.FieldToUserID)
	}
	if m.rating != nil {
		fields = append(fields, reviews.FieldRating)
	}
	if m.content != nil {
		fields = append(fields, reviews.FieldContent)
	}
	if m.sealed != nil {
		fields = append(fields, reviews.FieldSealed)
	}
	if m.created_at != nil {
		fields = append(fields, reviews.FieldCreatedAt)
	}
	if m.unsealed_at != nil {
		fields = append(fields, reviews.FieldUnsealedAt)
	}
	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 *ReviewsMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case reviews.FieldOrderID:
		return m.OrderID()
	case reviews.FieldFromUserID:
		return m.FromUserID()
	case reviews.FieldFromUserName:
		return m.FromUserName()
	case reviews.FieldFromUserAvatar:
		return m.FromUserAvatar()
	case reviews.FieldToUserID:
		return m.ToUserID()
	case reviews.FieldRating:
		return m.Rating()
	case reviews.FieldContent:
		return m.Content()
	case reviews.FieldSealed:
		return m.Sealed()
	case reviews.FieldCreatedAt:
		return m.CreatedAt()
	case reviews.FieldUnsealedAt:
		return m.UnsealedAt()
	}
	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 *ReviewsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case reviews.FieldOrderID:
		return m.OldOrderID(ctx)
	case reviews.FieldFromUserID:
		return m.OldFromUserID(ctx)
	case reviews.FieldFromUserName:
		return m.OldFromUserName(ctx)
	case reviews.FieldFromUserAvatar:
		return m.OldFromUserAvatar(ctx)
	case reviews.FieldToUserID:
		return m.OldToUserID(ctx)
	case reviews.FieldRating:
		return m.OldRating(ctx)
	case reviews.FieldContent:
		return m.OldContent(ctx)
	case reviews.FieldSealed:
		return m.OldSealed(ctx)
	case reviews.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case reviews.FieldUnsealedAt:
		return m.OldUnsealedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Reviews 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 *ReviewsMutation) SetField(name string, value ent.Value) error {
	switch name {
	case reviews.FieldOrderID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderID(v)
		return nil
	case reviews.FieldFromUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFromUserID(v)
		return nil
	case reviews.FieldFromUserName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFromUserName(v)
		return nil
	case reviews.FieldFromUserAvatar:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFromUserAvatar(v)
		return nil
	case reviews.FieldToUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetToUserID(v)
		return nil
	case reviews.FieldRating:
		v, ok := value.(int16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRating(v)
		return nil
	case reviews.FieldContent:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetContent(v)
		return nil
	case reviews.FieldSealed:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSealed(v)
		return nil
	case reviews.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 reviews.FieldUnsealedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUnsealedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Reviews field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ReviewsMutation) AddedFields() []string {
	var fields []string
	if m.addorder_id != nil {
		fields = append(fields, reviews.FieldOrderID)
	}
	if m.addfrom_user_id != nil {
		fields = append(fields, reviews.FieldFromUserID)
	}
	if m.addto_user_id != nil {
		fields = append(fields, reviews.FieldToUserID)
	}
	if m.addrating != nil {
		fields = append(fields, reviews.FieldRating)
	}
	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 *ReviewsMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case reviews.FieldOrderID:
		return m.AddedOrderID()
	case reviews.FieldFromUserID:
		return m.AddedFromUserID()
	case reviews.FieldToUserID:
		return m.AddedToUserID()
	case reviews.FieldRating:
		return m.AddedRating()
	}
	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 *ReviewsMutation) AddField(name string, value ent.Value) error {
	switch name {
	case reviews.FieldOrderID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOrderID(v)
		return nil
	case reviews.FieldFromUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFromUserID(v)
		return nil
	case reviews.FieldToUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddToUserID(v)
		return nil
	case reviews.FieldRating:
		v, ok := value.(int16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRating(v)
		return nil
	}
	return fmt.Errorf("unknown Reviews numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ReviewsMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(reviews.FieldFromUserAvatar) {
		fields = append(fields, reviews.FieldFromUserAvatar)
	}
	if m.FieldCleared(reviews.FieldContent) {
		fields = append(fields, reviews.FieldContent)
	}
	if m.FieldCleared(reviews.FieldUnsealedAt) {
		fields = append(fields, reviews.FieldUnsealedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ReviewsMutation) 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 *ReviewsMutation) ClearField(name string) error {
	switch name {
	case reviews.FieldFromUserAvatar:
		m.ClearFromUserAvatar()
		return nil
	case reviews.FieldContent:
		m.ClearContent()
		return nil
	case reviews.FieldUnsealedAt:
		m.ClearUnsealedAt()
		return nil
	}
	return fmt.Errorf("unknown Reviews 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 *ReviewsMutation) ResetField(name string) error {
	switch name {
	case reviews.FieldOrderID:
		m.ResetOrderID()
		return nil
	case reviews.FieldFromUserID:
		m.ResetFromUserID()
		return nil
	case reviews.FieldFromUserName:
		m.ResetFromUserName()
		return nil
	case reviews.FieldFromUserAvatar:
		m.ResetFromUserAvatar()
		return nil
	case reviews.FieldToUserID:
		m.ResetToUserID()
		return nil
	case reviews.FieldRating:
		m.ResetRating()
		return nil
	case reviews.FieldContent:
		m.ResetContent()
		return nil
	case reviews.FieldSealed:
		m.ResetSealed()
		return nil
	case reviews.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case reviews.FieldUnsealedAt:
		m.ResetUnsealedAt()
		return nil
	}
	return fmt.Errorf("unknown Reviews field %s", name)
}

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

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

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