// Code generated by ent, DO NOT EDIT.

package models

import (
	"encoding/json"
	"fmt"
	"juwan-backend/app/wallet/rpc/internal/models/wallettransactions"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/shopspring/decimal"
)

// WalletTransactions is the model entity for the WalletTransactions schema.
type WalletTransactions struct {
	config `json:"-"`
	// ID of the ent.
	ID string `json:"id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID int64 `json:"user_id,omitempty"`
	// Type holds the value of the "type" field.
	Type string `json:"type,omitempty"`
	// Amount holds the value of the "amount" field.
	Amount decimal.Decimal `json:"amount,omitempty"`
	// BalanceAfter holds the value of the "balance_after" field.
	BalanceAfter decimal.Decimal `json:"balance_after,omitempty"`
	// Description holds the value of the "description" field.
	Description []string `json:"description,omitempty"`
	// OrderID holds the value of the "order_id" field.
	OrderID int64 `json:"order_id,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// SearchText holds the value of the "search_text" field.
	SearchText   string `json:"search_text,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WalletTransactions) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case wallettransactions.FieldDescription:
			values[i] = new([]byte)
		case wallettransactions.FieldAmount, wallettransactions.FieldBalanceAfter:
			values[i] = new(decimal.Decimal)
		case wallettransactions.FieldUserID, wallettransactions.FieldOrderID:
			values[i] = new(sql.NullInt64)
		case wallettransactions.FieldID, wallettransactions.FieldType, wallettransactions.FieldSearchText:
			values[i] = new(sql.NullString)
		case wallettransactions.FieldCreatedAt:
			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 WalletTransactions fields.
func (_m *WalletTransactions) 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 wallettransactions.FieldID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value.Valid {
				_m.ID = value.String
			}
		case wallettransactions.FieldUserID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				_m.UserID = value.Int64
			}
		case wallettransactions.FieldType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				_m.Type = value.String
			}
		case wallettransactions.FieldAmount:
			if value, ok := values[i].(*decimal.Decimal); !ok {
				return fmt.Errorf("unexpected type %T for field amount", values[i])
			} else if value != nil {
				_m.Amount = *value
			}
		case wallettransactions.FieldBalanceAfter:
			if value, ok := values[i].(*decimal.Decimal); !ok {
				return fmt.Errorf("unexpected type %T for field balance_after", values[i])
			} else if value != nil {
				_m.BalanceAfter = *value
			}
		case wallettransactions.FieldDescription:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Description); err != nil {
					return fmt.Errorf("unmarshal field description: %w", err)
				}
			}
		case wallettransactions.FieldOrderID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field order_id", values[i])
			} else if value.Valid {
				_m.OrderID = value.Int64
			}
		case wallettransactions.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 {
				_m.CreatedAt = value.Time
			}
		case wallettransactions.FieldSearchText:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field search_text", values[i])
			} else if value.Valid {
				_m.SearchText = value.String
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *WalletTransactions) String() string {
	var builder strings.Builder
	builder.WriteString("WalletTransactions(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.UserID))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(_m.Type)
	builder.WriteString(", ")
	builder.WriteString("amount=")
	builder.WriteString(fmt.Sprintf("%v", _m.Amount))
	builder.WriteString(", ")
	builder.WriteString("balance_after=")
	builder.WriteString(fmt.Sprintf("%v", _m.BalanceAfter))
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(fmt.Sprintf("%v", _m.Description))
	builder.WriteString(", ")
	builder.WriteString("order_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.OrderID))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("search_text=")
	builder.WriteString(_m.SearchText)
	builder.WriteByte(')')
	return builder.String()
}

// WalletTransactionsSlice is a parsable slice of WalletTransactions.
type WalletTransactionsSlice []*WalletTransactions
