// Code generated by ent, DO NOT EDIT.

package ent

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

	"github.com/cloudwego/biz-demo/open-payment-platform/internal/payment/infrastructure/ent/order"
	"github.com/cloudwego/biz-demo/open-payment-platform/internal/payment/infrastructure/ent/predicate"

	"entgo.io/ent"
)

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

	// Node types.
	TypeOrder = "Order"
)

// OrderMutation represents an operation that mutates the Order nodes in the graph.
type OrderMutation struct {
	config
	op               Op
	typ              string
	id               *int
	merchant_id      *string
	channel          *string
	pay_way          *string
	out_order_no     *string
	total_amount     *uint64
	addtotal_amount  *int64
	body             *string
	order_status     *int8
	addorder_status  *int8
	auth_code        *string
	wx_appid         *string
	sub_openid       *string
	jump_url         *string
	notify_url       *string
	client_ip        *string
	attach           *string
	order_expiration *string
	extend_params    *string
	clearedFields    map[string]struct{}
	done             bool
	oldValue         func(context.Context) (*Order, error)
	predicates       []predicate.Order
}

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

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

// newOrderMutation creates new mutation for the Order entity.
func newOrderMutation(c config, op Op, opts ...orderOption) *OrderMutation {
	m := &OrderMutation{
		config:        c,
		op:            op,
		typ:           TypeOrder,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

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

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

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

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

// SetMerchantID sets the "merchant_id" field.
func (m *OrderMutation) SetMerchantID(s string) {
	m.merchant_id = &s
}

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

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

// ResetMerchantID resets all changes to the "merchant_id" field.
func (m *OrderMutation) ResetMerchantID() {
	m.merchant_id = nil
}

// SetChannel sets the "channel" field.
func (m *OrderMutation) SetChannel(s string) {
	m.channel = &s
}

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

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

// ResetChannel resets all changes to the "channel" field.
func (m *OrderMutation) ResetChannel() {
	m.channel = nil
}

// SetPayWay sets the "pay_way" field.
func (m *OrderMutation) SetPayWay(s string) {
	m.pay_way = &s
}

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

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

// ResetPayWay resets all changes to the "pay_way" field.
func (m *OrderMutation) ResetPayWay() {
	m.pay_way = nil
}

// SetOutOrderNo sets the "out_order_no" field.
func (m *OrderMutation) SetOutOrderNo(s string) {
	m.out_order_no = &s
}

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

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

// ResetOutOrderNo resets all changes to the "out_order_no" field.
func (m *OrderMutation) ResetOutOrderNo() {
	m.out_order_no = nil
}

// SetTotalAmount sets the "total_amount" field.
func (m *OrderMutation) SetTotalAmount(u uint64) {
	m.total_amount = &u
	m.addtotal_amount = nil
}

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

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

// AddTotalAmount adds u to the "total_amount" field.
func (m *OrderMutation) AddTotalAmount(u int64) {
	if m.addtotal_amount != nil {
		*m.addtotal_amount += u
	} else {
		m.addtotal_amount = &u
	}
}

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

// ResetTotalAmount resets all changes to the "total_amount" field.
func (m *OrderMutation) ResetTotalAmount() {
	m.total_amount = nil
	m.addtotal_amount = nil
}

// SetBody sets the "body" field.
func (m *OrderMutation) SetBody(s string) {
	m.body = &s
}

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

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

// ResetBody resets all changes to the "body" field.
func (m *OrderMutation) ResetBody() {
	m.body = nil
}

// SetOrderStatus sets the "order_status" field.
func (m *OrderMutation) SetOrderStatus(i int8) {
	m.order_status = &i
	m.addorder_status = nil
}

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

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

// AddOrderStatus adds i to the "order_status" field.
func (m *OrderMutation) AddOrderStatus(i int8) {
	if m.addorder_status != nil {
		*m.addorder_status += i
	} else {
		m.addorder_status = &i
	}
}

// AddedOrderStatus returns the value that was added to the "order_status" field in this mutation.
func (m *OrderMutation) AddedOrderStatus() (r int8, exists bool) {
	v := m.addorder_status
	if v == nil {
		return
	}
	return *v, true
}

// ResetOrderStatus resets all changes to the "order_status" field.
func (m *OrderMutation) ResetOrderStatus() {
	m.order_status = nil
	m.addorder_status = nil
}

// SetAuthCode sets the "auth_code" field.
func (m *OrderMutation) SetAuthCode(s string) {
	m.auth_code = &s
}

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

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

// ResetAuthCode resets all changes to the "auth_code" field.
func (m *OrderMutation) ResetAuthCode() {
	m.auth_code = nil
}

// SetWxAppid sets the "wx_appid" field.
func (m *OrderMutation) SetWxAppid(s string) {
	m.wx_appid = &s
}

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

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

// ResetWxAppid resets all changes to the "wx_appid" field.
func (m *OrderMutation) ResetWxAppid() {
	m.wx_appid = nil
}

// SetSubOpenid sets the "sub_openid" field.
func (m *OrderMutation) SetSubOpenid(s string) {
	m.sub_openid = &s
}

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

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

// ResetSubOpenid resets all changes to the "sub_openid" field.
func (m *OrderMutation) ResetSubOpenid() {
	m.sub_openid = nil
}

// SetJumpURL sets the "jump_url" field.
func (m *OrderMutation) SetJumpURL(s string) {
	m.jump_url = &s
}

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

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

// ResetJumpURL resets all changes to the "jump_url" field.
func (m *OrderMutation) ResetJumpURL() {
	m.jump_url = nil
}

// SetNotifyURL sets the "notify_url" field.
func (m *OrderMutation) SetNotifyURL(s string) {
	m.notify_url = &s
}

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

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

// ResetNotifyURL resets all changes to the "notify_url" field.
func (m *OrderMutation) ResetNotifyURL() {
	m.notify_url = nil
}

// SetClientIP sets the "client_ip" field.
func (m *OrderMutation) SetClientIP(s string) {
	m.client_ip = &s
}

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

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

// ResetClientIP resets all changes to the "client_ip" field.
func (m *OrderMutation) ResetClientIP() {
	m.client_ip = nil
}

// SetAttach sets the "attach" field.
func (m *OrderMutation) SetAttach(s string) {
	m.attach = &s
}

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

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

// ResetAttach resets all changes to the "attach" field.
func (m *OrderMutation) ResetAttach() {
	m.attach = nil
}

// SetOrderExpiration sets the "order_expiration" field.
func (m *OrderMutation) SetOrderExpiration(s string) {
	m.order_expiration = &s
}

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

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

// ResetOrderExpiration resets all changes to the "order_expiration" field.
func (m *OrderMutation) ResetOrderExpiration() {
	m.order_expiration = nil
}

// SetExtendParams sets the "extend_params" field.
func (m *OrderMutation) SetExtendParams(s string) {
	m.extend_params = &s
}

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

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

// ResetExtendParams resets all changes to the "extend_params" field.
func (m *OrderMutation) ResetExtendParams() {
	m.extend_params = nil
}

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

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

// Type returns the node type of this mutation (Order).
func (m *OrderMutation) 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 *OrderMutation) Fields() []string {
	fields := make([]string, 0, 16)
	if m.merchant_id != nil {
		fields = append(fields, order.FieldMerchantID)
	}
	if m.channel != nil {
		fields = append(fields, order.FieldChannel)
	}
	if m.pay_way != nil {
		fields = append(fields, order.FieldPayWay)
	}
	if m.out_order_no != nil {
		fields = append(fields, order.FieldOutOrderNo)
	}
	if m.total_amount != nil {
		fields = append(fields, order.FieldTotalAmount)
	}
	if m.body != nil {
		fields = append(fields, order.FieldBody)
	}
	if m.order_status != nil {
		fields = append(fields, order.FieldOrderStatus)
	}
	if m.auth_code != nil {
		fields = append(fields, order.FieldAuthCode)
	}
	if m.wx_appid != nil {
		fields = append(fields, order.FieldWxAppid)
	}
	if m.sub_openid != nil {
		fields = append(fields, order.FieldSubOpenid)
	}
	if m.jump_url != nil {
		fields = append(fields, order.FieldJumpURL)
	}
	if m.notify_url != nil {
		fields = append(fields, order.FieldNotifyURL)
	}
	if m.client_ip != nil {
		fields = append(fields, order.FieldClientIP)
	}
	if m.attach != nil {
		fields = append(fields, order.FieldAttach)
	}
	if m.order_expiration != nil {
		fields = append(fields, order.FieldOrderExpiration)
	}
	if m.extend_params != nil {
		fields = append(fields, order.FieldExtendParams)
	}
	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 *OrderMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case order.FieldMerchantID:
		return m.MerchantID()
	case order.FieldChannel:
		return m.Channel()
	case order.FieldPayWay:
		return m.PayWay()
	case order.FieldOutOrderNo:
		return m.OutOrderNo()
	case order.FieldTotalAmount:
		return m.TotalAmount()
	case order.FieldBody:
		return m.Body()
	case order.FieldOrderStatus:
		return m.OrderStatus()
	case order.FieldAuthCode:
		return m.AuthCode()
	case order.FieldWxAppid:
		return m.WxAppid()
	case order.FieldSubOpenid:
		return m.SubOpenid()
	case order.FieldJumpURL:
		return m.JumpURL()
	case order.FieldNotifyURL:
		return m.NotifyURL()
	case order.FieldClientIP:
		return m.ClientIP()
	case order.FieldAttach:
		return m.Attach()
	case order.FieldOrderExpiration:
		return m.OrderExpiration()
	case order.FieldExtendParams:
		return m.ExtendParams()
	}
	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 *OrderMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case order.FieldMerchantID:
		return m.OldMerchantID(ctx)
	case order.FieldChannel:
		return m.OldChannel(ctx)
	case order.FieldPayWay:
		return m.OldPayWay(ctx)
	case order.FieldOutOrderNo:
		return m.OldOutOrderNo(ctx)
	case order.FieldTotalAmount:
		return m.OldTotalAmount(ctx)
	case order.FieldBody:
		return m.OldBody(ctx)
	case order.FieldOrderStatus:
		return m.OldOrderStatus(ctx)
	case order.FieldAuthCode:
		return m.OldAuthCode(ctx)
	case order.FieldWxAppid:
		return m.OldWxAppid(ctx)
	case order.FieldSubOpenid:
		return m.OldSubOpenid(ctx)
	case order.FieldJumpURL:
		return m.OldJumpURL(ctx)
	case order.FieldNotifyURL:
		return m.OldNotifyURL(ctx)
	case order.FieldClientIP:
		return m.OldClientIP(ctx)
	case order.FieldAttach:
		return m.OldAttach(ctx)
	case order.FieldOrderExpiration:
		return m.OldOrderExpiration(ctx)
	case order.FieldExtendParams:
		return m.OldExtendParams(ctx)
	}
	return nil, fmt.Errorf("unknown Order 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 *OrderMutation) SetField(name string, value ent.Value) error {
	switch name {
	case order.FieldMerchantID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMerchantID(v)
		return nil
	case order.FieldChannel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannel(v)
		return nil
	case order.FieldPayWay:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPayWay(v)
		return nil
	case order.FieldOutOrderNo:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOutOrderNo(v)
		return nil
	case order.FieldTotalAmount:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotalAmount(v)
		return nil
	case order.FieldBody:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBody(v)
		return nil
	case order.FieldOrderStatus:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderStatus(v)
		return nil
	case order.FieldAuthCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAuthCode(v)
		return nil
	case order.FieldWxAppid:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWxAppid(v)
		return nil
	case order.FieldSubOpenid:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubOpenid(v)
		return nil
	case order.FieldJumpURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetJumpURL(v)
		return nil
	case order.FieldNotifyURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotifyURL(v)
		return nil
	case order.FieldClientIP:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetClientIP(v)
		return nil
	case order.FieldAttach:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAttach(v)
		return nil
	case order.FieldOrderExpiration:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderExpiration(v)
		return nil
	case order.FieldExtendParams:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExtendParams(v)
		return nil
	}
	return fmt.Errorf("unknown Order field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *OrderMutation) AddedFields() []string {
	var fields []string
	if m.addtotal_amount != nil {
		fields = append(fields, order.FieldTotalAmount)
	}
	if m.addorder_status != nil {
		fields = append(fields, order.FieldOrderStatus)
	}
	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 *OrderMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case order.FieldTotalAmount:
		return m.AddedTotalAmount()
	case order.FieldOrderStatus:
		return m.AddedOrderStatus()
	}
	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 *OrderMutation) AddField(name string, value ent.Value) error {
	switch name {
	case order.FieldTotalAmount:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTotalAmount(v)
		return nil
	case order.FieldOrderStatus:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOrderStatus(v)
		return nil
	}
	return fmt.Errorf("unknown Order numeric field %s", name)
}

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

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *OrderMutation) 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 *OrderMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Order 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 *OrderMutation) ResetField(name string) error {
	switch name {
	case order.FieldMerchantID:
		m.ResetMerchantID()
		return nil
	case order.FieldChannel:
		m.ResetChannel()
		return nil
	case order.FieldPayWay:
		m.ResetPayWay()
		return nil
	case order.FieldOutOrderNo:
		m.ResetOutOrderNo()
		return nil
	case order.FieldTotalAmount:
		m.ResetTotalAmount()
		return nil
	case order.FieldBody:
		m.ResetBody()
		return nil
	case order.FieldOrderStatus:
		m.ResetOrderStatus()
		return nil
	case order.FieldAuthCode:
		m.ResetAuthCode()
		return nil
	case order.FieldWxAppid:
		m.ResetWxAppid()
		return nil
	case order.FieldSubOpenid:
		m.ResetSubOpenid()
		return nil
	case order.FieldJumpURL:
		m.ResetJumpURL()
		return nil
	case order.FieldNotifyURL:
		m.ResetNotifyURL()
		return nil
	case order.FieldClientIP:
		m.ResetClientIP()
		return nil
	case order.FieldAttach:
		m.ResetAttach()
		return nil
	case order.FieldOrderExpiration:
		m.ResetOrderExpiration()
		return nil
	case order.FieldExtendParams:
		m.ResetExtendParams()
		return nil
	}
	return fmt.Errorf("unknown Order field %s", name)
}

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

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

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