// Code generated by ent, DO NOT EDIT.

package models

import (
	"fmt"
	"juwan-backend/app/player/rpc/internal/models/players"
	"juwan-backend/pkg/types"
	"strings"
	"time"

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

// Players is the model entity for the Players schema.
type Players struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID int64 `json:"user_id,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
	// Gender holds the value of the "gender" field.
	Gender bool `json:"gender,omitempty"`
	// Rating holds the value of the "rating" field.
	Rating decimal.Decimal `json:"rating,omitempty"`
	// TotalOrders holds the value of the "total_orders" field.
	TotalOrders int `json:"total_orders,omitempty"`
	// CompletedOrders holds the value of the "completed_orders" field.
	CompletedOrders int `json:"completed_orders,omitempty"`
	// ShopID holds the value of the "shop_id" field.
	ShopID *int64 `json:"shop_id,omitempty"`
	// Tags holds the value of the "tags" field.
	Tags []string `json:"tags,omitempty"`
	// Games holds the value of the "games" field.
	Games pq.Int64Array `json:"games,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt    time.Time `json:"updated_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Players) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case players.FieldTags:
			values[i] = new(types.TextArray)
		case players.FieldRating:
			values[i] = new(decimal.Decimal)
		case players.FieldGames:
			values[i] = new(pq.Int64Array)
		case players.FieldGender:
			values[i] = new(sql.NullBool)
		case players.FieldID, players.FieldUserID, players.FieldTotalOrders, players.FieldCompletedOrders, players.FieldShopID:
			values[i] = new(sql.NullInt64)
		case players.FieldStatus:
			values[i] = new(sql.NullString)
		case players.FieldCreatedAt, players.FieldUpdatedAt:
			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 Players fields.
func (_m *Players) 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 players.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case players.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 players.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_m.Status = value.String
			}
		case players.FieldGender:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field gender", values[i])
			} else if value.Valid {
				_m.Gender = value.Bool
			}
		case players.FieldRating:
			if value, ok := values[i].(*decimal.Decimal); !ok {
				return fmt.Errorf("unexpected type %T for field rating", values[i])
			} else if value != nil {
				_m.Rating = *value
			}
		case players.FieldTotalOrders:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_orders", values[i])
			} else if value.Valid {
				_m.TotalOrders = int(value.Int64)
			}
		case players.FieldCompletedOrders:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field completed_orders", values[i])
			} else if value.Valid {
				_m.CompletedOrders = int(value.Int64)
			}
		case players.FieldShopID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field shop_id", values[i])
			} else if value.Valid {
				_m.ShopID = new(int64)
				*_m.ShopID = value.Int64
			}
		case players.FieldTags:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field tags", values[i])
			} else if value != nil {
				_m.Tags = append([]string{}, value.Elements...)
			}
		case players.FieldGames:
			if value, ok := values[i].(*pq.Int64Array); !ok {
				return fmt.Errorf("unexpected type %T for field games", values[i])
			} else if value != nil {
				_m.Games = *value
			}
		case players.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 players.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 {
				_m.UpdatedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *Players) String() string {
	var builder strings.Builder
	builder.WriteString("Players(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.UserID))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(_m.Status)
	builder.WriteString(", ")
	builder.WriteString("gender=")
	builder.WriteString(fmt.Sprintf("%v", _m.Gender))
	builder.WriteString(", ")
	builder.WriteString("rating=")
	builder.WriteString(fmt.Sprintf("%v", _m.Rating))
	builder.WriteString(", ")
	builder.WriteString("total_orders=")
	builder.WriteString(fmt.Sprintf("%v", _m.TotalOrders))
	builder.WriteString(", ")
	builder.WriteString("completed_orders=")
	builder.WriteString(fmt.Sprintf("%v", _m.CompletedOrders))
	builder.WriteString(", ")
	if v := _m.ShopID; v != nil {
		builder.WriteString("shop_id=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	builder.WriteString("tags=")
	builder.WriteString(fmt.Sprintf("%v", _m.Tags))
	builder.WriteString(", ")
	builder.WriteString("games=")
	builder.WriteString(fmt.Sprintf("%v", _m.Games))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// PlayersSlice is a parsable slice of Players.
type PlayersSlice []*Players
