// Code generated by ent, DO NOT EDIT.

package models

import (
	"context"
	"errors"
	"fmt"
	"juwan-backend/app/player/rpc/internal/models/players"
	"juwan-backend/app/player/rpc/internal/models/playerservices"
	"juwan-backend/app/player/rpc/internal/models/predicate"
	"sync"
	"time"

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

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypePlayerServices = "PlayerServices"
	TypePlayers        = "Players"
)

// PlayerServicesMutation represents an operation that mutates the PlayerServices nodes in the graph.
type PlayerServicesMutation struct {
	config
	op                 Op
	typ                string
	id                 *int64
	player_id          *int64
	addplayer_id       *int64
	game_id            *int64
	addgame_id         *int64
	title              *string
	description        *string
	price              *decimal.Decimal
	unit               *string
	rank_range         *string
	availability       *[]string
	appendavailability []string
	rating             *decimal.Decimal
	is_active          *bool
	created_at         *time.Time
	updated_at         *time.Time
	clearedFields      map[string]struct{}
	done               bool
	oldValue           func(context.Context) (*PlayerServices, error)
	predicates         []predicate.PlayerServices
}

var _ ent.Mutation = (*PlayerServicesMutation)(nil)

// playerservicesOption allows management of the mutation configuration using functional options.
type playerservicesOption func(*PlayerServicesMutation)

// newPlayerServicesMutation creates new mutation for the PlayerServices entity.
func newPlayerServicesMutation(c config, op Op, opts ...playerservicesOption) *PlayerServicesMutation {
	m := &PlayerServicesMutation{
		config:        c,
		op:            op,
		typ:           TypePlayerServices,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPlayerServicesID sets the ID field of the mutation.
func withPlayerServicesID(id int64) playerservicesOption {
	return func(m *PlayerServicesMutation) {
		var (
			err   error
			once  sync.Once
			value *PlayerServices
		)
		m.oldValue = func(ctx context.Context) (*PlayerServices, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PlayerServices.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPlayerServices sets the old PlayerServices of the mutation.
func withPlayerServices(node *PlayerServices) playerservicesOption {
	return func(m *PlayerServicesMutation) {
		m.oldValue = func(context.Context) (*PlayerServices, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PlayerServicesMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PlayerServicesMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("models: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of PlayerServices entities.
func (m *PlayerServicesMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PlayerServicesMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PlayerServicesMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PlayerServices.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetPlayerID sets the "player_id" field.
func (m *PlayerServicesMutation) SetPlayerID(i int64) {
	m.player_id = &i
	m.addplayer_id = nil
}

// PlayerID returns the value of the "player_id" field in the mutation.
func (m *PlayerServicesMutation) PlayerID() (r int64, exists bool) {
	v := m.player_id
	if v == nil {
		return
	}
	return *v, true
}

// OldPlayerID returns the old "player_id" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldPlayerID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlayerID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlayerID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlayerID: %w", err)
	}
	return oldValue.PlayerID, nil
}

// AddPlayerID adds i to the "player_id" field.
func (m *PlayerServicesMutation) AddPlayerID(i int64) {
	if m.addplayer_id != nil {
		*m.addplayer_id += i
	} else {
		m.addplayer_id = &i
	}
}

// AddedPlayerID returns the value that was added to the "player_id" field in this mutation.
func (m *PlayerServicesMutation) AddedPlayerID() (r int64, exists bool) {
	v := m.addplayer_id
	if v == nil {
		return
	}
	return *v, true
}

// ResetPlayerID resets all changes to the "player_id" field.
func (m *PlayerServicesMutation) ResetPlayerID() {
	m.player_id = nil
	m.addplayer_id = nil
}

// SetGameID sets the "game_id" field.
func (m *PlayerServicesMutation) SetGameID(i int64) {
	m.game_id = &i
	m.addgame_id = nil
}

// GameID returns the value of the "game_id" field in the mutation.
func (m *PlayerServicesMutation) GameID() (r int64, exists bool) {
	v := m.game_id
	if v == nil {
		return
	}
	return *v, true
}

// OldGameID returns the old "game_id" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldGameID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGameID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGameID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGameID: %w", err)
	}
	return oldValue.GameID, nil
}

// AddGameID adds i to the "game_id" field.
func (m *PlayerServicesMutation) AddGameID(i int64) {
	if m.addgame_id != nil {
		*m.addgame_id += i
	} else {
		m.addgame_id = &i
	}
}

// AddedGameID returns the value that was added to the "game_id" field in this mutation.
func (m *PlayerServicesMutation) AddedGameID() (r int64, exists bool) {
	v := m.addgame_id
	if v == nil {
		return
	}
	return *v, true
}

// ResetGameID resets all changes to the "game_id" field.
func (m *PlayerServicesMutation) ResetGameID() {
	m.game_id = nil
	m.addgame_id = nil
}

// SetTitle sets the "title" field.
func (m *PlayerServicesMutation) SetTitle(s string) {
	m.title = &s
}

// Title returns the value of the "title" field in the mutation.
func (m *PlayerServicesMutation) Title() (r string, exists bool) {
	v := m.title
	if v == nil {
		return
	}
	return *v, true
}

// OldTitle returns the old "title" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldTitle(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTitle is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTitle requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTitle: %w", err)
	}
	return oldValue.Title, nil
}

// ResetTitle resets all changes to the "title" field.
func (m *PlayerServicesMutation) ResetTitle() {
	m.title = nil
}

// SetDescription sets the "description" field.
func (m *PlayerServicesMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *PlayerServicesMutation) Description() (r string, exists bool) {
	v := m.description
	if v == nil {
		return
	}
	return *v, true
}

// OldDescription returns the old "description" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldDescription(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDescription is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDescription requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDescription: %w", err)
	}
	return oldValue.Description, nil
}

// ClearDescription clears the value of the "description" field.
func (m *PlayerServicesMutation) ClearDescription() {
	m.description = nil
	m.clearedFields[playerservices.FieldDescription] = struct{}{}
}

// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *PlayerServicesMutation) DescriptionCleared() bool {
	_, ok := m.clearedFields[playerservices.FieldDescription]
	return ok
}

// ResetDescription resets all changes to the "description" field.
func (m *PlayerServicesMutation) ResetDescription() {
	m.description = nil
	delete(m.clearedFields, playerservices.FieldDescription)
}

// SetPrice sets the "price" field.
func (m *PlayerServicesMutation) SetPrice(d decimal.Decimal) {
	m.price = &d
}

// Price returns the value of the "price" field in the mutation.
func (m *PlayerServicesMutation) Price() (r decimal.Decimal, exists bool) {
	v := m.price
	if v == nil {
		return
	}
	return *v, true
}

// OldPrice returns the old "price" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldPrice(ctx context.Context) (v decimal.Decimal, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPrice is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPrice requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPrice: %w", err)
	}
	return oldValue.Price, nil
}

