// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"

	"entgo.io/ent/dialect/sql"
	"github.com/cloudwego/biz-demo/open-payment-platform/internal/payment/infrastructure/ent/order"
)

// Order is the model entity for the Order schema.
type Order struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// MerchantID holds the value of the "merchant_id" field.
	MerchantID string `json:"merchant_id,omitempty"`
	// Channel holds the value of the "channel" field.
	Channel string `json:"channel,omitempty"`
	// PayWay holds the value of the "pay_way" field.
	PayWay string `json:"pay_way,omitempty"`
	// OutOrderNo holds the value of the "out_order_no" field.
	OutOrderNo string `json:"out_order_no,omitempty"`
	// TotalAmount holds the value of the "total_amount" field.
	TotalAmount uint64 `json:"total_amount,omitempty"`
	// Body holds the value of the "body" field.
	Body string `json:"body,omitempty"`
	// OrderStatus holds the value of the "order_status" field.
	OrderStatus int8 `json:"order_status,omitempty"`
	// AuthCode holds the value of the "auth_code" field.
	AuthCode string `json:"auth_code,omitempty"`
	// WxAppid holds the value of the "wx_appid" field.
	WxAppid string `json:"wx_appid,omitempty"`
	// SubOpenid holds the value of the "sub_openid" field.
	SubOpenid string `json:"sub_openid,omitempty"`
	// JumpURL holds the value of the "jump_url" field.
	JumpURL string `json:"jump_url,omitempty"`
	// NotifyURL holds the value of the "notify_url" field.
	NotifyURL string `json:"notify_url,omitempty"`
	// ClientIP holds the value of the "client_ip" field.
	ClientIP string `json:"client_ip,omitempty"`
	// Attach holds the value of the "attach" field.
	Attach string `json:"attach,omitempty"`
	// OrderExpiration holds the value of the "order_expiration" field.
	OrderExpiration string `json:"order_expiration,omitempty"`
	// ExtendParams holds the value of the "extend_params" field.
	ExtendParams string `json:"extend_params,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Order) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case order.FieldID, order.FieldTotalAmount, order.FieldOrderStatus:
			values[i] = new(sql.NullInt64)
		case order.FieldMerchantID, order.FieldChannel, order.FieldPayWay, order.FieldOutOrderNo, order.FieldBody, order.FieldAuthCode, order.FieldWxAppid, order.FieldSubOpenid, order.FieldJumpURL, order.FieldNotifyURL, order.FieldClientIP, order.FieldAttach, order.FieldOrderExpiration, order.FieldExtendParams:
			values[i] = new(sql.NullString)
		default:
			return nil, fmt.Errorf("unexpected column %q for type Order", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Order fields.
func (o *Order) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case order.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			o.ID = int(value.Int64)
		case order.FieldMerchantID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field merchant_id", values[i])
			} else if value.Valid {
				o.MerchantID = value.String
			}
		case order.FieldChannel:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field channel", values[i])
			} else if value.Valid {
				o.Channel = value.String
			}
		case order.FieldPayWay:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field pay_way", values[i])
			} else if value.Valid {
				o.PayWay = value.String
			}
		case order.FieldOutOrderNo:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field out_order_no", values[i])
			} else if value.Valid {
				o.OutOrderNo = value.String
			}
		case order.FieldTotalAmount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_amount", values[i])
			} else if value.Valid {
				o.TotalAmount = uint64(value.Int64)
			}
		case order.FieldBody:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field body", values[i])
			} else if value.Valid {
				o.Body = value.String
			}
		case order.FieldOrderStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field order_status", values[i])
			} else if value.Valid {
				o.OrderStatus = int8(value.Int64)
			}
		case order.FieldAuthCode:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field auth_code", values[i])
			} else if value.Valid {
				o.AuthCode = value.String
			}
		case order.FieldWxAppid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wx_appid", values[i])
			} else if value.Valid {
				o.WxAppid = value.String
			}
		case order.FieldSubOpenid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field sub_openid", values[i])
			} else if value.Valid {
				o.SubOpenid = value.String
			}
		case order.FieldJumpURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field jump_url", values[i])
			} else if value.Valid {
				o.JumpURL = value.String
			}
		case order.FieldNotifyURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field notify_url", values[i])
			} else if value.Valid {
				o.NotifyURL = value.String
			}
		case order.FieldClientIP:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field client_ip", values[i])
			} else if value.Valid {
				o.ClientIP = value.String
			}
		case order.FieldAttach:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field attach", values[i])
			} else if value.Valid {
				o.Attach = value.String
			}
		case order.FieldOrderExpiration:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field order_expiration", values[i])
			} else if value.Valid {
				o.OrderExpiration = value.String
			}
		case order.FieldExtendParams:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field extend_params", values[i])
			} else if value.Valid {
				o.ExtendParams = value.String
			}
		}
	}
	return nil
}

// Update returns a builder for updating this Order.
// Note that you need to call Order.Unwrap() before calling this method if this Order
// was returned from a transaction, and the transaction was committed or rolled back.
func (o *Order) Update() *OrderUpdateOne {
	return (&OrderClient{config: o.config}).UpdateOne(o)
}

// Unwrap unwraps the Order entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (o *Order) Unwrap() *Order {
	_tx, ok := o.config.driver.(*txDriver)
	if !ok {
		panic("ent: Order is not a transactional entity")
	}
	o.config.driver = _tx.drv
	return o
}

// String implements the fmt.Stringer.
func (o *Order) String() string {
	var builder strings.Builder
	builder.WriteString("Order(")
	builder.WriteString(fmt.Sprintf("id=%v, ", o.ID))
	builder.WriteString("merchant_id=")
	builder.WriteString(o.MerchantID)
	builder.WriteString(", ")
	builder.WriteString("channel=")
	builder.WriteString(o.Channel)
	builder.WriteString(", ")
	builder.WriteString("pay_way=")
	builder.WriteString(o.PayWay)
	builder.WriteString(", ")
	builder.WriteString("out_order_no=")
	builder.WriteString(o.OutOrderNo)
	builder.WriteString(", ")
	builder.WriteString("total_amount=")
	builder.WriteString(fmt.Sprintf("%v", o.TotalAmount))
	builder.WriteString(", ")
	builder.WriteString("body=")
	builder.WriteString(o.Body)
	builder.WriteString(", ")
	builder.WriteString("order_status=")
	builder.WriteString(fmt.Sprintf("%v", o.OrderStatus))
	builder.WriteString(", ")
	builder.WriteString("auth_code=")
	builder.WriteString(o.AuthCode)
	builder.WriteString(", ")
	builder.WriteString("wx_appid=")
	builder.WriteString(o.WxAppid)
	builder.WriteString(", ")
	builder.WriteString("sub_openid=")
	builder.WriteString(o.SubOpenid)
	builder.WriteString(", ")
	builder.WriteString("jump_url=")
	builder.WriteString(o.JumpURL)
	builder.WriteString(", ")
	builder.WriteString("notify_url=")
	builder.WriteString(o.NotifyURL)
	builder.WriteString(", ")
	builder.WriteString("client_ip=")
	builder.WriteString(o.ClientIP)
	builder.WriteString(", ")
	builder.WriteString("attach=")
	builder.WriteString(o.Attach)
	builder.WriteString(", ")
	builder.WriteString("order_expiration=")
	builder.WriteString(o.OrderExpiration)
	builder.WriteString(", ")
	builder.WriteString("extend_params=")
	builder.WriteString(o.ExtendParams)
	builder.WriteByte(')')
	return builder.String()
}

// Orders is a parsable slice of Order.
type Orders []*Order

func (o Orders) config(cfg config) {
	for _i := range o {
		o[_i].config = cfg
	}
}
