// 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/predicate"
	"juwan-backend/pkg/types"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/dialect/sql/sqljson"
	"entgo.io/ent/schema/field"
	"github.com/lib/pq"
	"github.com/shopspring/decimal"
)

// PlayersUpdate is the builder for updating Players entities.
type PlayersUpdate struct {
	config
	hooks    []Hook
	mutation *PlayersMutation
}

// Where appends a list predicates to the PlayersUpdate builder.
func (_u *PlayersUpdate) Where(ps ...predicate.Players) *PlayersUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetUserID sets the "user_id" field.
func (_u *PlayersUpdate) SetUserID(v int64) *PlayersUpdate {
	_u.mutation.ResetUserID()
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableUserID(v *int64) *PlayersUpdate {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// AddUserID adds value to the "user_id" field.
func (_u *PlayersUpdate) AddUserID(v int64) *PlayersUpdate {
	_u.mutation.AddUserID(v)
	return _u
}

// SetStatus sets the "status" field.
func (_u *PlayersUpdate) SetStatus(v string) *PlayersUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableStatus(v *string) *PlayersUpdate {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetGender sets the "gender" field.
func (_u *PlayersUpdate) SetGender(v bool) *PlayersUpdate {
	_u.mutation.SetGender(v)
	return _u
}

// SetNillableGender sets the "gender" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableGender(v *bool) *PlayersUpdate {
	if v != nil {
		_u.SetGender(*v)
	}
	return _u
}

// SetRating sets the "rating" field.
func (_u *PlayersUpdate) SetRating(v decimal.Decimal) *PlayersUpdate {
	_u.mutation.SetRating(v)
	return _u
}

// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableRating(v *decimal.Decimal) *PlayersUpdate {
	if v != nil {
		_u.SetRating(*v)
	}
	return _u
}

// ClearRating clears the value of the "rating" field.
func (_u *PlayersUpdate) ClearRating() *PlayersUpdate {
	_u.mutation.ClearRating()
	return _u
}

// SetTotalOrders sets the "total_orders" field.
func (_u *PlayersUpdate) SetTotalOrders(v int) *PlayersUpdate {
	_u.mutation.ResetTotalOrders()
	_u.mutation.SetTotalOrders(v)
	return _u
}

// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableTotalOrders(v *int) *PlayersUpdate {
	if v != nil {
		_u.SetTotalOrders(*v)
	}
	return _u
}

// AddTotalOrders adds value to the "total_orders" field.
func (_u *PlayersUpdate) AddTotalOrders(v int) *PlayersUpdate {
	_u.mutation.AddTotalOrders(v)
	return _u
}

// ClearTotalOrders clears the value of the "total_orders" field.
func (_u *PlayersUpdate) ClearTotalOrders() *PlayersUpdate {
	_u.mutation.ClearTotalOrders()
	return _u
}

// SetCompletedOrders sets the "completed_orders" field.
func (_u *PlayersUpdate) SetCompletedOrders(v int) *PlayersUpdate {
	_u.mutation.ResetCompletedOrders()
	_u.mutation.SetCompletedOrders(v)
	return _u
}

// SetNillableCompletedOrders sets the "completed_orders" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableCompletedOrders(v *int) *PlayersUpdate {
	if v != nil {
		_u.SetCompletedOrders(*v)
	}
	return _u
}

// AddCompletedOrders adds value to the "completed_orders" field.
func (_u *PlayersUpdate) AddCompletedOrders(v int) *PlayersUpdate {
	_u.mutation.AddCompletedOrders(v)
	return _u
}

// ClearCompletedOrders clears the value of the "completed_orders" field.
func (_u *PlayersUpdate) ClearCompletedOrders() *PlayersUpdate {
	_u.mutation.ClearCompletedOrders()
	return _u
}

// SetShopID sets the "shop_id" field.
func (_u *PlayersUpdate) SetShopID(v int64) *PlayersUpdate {
	_u.mutation.ResetShopID()
	_u.mutation.SetShopID(v)
	return _u
}

// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *PlayersUpdate) SetNillableShopID(v *int64) *PlayersUpdate {
	if v != nil {
		_u.SetShopID(*v)
	}
	return _u
}

// AddShopID adds value to the "shop_id" field.
func (_u *PlayersUpdate) AddShopID(v int64) *PlayersUpdate {
	_u.mutation.AddShopID(v)
	return _u
}