// ResetPrice resets all changes to the "price" field.
func (m *PlayerServicesMutation) ResetPrice() {
	m.price = nil
}

// SetUnit sets the "unit" field.
func (m *PlayerServicesMutation) SetUnit(s string) {
	m.unit = &s
}

// Unit returns the value of the "unit" field in the mutation.
func (m *PlayerServicesMutation) Unit() (r string, exists bool) {
	v := m.unit
	if v == nil {
		return
	}
	return *v, true
}

// OldUnit returns the old "unit" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldUnit(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUnit is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUnit requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUnit: %w", err)
	}
	return oldValue.Unit, nil
}

// ResetUnit resets all changes to the "unit" field.
func (m *PlayerServicesMutation) ResetUnit() {
	m.unit = nil
}

// SetRankRange sets the "rank_range" field.
func (m *PlayerServicesMutation) SetRankRange(s string) {
	m.rank_range = &s
}

// RankRange returns the value of the "rank_range" field in the mutation.
func (m *PlayerServicesMutation) RankRange() (r string, exists bool) {
	v := m.rank_range
	if v == nil {
		return
	}
	return *v, true
}

// OldRankRange returns the old "rank_range" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldRankRange(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRankRange is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRankRange requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRankRange: %w", err)
	}
	return oldValue.RankRange, nil
}

// ClearRankRange clears the value of the "rank_range" field.
func (m *PlayerServicesMutation) ClearRankRange() {
	m.rank_range = nil
	m.clearedFields[playerservices.FieldRankRange] = struct{}{}
}

// RankRangeCleared returns if the "rank_range" field was cleared in this mutation.
func (m *PlayerServicesMutation) RankRangeCleared() bool {
	_, ok := m.clearedFields[playerservices.FieldRankRange]
	return ok
}

// ResetRankRange resets all changes to the "rank_range" field.
func (m *PlayerServicesMutation) ResetRankRange() {
	m.rank_range = nil
	delete(m.clearedFields, playerservices.FieldRankRange)
}

// SetAvailability sets the "availability" field.
func (m *PlayerServicesMutation) SetAvailability(s []string) {
	m.availability = &s
	m.appendavailability = nil
}

// Availability returns the value of the "availability" field in the mutation.
func (m *PlayerServicesMutation) Availability() (r []string, exists bool) {
	v := m.availability
	if v == nil {
		return
	}
	return *v, true
}

// OldAvailability returns the old "availability" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldAvailability(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAvailability is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAvailability requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAvailability: %w", err)
	}
	return oldValue.Availability, nil
}

// AppendAvailability adds s to the "availability" field.
func (m *PlayerServicesMutation) AppendAvailability(s []string) {
	m.appendavailability = append(m.appendavailability, s...)
}

// AppendedAvailability returns the list of values that were appended to the "availability" field in this mutation.
func (m *PlayerServicesMutation) AppendedAvailability() ([]string, bool) {
	if len(m.appendavailability) == 0 {
		return nil, false
	}
	return m.appendavailability, true
}

