// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/payrecharge"

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

// PayRecharge is the model entity for the PayRecharge schema.
type PayRecharge struct {
	config `json:"-"`
	// ID of the ent.
	ID uint64 `json:"id,omitempty"`
	// Create Time | 创建日期
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 修改日期
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// user_id | 用户ID
	UserID string `json:"user_id,omitempty"`
	// number | 变化积分数
	Number float32 `json:"number,omitempty"`
	// status | 状态 1-正常 2-禁用
	Status int `json:"status,omitempty"`
	// money | 充值钱数
	Money float32 `json:"money,omitempty"`
	// out_trade_no | 外部订单号
	OutTradeNo string `json:"out_trade_no,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	selectValues   sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*PayRecharge) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case payrecharge.FieldNumber, payrecharge.FieldMoney:
			values[i] = new(sql.NullFloat64)
		case payrecharge.FieldID, payrecharge.FieldStatus, payrecharge.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case payrecharge.FieldUserID, payrecharge.FieldOutTradeNo:
			values[i] = new(sql.NullString)
		case payrecharge.FieldCreatedAt, payrecharge.FieldUpdatedAt, payrecharge.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the PayRecharge fields.
func (pr *PayRecharge) 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 payrecharge.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			pr.ID = uint64(value.Int64)
		case payrecharge.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				pr.CreatedAt = value.Time
			}
		case payrecharge.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				pr.UpdatedAt = value.Time
			}
		case payrecharge.FieldDeletedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
			} else if value.Valid {
				pr.DeletedAt = value.Time
			}
		case payrecharge.FieldUserID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				pr.UserID = value.String
			}
		case payrecharge.FieldNumber:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field number", values[i])
			} else if value.Valid {
				pr.Number = float32(value.Float64)
			}
		case payrecharge.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				pr.Status = int(value.Int64)
			}
		case payrecharge.FieldMoney:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field money", values[i])
			} else if value.Valid {
				pr.Money = float32(value.Float64)
			}
		case payrecharge.FieldOutTradeNo:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field out_trade_no", values[i])
			} else if value.Valid {
				pr.OutTradeNo = value.String
			}
		case payrecharge.FieldOrganizationID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
			} else if value.Valid {
				pr.OrganizationID = uint64(value.Int64)
			}
		default:
			pr.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the PayRecharge.
// This includes values selected through modifiers, order, etc.
func (pr *PayRecharge) Value(name string) (ent.Value, error) {
	return pr.selectValues.Get(name)
}

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

// Unwrap unwraps the PayRecharge 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 (pr *PayRecharge) Unwrap() *PayRecharge {
	_tx, ok := pr.config.driver.(*txDriver)
	if !ok {
		panic("ent: PayRecharge is not a transactional entity")
	}
	pr.config.driver = _tx.drv
	return pr
}

// String implements the fmt.Stringer.
func (pr *PayRecharge) String() string {
	var builder strings.Builder
	builder.WriteString("PayRecharge(")
	builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID))
	builder.WriteString("created_at=")
	builder.WriteString(pr.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(pr.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(pr.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(pr.UserID)
	builder.WriteString(", ")
	builder.WriteString("number=")
	builder.WriteString(fmt.Sprintf("%v", pr.Number))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", pr.Status))
	builder.WriteString(", ")
	builder.WriteString("money=")
	builder.WriteString(fmt.Sprintf("%v", pr.Money))
	builder.WriteString(", ")
	builder.WriteString("out_trade_no=")
	builder.WriteString(pr.OutTradeNo)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", pr.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// PayRecharges is a parsable slice of PayRecharge.
type PayRecharges []*PayRecharge
