// Code generated by ent, DO NOT EDIT.

package ent

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

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

// CreditBalance is the model entity for the CreditBalance schema.
type CreditBalance 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"`
	// role | 角色设定
	Balance float32 `json:"balance,omitempty"`
	// status | 状态 1-正常 2-禁用
	Status int `json:"status,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	selectValues   sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*CreditBalance) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case creditbalance.FieldBalance:
			values[i] = new(sql.NullFloat64)
		case creditbalance.FieldID, creditbalance.FieldStatus, creditbalance.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case creditbalance.FieldUserID:
			values[i] = new(sql.NullString)
		case creditbalance.FieldCreatedAt, creditbalance.FieldUpdatedAt, creditbalance.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 CreditBalance fields.
func (cb *CreditBalance) 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 creditbalance.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			cb.ID = uint64(value.Int64)
		case creditbalance.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 {
				cb.CreatedAt = value.Time
			}
		case creditbalance.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 {
				cb.UpdatedAt = value.Time
			}
		case creditbalance.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 {
				cb.DeletedAt = value.Time
			}
		case creditbalance.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 {
				cb.UserID = value.String
			}
		case creditbalance.FieldBalance:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field balance", values[i])
			} else if value.Valid {
				cb.Balance = float32(value.Float64)
			}
		case creditbalance.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				cb.Status = int(value.Int64)
			}
		case creditbalance.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 {
				cb.OrganizationID = uint64(value.Int64)
			}
		default:
			cb.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (cb *CreditBalance) String() string {
	var builder strings.Builder
	builder.WriteString("CreditBalance(")
	builder.WriteString(fmt.Sprintf("id=%v, ", cb.ID))
	builder.WriteString("created_at=")
	builder.WriteString(cb.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(cb.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(cb.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(cb.UserID)
	builder.WriteString(", ")
	builder.WriteString("balance=")
	builder.WriteString(fmt.Sprintf("%v", cb.Balance))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", cb.Status))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", cb.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// CreditBalances is a parsable slice of CreditBalance.
type CreditBalances []*CreditBalance