// ClearAvailability clears the value of the "availability" field.
func (m *PlayerServicesMutation) ClearAvailability() {
	m.availability = nil
	m.appendavailability = nil
	m.clearedFields[playerservices.FieldAvailability] = struct{}{}
}

// AvailabilityCleared returns if the "availability" field was cleared in this mutation.
func (m *PlayerServicesMutation) AvailabilityCleared() bool {
	_, ok := m.clearedFields[playerservices.FieldAvailability]
	return ok
}

// ResetAvailability resets all changes to the "availability" field.
func (m *PlayerServicesMutation) ResetAvailability() {
	m.availability = nil
	m.appendavailability = nil
	delete(m.clearedFields, playerservices.FieldAvailability)
}

// SetRating sets the "rating" field.
func (m *PlayerServicesMutation) SetRating(d decimal.Decimal) {
	m.rating = &d
}

// Rating returns the value of the "rating" field in the mutation.
func (m *PlayerServicesMutation) Rating() (r decimal.Decimal, exists bool) {
	v := m.rating
	if v == nil {
		return
	}
	return *v, true
}

// OldRating returns the old "rating" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldRating(ctx context.Context) (v decimal.Decimal, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRating is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRating requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRating: %w", err)
	}
	return oldValue.Rating, nil
}

// ResetRating resets all changes to the "rating" field.
func (m *PlayerServicesMutation) ResetRating() {
	m.rating = nil
}

// SetIsActive sets the "is_active" field.
func (m *PlayerServicesMutation) SetIsActive(b bool) {
	m.is_active = &b
}

// IsActive returns the value of the "is_active" field in the mutation.
func (m *PlayerServicesMutation) IsActive() (r bool, exists bool) {
	v := m.is_active
	if v == nil {
		return
	}
	return *v, true
}

// OldIsActive returns the old "is_active" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldIsActive(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIsActive is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIsActive requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIsActive: %w", err)
	}
	return oldValue.IsActive, nil
}

// ClearIsActive clears the value of the "is_active" field.
func (m *PlayerServicesMutation) ClearIsActive() {
	m.is_active = nil
	m.clearedFields[playerservices.FieldIsActive] = struct{}{}
}

// IsActiveCleared returns if the "is_active" field was cleared in this mutation.
func (m *PlayerServicesMutation) IsActiveCleared() bool {
	_, ok := m.clearedFields[playerservices.FieldIsActive]
	return ok
}

// ResetIsActive resets all changes to the "is_active" field.
func (m *PlayerServicesMutation) ResetIsActive() {
	m.is_active = nil
	delete(m.clearedFields, playerservices.FieldIsActive)
}

// SetCreatedAt sets the "created_at" field.
func (m *PlayerServicesMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PlayerServicesMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedAt returns the old "created_at" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
	}
	return oldValue.CreatedAt, nil
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PlayerServicesMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PlayerServicesMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PlayerServicesMutation) UpdatedAt() (r time.Time, exists bool) {
	v := m.updated_at
	if v == nil {
		return
	}
	return *v, true
}