// ClearShopID clears the value of the "shop_id" field.
func (_u *PlayersUpdate) ClearShopID() *PlayersUpdate {
	_u.mutation.ClearShopID()
	return _u
}

// SetTags sets the "tags" field.
func (_u *PlayersUpdate) SetTags(v []string) *PlayersUpdate {
	_u.mutation.SetTags(v)
	return _u
}

// AppendTags appends value to the "tags" field.
func (_u *PlayersUpdate) AppendTags(v []string) *PlayersUpdate {
	_u.mutation.AppendTags(v)
	return _u
}

// ClearTags clears the value of the "tags" field.
func (_u *PlayersUpdate) ClearTags() *PlayersUpdate {
	_u.mutation.ClearTags()
	return _u
}

// SetGames sets the "games" field.
func (_u *PlayersUpdate) SetGames(v pq.Int64Array) *PlayersUpdate {
	_u.mutation.SetGames(v)
	return _u
}

// ClearGames clears the value of the "games" field.
func (_u *PlayersUpdate) ClearGames() *PlayersUpdate {
	_u.mutation.ClearGames()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *PlayersUpdate) SetUpdatedAt(v time.Time) *PlayersUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// Mutation returns the PlayersMutation object of the builder.
func (_u *PlayersUpdate) Mutation() *PlayersMutation {
	return _u.mutation
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *PlayersUpdate) Save(ctx context.Context) (int, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *PlayersUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (_u *PlayersUpdate) Exec(ctx context.Context) error {
	_, err := _u.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_u *PlayersUpdate) ExecX(ctx context.Context) {
	if err := _u.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (_u *PlayersUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := players.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PlayersUpdate) check() error {
	if v, ok := _u.mutation.Status(); ok {
		if err := players.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Players.status": %w`, err)}
		}
	}
	return nil
}

func (_u *PlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(players.Table, players.Columns, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UserID(); ok {
		_spec.SetField(players.FieldUserID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedUserID(); ok {
		_spec.AddField(players.FieldUserID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(players.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Gender(); ok {
		_spec.SetField(players.FieldGender, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Rating(); ok {
		_spec.SetField(players.FieldRating, field.TypeOther, value)
	}
	if _u.mutation.RatingCleared() {
		_spec.ClearField(players.FieldRating, field.TypeOther)
	}
	if value, ok := _u.mutation.TotalOrders(); ok {
		_spec.SetField(players.FieldTotalOrders, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedTotalOrders(); ok {
		_spec.AddField(players.FieldTotalOrders, field.TypeInt, value)
	}
	if _u.mutation.TotalOrdersCleared() {
		_spec.ClearField(players.FieldTotalOrders, field.TypeInt)
	}
	if value, ok := _u.mutation.CompletedOrders(); ok {
		_spec.SetField(players.FieldCompletedOrders, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCompletedOrders(); ok {
		_spec.AddField(players.FieldCompletedOrders, field.TypeInt, value)
	}
	if _u.mutation.CompletedOrdersCleared() {
		_spec.ClearField(players.FieldCompletedOrders, field.TypeInt)
	}
	if value, ok := _u.mutation.ShopID(); ok {
		_spec.SetField(players.FieldShopID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedShopID(); ok {
		_spec.AddField(players.FieldShopID, field.TypeInt64, value)
	}
	if _u.mutation.ShopIDCleared() {
		_spec.ClearField(players.FieldShopID, field.TypeInt64)
	}
	if value, ok := _u.mutation.Tags(); ok {
		tags := types.TextArray{Elements: append([]string{}, value...), Valid: true}
		_spec.SetField(players.FieldTags, field.TypeOther, tags)
	}
	if value, ok := _u.mutation.AppendedTags(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, players.FieldTags, value)
		})
	}
	if _u.mutation.TagsCleared() {
		_spec.ClearField(players.FieldTags, field.TypeOther)
	}
	if value, ok := _u.mutation.Games(); ok {
		_spec.SetField(players.FieldGames, field.TypeOther, value)
	}
	if _u.mutation.GamesCleared() {
		_spec.ClearField(players.FieldGames, field.TypeOther)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(players.FieldUpdatedAt, field.TypeTime, value)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{players.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// PlayersUpdateOne is the builder for updating a single Players entity.
type PlayersUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PlayersMutation
}

// SetUserID sets the "user_id" field.
func (_u *PlayersUpdateOne) SetUserID(v int64) *PlayersUpdateOne {
	_u.mutation.ResetUserID()
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableUserID(v *int64) *PlayersUpdateOne {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// AddUserID adds value to the "user_id" field.
func (_u *PlayersUpdateOne) AddUserID(v int64) *PlayersUpdateOne {
	_u.mutation.AddUserID(v)
	return _u
}

// SetStatus sets the "status" field.
func (_u *PlayersUpdateOne) SetStatus(v string) *PlayersUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableStatus(v *string) *PlayersUpdateOne {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetGender sets the "gender" field.
func (_u *PlayersUpdateOne) SetGender(v bool) *PlayersUpdateOne {
	_u.mutation.SetGender(v)
	return _u
}

// SetNillableGender sets the "gender" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableGender(v *bool) *PlayersUpdateOne {
	if v != nil {
		_u.SetGender(*v)
	}
	return _u
}

// SetRating sets the "rating" field.
func (_u *PlayersUpdateOne) SetRating(v decimal.Decimal) *PlayersUpdateOne {
	_u.mutation.SetRating(v)
	return _u
}

// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableRating(v *decimal.Decimal) *PlayersUpdateOne {
	if v != nil {
		_u.SetRating(*v)
	}
	return _u
}

// ClearRating clears the value of the "rating" field.
func (_u *PlayersUpdateOne) ClearRating() *PlayersUpdateOne {
	_u.mutation.ClearRating()
	return _u
}

// SetTotalOrders sets the "total_orders" field.
func (_u *PlayersUpdateOne) SetTotalOrders(v int) *PlayersUpdateOne {
	_u.mutation.ResetTotalOrders()
	_u.mutation.SetTotalOrders(v)
	return _u
}

// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableTotalOrders(v *int) *PlayersUpdateOne {
	if v != nil {
		_u.SetTotalOrders(*v)
	}
	return _u
}

// AddTotalOrders adds value to the "total_orders" field.
func (_u *PlayersUpdateOne) AddTotalOrders(v int) *PlayersUpdateOne {
	_u.mutation.AddTotalOrders(v)
	return _u
}

// ClearTotalOrders clears the value of the "total_orders" field.
func (_u *PlayersUpdateOne) ClearTotalOrders() *PlayersUpdateOne {
	_u.mutation.ClearTotalOrders()
	return _u
}

// SetCompletedOrders sets the "completed_orders" field.
func (_u *PlayersUpdateOne) SetCompletedOrders(v int) *PlayersUpdateOne {
	_u.mutation.ResetCompletedOrders()
	_u.mutation.SetCompletedOrders(v)
	return _u
}

// SetNillableCompletedOrders sets the "completed_orders" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableCompletedOrders(v *int) *PlayersUpdateOne {
	if v != nil {
		_u.SetCompletedOrders(*v)
	}
	return _u
}

// AddCompletedOrders adds value to the "completed_orders" field.
func (_u *PlayersUpdateOne) AddCompletedOrders(v int) *PlayersUpdateOne {
	_u.mutation.AddCompletedOrders(v)
	return _u
}

// ClearCompletedOrders clears the value of the "completed_orders" field.
func (_u *PlayersUpdateOne) ClearCompletedOrders() *PlayersUpdateOne {
	_u.mutation.ClearCompletedOrders()
	return _u
}

// SetShopID sets the "shop_id" field.
func (_u *PlayersUpdateOne) SetShopID(v int64) *PlayersUpdateOne {
	_u.mutation.ResetShopID()
	_u.mutation.SetShopID(v)
	return _u
}

// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *PlayersUpdateOne) SetNillableShopID(v *int64) *PlayersUpdateOne {
	if v != nil {
		_u.SetShopID(*v)
	}
	return _u
}

// AddShopID adds value to the "shop_id" field.
func (_u *PlayersUpdateOne) AddShopID(v int64) *PlayersUpdateOne {
	_u.mutation.AddShopID(v)
	return _u
}

// ClearShopID clears the value of the "shop_id" field.
func (_u *PlayersUpdateOne) ClearShopID() *PlayersUpdateOne {
	_u.mutation.ClearShopID()
	return _u
}

// SetTags sets the "tags" field.
func (_u *PlayersUpdateOne) SetTags(v []string) *PlayersUpdateOne {
	_u.mutation.SetTags(v)
	return _u
}

// AppendTags appends value to the "tags" field.
func (_u *PlayersUpdateOne) AppendTags(v []string) *PlayersUpdateOne {
	_u.mutation.AppendTags(v)
	return _u
}

// ClearTags clears the value of the "tags" field.
func (_u *PlayersUpdateOne) ClearTags() *PlayersUpdateOne {
	_u.mutation.ClearTags()
	return _u
}

// SetGames sets the "games" field.
func (_u *PlayersUpdateOne) SetGames(v pq.Int64Array) *PlayersUpdateOne {
	_u.mutation.SetGames(v)
	return _u
}

// ClearGames clears the value of the "games" field.
func (_u *PlayersUpdateOne) ClearGames() *PlayersUpdateOne {
	_u.mutation.ClearGames()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *PlayersUpdateOne) SetUpdatedAt(v time.Time) *PlayersUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// Mutation returns the PlayersMutation object of the builder.
func (_u *PlayersUpdateOne) Mutation() *PlayersMutation {
	return _u.mutation
}

// Where appends a list predicates to the PlayersUpdate builder.
func (_u *PlayersUpdateOne) Where(ps ...predicate.Players) *PlayersUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *PlayersUpdateOne) Select(field string, fields ...string) *PlayersUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated Players entity.
func (_u *PlayersUpdateOne) Save(ctx context.Context) (*Players, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *PlayersUpdateOne) SaveX(ctx context.Context) *Players {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (_u *PlayersUpdateOne) Exec(ctx context.Context) error {
	_, err := _u.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_u *PlayersUpdateOne) ExecX(ctx context.Context) {
	if err := _u.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (_u *PlayersUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := players.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PlayersUpdateOne) check() error {
	if v, ok := _u.mutation.Status(); ok {
		if err := players.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "Players.status": %w`, err)}
		}
	}
	return nil
}

func (_u *PlayersUpdateOne) sqlSave(ctx context.Context) (_node *Players, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(players.Table, players.Columns, sqlgraph.NewFieldSpec(players.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Players.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, players.FieldID)
		for _, f := range fields {
			if !players.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
			}
			if f != players.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UserID(); ok {
		_spec.SetField(players.FieldUserID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedUserID(); ok {
		_spec.AddField(players.FieldUserID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(players.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Gender(); ok {
		_spec.SetField(players.FieldGender, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Rating(); ok {
		_spec.SetField(players.FieldRating, field.TypeOther, value)
	}
	if _u.mutation.RatingCleared() {
		_spec.ClearField(players.FieldRating, field.TypeOther)
	}
	if value, ok := _u.mutation.TotalOrders(); ok {
		_spec.SetField(players.FieldTotalOrders, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedTotalOrders(); ok {
		_spec.AddField(players.FieldTotalOrders, field.TypeInt, value)
	}
	if _u.mutation.TotalOrdersCleared() {
		_spec.ClearField(players.FieldTotalOrders, field.TypeInt)
	}
	if value, ok := _u.mutation.CompletedOrders(); ok {
		_spec.SetField(players.FieldCompletedOrders, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCompletedOrders(); ok {
		_spec.AddField(players.FieldCompletedOrders, field.TypeInt, value)
	}
	if _u.mutation.CompletedOrdersCleared() {
		_spec.ClearField(players.FieldCompletedOrders, field.TypeInt)
	}
	if value, ok := _u.mutation.ShopID(); ok {
		_spec.SetField(players.FieldShopID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedShopID(); ok {
		_spec.AddField(players.FieldShopID, field.TypeInt64, value)
	}
	if _u.mutation.ShopIDCleared() {
		_spec.ClearField(players.FieldShopID, field.TypeInt64)
	}
	if value, ok := _u.mutation.Tags(); ok {
		tags := types.TextArray{Elements: append([]string{}, value...), Valid: true}
		_spec.SetField(players.FieldTags, field.TypeOther, tags)
	}
	if value, ok := _u.mutation.AppendedTags(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, players.FieldTags, value)
		})
	}
	if _u.mutation.TagsCleared() {
		_spec.ClearField(players.FieldTags, field.TypeOther)
	}
	if value, ok := _u.mutation.Games(); ok {
		_spec.SetField(players.FieldGames, field.TypeOther, value)
	}
	if _u.mutation.GamesCleared() {
		_spec.ClearField(players.FieldGames, field.TypeOther)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(players.FieldUpdatedAt, field.TypeTime, value)
	}
	_node = &Players{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{players.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
