// Code generated by ent, DO NOT EDIT.

package models

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

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

// PlayerServices is the model entity for the PlayerServices schema.
type PlayerServices struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// PlayerID holds the value of the "player_id" field.
	PlayerID int64 `json:"player_id,omitempty"`
	// GameID holds the value of the "game_id" field.
	GameID int64 `json:"game_id,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Description holds the value of the "description" field.
	Description *string `json:"description,omitempty"`
	// Price holds the value of the "price" field.
	Price decimal.Decimal `json:"price,omitempty"`
	// Unit holds the value of the "unit" field.
	Unit string `json:"unit,omitempty"`
	// RankRange holds the value of the "rank_range" field.
	RankRange *string `json:"rank_range,omitempty"`
	// Availability holds the value of the "availability" field.
	Availability []string `json:"availability,omitempty"`
	// Rating holds the value of the "rating" field.
	Rating decimal.Decimal `json:"rating,omitempty"`
	// IsActive holds the value of the "is_active" field.
	IsActive bool `json:"is_active,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 (*PlayerServices) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case playerservices.FieldAvailability:
			values[i] = new(types.TextArray)
		case playerservices.FieldPrice, playerservices.FieldRating:
			values[i] = new(decimal.Decimal)
		case playerservices.FieldIsActive:
			values[i] = new(sql.NullBool)
		case playerservices.FieldID, playerservices.FieldPlayerID, playerservices.FieldGameID:
			values[i] = new(sql.NullInt64)
		case playerservices.FieldTitle, playerservices.FieldDescription, playerservices.FieldUnit, playerservices.FieldRankRange:
			values[i] = new(sql.NullString)
		case playerservices.FieldCreatedAt, playerservices.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 PlayerServices fields.
func (_m *PlayerServices) 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 playerservices.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 playerservices.FieldPlayerID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field player_id", values[i])
			} else if value.Valid {
				_m.PlayerID = value.Int64
			}
		case playerservices.FieldGameID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field game_id", values[i])
			} else if value.Valid {
				_m.GameID = value.Int64
			}
		case playerservices.FieldTitle:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field title", values[i])
			} else if value.Valid {
				_m.Title = value.String
			}
		case playerservices.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				_m.Description = new(string)
				*_m.Description = value.String
			}
		case playerservices.FieldPrice:
			if value, ok := values[i].(*decimal.Decimal); !ok {
				return fmt.Errorf("unexpected type %T for field price", values[i])
			} else if value != nil {
				_m.Price = *value
			}
		case playerservices.FieldUnit:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field unit", values[i])
			} else if value.Valid {
				_m.Unit = value.String
			}
		case playerservices.FieldRankRange:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field rank_range", values[i])
			} else if value.Valid {
				_m.RankRange = new(string)
				*_m.RankRange = value.String
			}
		case playerservices.FieldAvailability:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field availability", values[i])
			} else if value != nil {
				_m.Availability = append([]string{}, value.Elements...)
			}
		case playerservices.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 playerservices.FieldIsActive:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field is_active", values[i])
			} else if value.Valid {
				_m.IsActive = value.Bool
			}
		case playerservices.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 playerservices.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 PlayerServices.
// This includes values selected through modifiers, order, etc.
func (_m *PlayerServices) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

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

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

// String implements the fmt.Stringer.
func (_m *PlayerServices) String() string {
	var builder strings.Builder
	builder.WriteString("PlayerServices(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("player_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.PlayerID))
	builder.WriteString(", ")
	builder.WriteString("game_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.GameID))
	builder.WriteString(", ")
	builder.WriteString("title=")
	builder.WriteString(_m.Title)
	builder.WriteString(", ")
	if v := _m.Description; v != nil {
		builder.WriteString("description=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("price=")
	builder.WriteString(fmt.Sprintf("%v", _m.Price))
	builder.WriteString(", ")
	builder.WriteString("unit=")
	builder.WriteString(_m.Unit)
	builder.WriteString(", ")
	if v := _m.RankRange; v != nil {
		builder.WriteString("rank_range=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("availability=")
	builder.WriteString(fmt.Sprintf("%v", _m.Availability))
	builder.WriteString(", ")
	builder.WriteString("rating=")
	builder.WriteString(fmt.Sprintf("%v", _m.Rating))
	builder.WriteString(", ")
	builder.WriteString("is_active=")
	builder.WriteString(fmt.Sprintf("%v", _m.IsActive))
	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()
}

// PlayerServicesSlice is a parsable slice of PlayerServices.
type PlayerServicesSlice []*PlayerServices