// OldUpdatedAt returns the old "updated_at" field's value of the PlayerServices entity.
// If the PlayerServices object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerServicesMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
	}
	return oldValue.UpdatedAt, nil
}

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PlayerServicesMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// Where appends a list predicates to the PlayerServicesMutation builder.
func (m *PlayerServicesMutation) Where(ps ...predicate.PlayerServices) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PlayerServicesMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PlayerServicesMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PlayerServices, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PlayerServicesMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PlayerServicesMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PlayerServices).
func (m *PlayerServicesMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PlayerServicesMutation) Fields() []string {
	fields := make([]string, 0, 12)
	if m.player_id != nil {
		fields = append(fields, playerservices.FieldPlayerID)
	}
	if m.game_id != nil {
		fields = append(fields, playerservices.FieldGameID)
	}
	if m.title != nil {
		fields = append(fields, playerservices.FieldTitle)
	}
	if m.description != nil {
		fields = append(fields, playerservices.FieldDescription)
	}
	if m.price != nil {
		fields = append(fields, playerservices.FieldPrice)
	}
	if m.unit != nil {
		fields = append(fields, playerservices.FieldUnit)
	}
	if m.rank_range != nil {
		fields = append(fields, playerservices.FieldRankRange)
	}
	if m.availability != nil {
		fields = append(fields, playerservices.FieldAvailability)
	}
	if m.rating != nil {
		fields = append(fields, playerservices.FieldRating)
	}
	if m.is_active != nil {
		fields = append(fields, playerservices.FieldIsActive)
	}
	if m.created_at != nil {
		fields = append(fields, playerservices.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, playerservices.FieldUpdatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PlayerServicesMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case playerservices.FieldPlayerID:
		return m.PlayerID()
	case playerservices.FieldGameID:
		return m.GameID()
	case playerservices.FieldTitle:
		return m.Title()
	case playerservices.FieldDescription:
		return m.Description()
	case playerservices.FieldPrice:
		return m.Price()
	case playerservices.FieldUnit:
		return m.Unit()
	case playerservices.FieldRankRange:
		return m.RankRange()
	case playerservices.FieldAvailability:
		return m.Availability()
	case playerservices.FieldRating:
		return m.Rating()
	case playerservices.FieldIsActive:
		return m.IsActive()
	case playerservices.FieldCreatedAt:
		return m.CreatedAt()
	case playerservices.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PlayerServicesMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case playerservices.FieldPlayerID:
		return m.OldPlayerID(ctx)
	case playerservices.FieldGameID:
		return m.OldGameID(ctx)
	case playerservices.FieldTitle:
		return m.OldTitle(ctx)
	case playerservices.FieldDescription:
		return m.OldDescription(ctx)
	case playerservices.FieldPrice:
		return m.OldPrice(ctx)
	case playerservices.FieldUnit:
		return m.OldUnit(ctx)
	case playerservices.FieldRankRange:
		return m.OldRankRange(ctx)
	case playerservices.FieldAvailability:
		return m.OldAvailability(ctx)
	case playerservices.FieldRating:
		return m.OldRating(ctx)
	case playerservices.FieldIsActive:
		return m.OldIsActive(ctx)
	case playerservices.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case playerservices.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PlayerServices field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlayerServicesMutation) SetField(name string, value ent.Value) error {
	switch name {
	case playerservices.FieldPlayerID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlayerID(v)
		return nil
	case playerservices.FieldGameID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGameID(v)
		return nil
	case playerservices.FieldTitle:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTitle(v)
		return nil
	case playerservices.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case playerservices.FieldPrice:
		v, ok := value.(decimal.Decimal)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrice(v)
		return nil
	case playerservices.FieldUnit:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUnit(v)
		return nil
	case playerservices.FieldRankRange:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRankRange(v)
		return nil
	case playerservices.FieldAvailability:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAvailability(v)
		return nil
	case playerservices.FieldRating:
		v, ok := value.(decimal.Decimal)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRating(v)
		return nil
	case playerservices.FieldIsActive:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIsActive(v)
		return nil
	case playerservices.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case playerservices.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PlayerServices field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PlayerServicesMutation) AddedFields() []string {
	var fields []string
	if m.addplayer_id != nil {
		fields = append(fields, playerservices.FieldPlayerID)
	}
	if m.addgame_id != nil {
		fields = append(fields, playerservices.FieldGameID)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PlayerServicesMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case playerservices.FieldPlayerID:
		return m.AddedPlayerID()
	case playerservices.FieldGameID:
		return m.AddedGameID()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlayerServicesMutation) AddField(name string, value ent.Value) error {
	switch name {
	case playerservices.FieldPlayerID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlayerID(v)
		return nil
	case playerservices.FieldGameID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddGameID(v)
		return nil
	}
	return fmt.Errorf("unknown PlayerServices numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PlayerServicesMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(playerservices.FieldDescription) {
		fields = append(fields, playerservices.FieldDescription)
	}
	if m.FieldCleared(playerservices.FieldRankRange) {
		fields = append(fields, playerservices.FieldRankRange)
	}
	if m.FieldCleared(playerservices.FieldAvailability) {
		fields = append(fields, playerservices.FieldAvailability)
	}
	if m.FieldCleared(playerservices.FieldIsActive) {
		fields = append(fields, playerservices.FieldIsActive)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PlayerServicesMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PlayerServicesMutation) ClearField(name string) error {
	switch name {
	case playerservices.FieldDescription:
		m.ClearDescription()
		return nil
	case playerservices.FieldRankRange:
		m.ClearRankRange()
		return nil
	case playerservices.FieldAvailability:
		m.ClearAvailability()
		return nil
	case playerservices.FieldIsActive:
		m.ClearIsActive()
		return nil
	}
	return fmt.Errorf("unknown PlayerServices nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PlayerServicesMutation) ResetField(name string) error {
	switch name {
	case playerservices.FieldPlayerID:
		m.ResetPlayerID()
		return nil
	case playerservices.FieldGameID:
		m.ResetGameID()
		return nil
	case playerservices.FieldTitle:
		m.ResetTitle()
		return nil
	case playerservices.FieldDescription:
		m.ResetDescription()
		return nil
	case playerservices.FieldPrice:
		m.ResetPrice()
		return nil
	case playerservices.FieldUnit:
		m.ResetUnit()
		return nil
	case playerservices.FieldRankRange:
		m.ResetRankRange()
		return nil
	case playerservices.FieldAvailability:
		m.ResetAvailability()
		return nil
	case playerservices.FieldRating:
		m.ResetRating()
		return nil
	case playerservices.FieldIsActive:
		m.ResetIsActive()
		return nil
	case playerservices.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case playerservices.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown PlayerServices field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PlayerServicesMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PlayerServicesMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PlayerServicesMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PlayerServicesMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PlayerServicesMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PlayerServicesMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PlayerServicesMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown PlayerServices unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *PlayerServicesMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown PlayerServices edge %s", name)
}

// PlayersMutation represents an operation that mutates the Players nodes in the graph.
type PlayersMutation struct {
	config
	op                  Op
	typ                 string
	id                  *int64
	user_id             *int64
	adduser_id          *int64
	status              *string
	gender              *bool
	rating              *decimal.Decimal
	total_orders        *int
	addtotal_orders     *int
	completed_orders    *int
	addcompleted_orders *int
	shop_id             *int64
	addshop_id          *int64
	tags                *[]string
	appendtags          []string
	games               *pq.Int64Array
	created_at          *time.Time
	updated_at          *time.Time
	clearedFields       map[string]struct{}
	done                bool
	oldValue            func(context.Context) (*Players, error)
	predicates          []predicate.Players
}

var _ ent.Mutation = (*PlayersMutation)(nil)

// playersOption allows management of the mutation configuration using functional options.
type playersOption func(*PlayersMutation)

// newPlayersMutation creates new mutation for the Players entity.
func newPlayersMutation(c config, op Op, opts ...playersOption) *PlayersMutation {
	m := &PlayersMutation{
		config:        c,
		op:            op,
		typ:           TypePlayers,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPlayersID sets the ID field of the mutation.
func withPlayersID(id int64) playersOption {
	return func(m *PlayersMutation) {
		var (
			err   error
			once  sync.Once
			value *Players
		)
		m.oldValue = func(ctx context.Context) (*Players, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Players.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPlayers sets the old Players of the mutation.
func withPlayers(node *Players) playersOption {
	return func(m *PlayersMutation) {
		m.oldValue = func(context.Context) (*Players, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PlayersMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PlayersMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("models: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Players entities.
func (m *PlayersMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PlayersMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PlayersMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Players.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetUserID sets the "user_id" field.
func (m *PlayersMutation) SetUserID(i int64) {
	m.user_id = &i
	m.adduser_id = nil
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *PlayersMutation) UserID() (r int64, exists bool) {
	v := m.user_id
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// AddUserID adds i to the "user_id" field.
func (m *PlayersMutation) AddUserID(i int64) {
	if m.adduser_id != nil {
		*m.adduser_id += i
	} else {
		m.adduser_id = &i
	}
}

// AddedUserID returns the value that was added to the "user_id" field in this mutation.
func (m *PlayersMutation) AddedUserID() (r int64, exists bool) {
	v := m.adduser_id
	if v == nil {
		return
	}
	return *v, true
}

// ResetUserID resets all changes to the "user_id" field.
func (m *PlayersMutation) ResetUserID() {
	m.user_id = nil
	m.adduser_id = nil
}

// SetStatus sets the "status" field.
func (m *PlayersMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *PlayersMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldStatus(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStatus is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStatus requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStatus: %w", err)
	}
	return oldValue.Status, nil
}

// ResetStatus resets all changes to the "status" field.
func (m *PlayersMutation) ResetStatus() {
	m.status = nil
}

// SetGender sets the "gender" field.
func (m *PlayersMutation) SetGender(b bool) {
	m.gender = &b
}

// Gender returns the value of the "gender" field in the mutation.
func (m *PlayersMutation) Gender() (r bool, exists bool) {
	v := m.gender
	if v == nil {
		return
	}
	return *v, true
}

// OldGender returns the old "gender" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldGender(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGender is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGender requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGender: %w", err)
	}
	return oldValue.Gender, nil
}

// ResetGender resets all changes to the "gender" field.
func (m *PlayersMutation) ResetGender() {
	m.gender = nil
}

// SetRating sets the "rating" field.
func (m *PlayersMutation) SetRating(d decimal.Decimal) {
	m.rating = &d
}

// Rating returns the value of the "rating" field in the mutation.
func (m *PlayersMutation) Rating() (r decimal.Decimal, exists bool) {
	v := m.rating
	if v == nil {
		return
	}
	return *v, true
}

// OldRating returns the old "rating" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldRating(ctx context.Context) (v decimal.Decimal, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRating is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRating requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRating: %w", err)
	}
	return oldValue.Rating, nil
}

// ClearRating clears the value of the "rating" field.
func (m *PlayersMutation) ClearRating() {
	m.rating = nil
	m.clearedFields[players.FieldRating] = struct{}{}
}

// RatingCleared returns if the "rating" field was cleared in this mutation.
func (m *PlayersMutation) RatingCleared() bool {
	_, ok := m.clearedFields[players.FieldRating]
	return ok
}

// ResetRating resets all changes to the "rating" field.
func (m *PlayersMutation) ResetRating() {
	m.rating = nil
	delete(m.clearedFields, players.FieldRating)
}

// SetTotalOrders sets the "total_orders" field.
func (m *PlayersMutation) SetTotalOrders(i int) {
	m.total_orders = &i
	m.addtotal_orders = nil
}

// TotalOrders returns the value of the "total_orders" field in the mutation.
func (m *PlayersMutation) TotalOrders() (r int, exists bool) {
	v := m.total_orders
	if v == nil {
		return
	}
	return *v, true
}

// OldTotalOrders returns the old "total_orders" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldTotalOrders(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotalOrders is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotalOrders requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotalOrders: %w", err)
	}
	return oldValue.TotalOrders, nil
}

// AddTotalOrders adds i to the "total_orders" field.
func (m *PlayersMutation) AddTotalOrders(i int) {
	if m.addtotal_orders != nil {
		*m.addtotal_orders += i
	} else {
		m.addtotal_orders = &i
	}
}

// AddedTotalOrders returns the value that was added to the "total_orders" field in this mutation.
func (m *PlayersMutation) AddedTotalOrders() (r int, exists bool) {
	v := m.addtotal_orders
	if v == nil {
		return
	}
	return *v, true
}

// ClearTotalOrders clears the value of the "total_orders" field.
func (m *PlayersMutation) ClearTotalOrders() {
	m.total_orders = nil
	m.addtotal_orders = nil
	m.clearedFields[players.FieldTotalOrders] = struct{}{}
}

// TotalOrdersCleared returns if the "total_orders" field was cleared in this mutation.
func (m *PlayersMutation) TotalOrdersCleared() bool {
	_, ok := m.clearedFields[players.FieldTotalOrders]
	return ok
}

// ResetTotalOrders resets all changes to the "total_orders" field.
func (m *PlayersMutation) ResetTotalOrders() {
	m.total_orders = nil
	m.addtotal_orders = nil
	delete(m.clearedFields, players.FieldTotalOrders)
}

// SetCompletedOrders sets the "completed_orders" field.
func (m *PlayersMutation) SetCompletedOrders(i int) {
	m.completed_orders = &i
	m.addcompleted_orders = nil
}

// CompletedOrders returns the value of the "completed_orders" field in the mutation.
func (m *PlayersMutation) CompletedOrders() (r int, exists bool) {
	v := m.completed_orders
	if v == nil {
		return
	}
	return *v, true
}

// OldCompletedOrders returns the old "completed_orders" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldCompletedOrders(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCompletedOrders is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCompletedOrders requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCompletedOrders: %w", err)
	}
	return oldValue.CompletedOrders, nil
}

// AddCompletedOrders adds i to the "completed_orders" field.
func (m *PlayersMutation) AddCompletedOrders(i int) {
	if m.addcompleted_orders != nil {
		*m.addcompleted_orders += i
	} else {
		m.addcompleted_orders = &i
	}
}

// AddedCompletedOrders returns the value that was added to the "completed_orders" field in this mutation.
func (m *PlayersMutation) AddedCompletedOrders() (r int, exists bool) {
	v := m.addcompleted_orders
	if v == nil {
		return
	}
	return *v, true
}

// ClearCompletedOrders clears the value of the "completed_orders" field.
func (m *PlayersMutation) ClearCompletedOrders() {
	m.completed_orders = nil
	m.addcompleted_orders = nil
	m.clearedFields[players.FieldCompletedOrders] = struct{}{}
}

// CompletedOrdersCleared returns if the "completed_orders" field was cleared in this mutation.
func (m *PlayersMutation) CompletedOrdersCleared() bool {
	_, ok := m.clearedFields[players.FieldCompletedOrders]
	return ok
}

// ResetCompletedOrders resets all changes to the "completed_orders" field.
func (m *PlayersMutation) ResetCompletedOrders() {
	m.completed_orders = nil
	m.addcompleted_orders = nil
	delete(m.clearedFields, players.FieldCompletedOrders)
}

// SetShopID sets the "shop_id" field.
func (m *PlayersMutation) SetShopID(i int64) {
	m.shop_id = &i
	m.addshop_id = nil
}

// ShopID returns the value of the "shop_id" field in the mutation.
func (m *PlayersMutation) ShopID() (r int64, exists bool) {
	v := m.shop_id
	if v == nil {
		return
	}
	return *v, true
}

// OldShopID returns the old "shop_id" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldShopID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldShopID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldShopID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldShopID: %w", err)
	}
	return oldValue.ShopID, nil
}

// AddShopID adds i to the "shop_id" field.
func (m *PlayersMutation) AddShopID(i int64) {
	if m.addshop_id != nil {
		*m.addshop_id += i
	} else {
		m.addshop_id = &i
	}
}

// AddedShopID returns the value that was added to the "shop_id" field in this mutation.
func (m *PlayersMutation) AddedShopID() (r int64, exists bool) {
	v := m.addshop_id
	if v == nil {
		return
	}
	return *v, true
}

// ClearShopID clears the value of the "shop_id" field.
func (m *PlayersMutation) ClearShopID() {
	m.shop_id = nil
	m.addshop_id = nil
	m.clearedFields[players.FieldShopID] = struct{}{}
}

// ShopIDCleared returns if the "shop_id" field was cleared in this mutation.
func (m *PlayersMutation) ShopIDCleared() bool {
	_, ok := m.clearedFields[players.FieldShopID]
	return ok
}

// ResetShopID resets all changes to the "shop_id" field.
func (m *PlayersMutation) ResetShopID() {
	m.shop_id = nil
	m.addshop_id = nil
	delete(m.clearedFields, players.FieldShopID)
}

// SetTags sets the "tags" field.
func (m *PlayersMutation) SetTags(s []string) {
	m.tags = &s
	m.appendtags = nil
}

// Tags returns the value of the "tags" field in the mutation.
func (m *PlayersMutation) Tags() (r []string, exists bool) {
	v := m.tags
	if v == nil {
		return
	}
	return *v, true
}

// OldTags returns the old "tags" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldTags(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTags is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTags requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTags: %w", err)
	}
	return oldValue.Tags, nil
}

// AppendTags adds s to the "tags" field.
func (m *PlayersMutation) AppendTags(s []string) {
	m.appendtags = append(m.appendtags, s...)
}

// AppendedTags returns the list of values that were appended to the "tags" field in this mutation.
func (m *PlayersMutation) AppendedTags() ([]string, bool) {
	if len(m.appendtags) == 0 {
		return nil, false
	}
	return m.appendtags, true
}

// ClearTags clears the value of the "tags" field.
func (m *PlayersMutation) ClearTags() {
	m.tags = nil
	m.appendtags = nil
	m.clearedFields[players.FieldTags] = struct{}{}
}

// TagsCleared returns if the "tags" field was cleared in this mutation.
func (m *PlayersMutation) TagsCleared() bool {
	_, ok := m.clearedFields[players.FieldTags]
	return ok
}

// ResetTags resets all changes to the "tags" field.
func (m *PlayersMutation) ResetTags() {
	m.tags = nil
	m.appendtags = nil
	delete(m.clearedFields, players.FieldTags)
}

// SetGames sets the "games" field.
func (m *PlayersMutation) SetGames(pq pq.Int64Array) {
	m.games = &pq
}

// Games returns the value of the "games" field in the mutation.
func (m *PlayersMutation) Games() (r pq.Int64Array, exists bool) {
	v := m.games
	if v == nil {
		return
	}
	return *v, true
}

// OldGames returns the old "games" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldGames(ctx context.Context) (v pq.Int64Array, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGames is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGames requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGames: %w", err)
	}
	return oldValue.Games, nil
}

// ClearGames clears the value of the "games" field.
func (m *PlayersMutation) ClearGames() {
	m.games = nil
	m.clearedFields[players.FieldGames] = struct{}{}
}

// GamesCleared returns if the "games" field was cleared in this mutation.
func (m *PlayersMutation) GamesCleared() bool {
	_, ok := m.clearedFields[players.FieldGames]
	return ok
}

// ResetGames resets all changes to the "games" field.
func (m *PlayersMutation) ResetGames() {
	m.games = nil
	delete(m.clearedFields, players.FieldGames)
}

// SetCreatedAt sets the "created_at" field.
func (m *PlayersMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PlayersMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedAt returns the old "created_at" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
	}
	return oldValue.CreatedAt, nil
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PlayersMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PlayersMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PlayersMutation) UpdatedAt() (r time.Time, exists bool) {
	v := m.updated_at
	if v == nil {
		return
	}
	return *v, true
}

// OldUpdatedAt returns the old "updated_at" field's value of the Players entity.
// If the Players object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayersMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
	}
	return oldValue.UpdatedAt, nil
}

// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PlayersMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// Where appends a list predicates to the PlayersMutation builder.
func (m *PlayersMutation) Where(ps ...predicate.Players) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PlayersMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PlayersMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Players, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PlayersMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PlayersMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Players).
func (m *PlayersMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PlayersMutation) Fields() []string {
	fields := make([]string, 0, 11)
	if m.user_id != nil {
		fields = append(fields, players.FieldUserID)
	}
	if m.status != nil {
		fields = append(fields, players.FieldStatus)
	}
	if m.gender != nil {
		fields = append(fields, players.FieldGender)
	}
	if m.rating != nil {
		fields = append(fields, players.FieldRating)
	}
	if m.total_orders != nil {
		fields = append(fields, players.FieldTotalOrders)
	}
	if m.completed_orders != nil {
		fields = append(fields, players.FieldCompletedOrders)
	}
	if m.shop_id != nil {
		fields = append(fields, players.FieldShopID)
	}
	if m.tags != nil {
		fields = append(fields, players.FieldTags)
	}
	if m.games != nil {
		fields = append(fields, players.FieldGames)
	}
	if m.created_at != nil {
		fields = append(fields, players.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, players.FieldUpdatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PlayersMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case players.FieldUserID:
		return m.UserID()
	case players.FieldStatus:
		return m.Status()
	case players.FieldGender:
		return m.Gender()
	case players.FieldRating:
		return m.Rating()
	case players.FieldTotalOrders:
		return m.TotalOrders()
	case players.FieldCompletedOrders:
		return m.CompletedOrders()
	case players.FieldShopID:
		return m.ShopID()
	case players.FieldTags:
		return m.Tags()
	case players.FieldGames:
		return m.Games()
	case players.FieldCreatedAt:
		return m.CreatedAt()
	case players.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PlayersMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case players.FieldUserID:
		return m.OldUserID(ctx)
	case players.FieldStatus:
		return m.OldStatus(ctx)
	case players.FieldGender:
		return m.OldGender(ctx)
	case players.FieldRating:
		return m.OldRating(ctx)
	case players.FieldTotalOrders:
		return m.OldTotalOrders(ctx)
	case players.FieldCompletedOrders:
		return m.OldCompletedOrders(ctx)
	case players.FieldShopID:
		return m.OldShopID(ctx)
	case players.FieldTags:
		return m.OldTags(ctx)
	case players.FieldGames:
		return m.OldGames(ctx)
	case players.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case players.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Players field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlayersMutation) SetField(name string, value ent.Value) error {
	switch name {
	case players.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case players.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case players.FieldGender:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGender(v)
		return nil
	case players.FieldRating:
		v, ok := value.(decimal.Decimal)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRating(v)
		return nil
	case players.FieldTotalOrders:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotalOrders(v)
		return nil
	case players.FieldCompletedOrders:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompletedOrders(v)
		return nil
	case players.FieldShopID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetShopID(v)
		return nil
	case players.FieldTags:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTags(v)
		return nil
	case players.FieldGames:
		v, ok := value.(pq.Int64Array)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGames(v)
		return nil
	case players.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	case players.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Players field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PlayersMutation) AddedFields() []string {
	var fields []string
	if m.adduser_id != nil {
		fields = append(fields, players.FieldUserID)
	}
	if m.addtotal_orders != nil {
		fields = append(fields, players.FieldTotalOrders)
	}
	if m.addcompleted_orders != nil {
		fields = append(fields, players.FieldCompletedOrders)
	}
	if m.addshop_id != nil {
		fields = append(fields, players.FieldShopID)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PlayersMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case players.FieldUserID:
		return m.AddedUserID()
	case players.FieldTotalOrders:
		return m.AddedTotalOrders()
	case players.FieldCompletedOrders:
		return m.AddedCompletedOrders()
	case players.FieldShopID:
		return m.AddedShopID()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlayersMutation) AddField(name string, value ent.Value) error {
	switch name {
	case players.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUserID(v)
		return nil
	case players.FieldTotalOrders:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTotalOrders(v)
		return nil
	case players.FieldCompletedOrders:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCompletedOrders(v)
		return nil
	case players.FieldShopID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddShopID(v)
		return nil
	}
	return fmt.Errorf("unknown Players numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PlayersMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(players.FieldRating) {
		fields = append(fields, players.FieldRating)
	}
	if m.FieldCleared(players.FieldTotalOrders) {
		fields = append(fields, players.FieldTotalOrders)
	}
	if m.FieldCleared(players.FieldCompletedOrders) {
		fields = append(fields, players.FieldCompletedOrders)
	}
	if m.FieldCleared(players.FieldShopID) {
		fields = append(fields, players.FieldShopID)
	}
	if m.FieldCleared(players.FieldTags) {
		fields = append(fields, players.FieldTags)
	}
	if m.FieldCleared(players.FieldGames) {
		fields = append(fields, players.FieldGames)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PlayersMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PlayersMutation) ClearField(name string) error {
	switch name {
	case players.FieldRating:
		m.ClearRating()
		return nil
	case players.FieldTotalOrders:
		m.ClearTotalOrders()
		return nil
	case players.FieldCompletedOrders:
		m.ClearCompletedOrders()
		return nil
	case players.FieldShopID:
		m.ClearShopID()
		return nil
	case players.FieldTags:
		m.ClearTags()
		return nil
	case players.FieldGames:
		m.ClearGames()
		return nil
	}
	return fmt.Errorf("unknown Players nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PlayersMutation) ResetField(name string) error {
	switch name {
	case players.FieldUserID:
		m.ResetUserID()
		return nil
	case players.FieldStatus:
		m.ResetStatus()
		return nil
	case players.FieldGender:
		m.ResetGender()
		return nil
	case players.FieldRating:
		m.ResetRating()
		return nil
	case players.FieldTotalOrders:
		m.ResetTotalOrders()
		return nil
	case players.FieldCompletedOrders:
		m.ResetCompletedOrders()
		return nil
	case players.FieldShopID:
		m.ResetShopID()
		return nil
	case players.FieldTags:
		m.ResetTags()
		return nil
	case players.FieldGames:
		m.ResetGames()
		return nil
	case players.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case players.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Players field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PlayersMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PlayersMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PlayersMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PlayersMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PlayersMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PlayersMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PlayersMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Players unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *PlayersMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Players edge %s", name)
}
