// Code generated by ent, DO NOT EDIT.

package models

import (
	"context"
	"errors"
	"fmt"
	"juwan-backend/app/player/rpc/internal/models/playerservices"
	"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/shopspring/decimal"
)

// PlayerServicesUpdate is the builder for updating PlayerServices entities.
type PlayerServicesUpdate struct {
	config
	hooks    []Hook
	mutation *PlayerServicesMutation
}

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

// SetPlayerID sets the "player_id" field.
func (_u *PlayerServicesUpdate) SetPlayerID(v int64) *PlayerServicesUpdate {
	_u.mutation.ResetPlayerID()
	_u.mutation.SetPlayerID(v)
	return _u
}

// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillablePlayerID(v *int64) *PlayerServicesUpdate {
	if v != nil {
		_u.SetPlayerID(*v)
	}
	return _u
}

// AddPlayerID adds value to the "player_id" field.
func (_u *PlayerServicesUpdate) AddPlayerID(v int64) *PlayerServicesUpdate {
	_u.mutation.AddPlayerID(v)
	return _u
}

// SetGameID sets the "game_id" field.
func (_u *PlayerServicesUpdate) SetGameID(v int64) *PlayerServicesUpdate {
	_u.mutation.ResetGameID()
	_u.mutation.SetGameID(v)
	return _u
}

// SetNillableGameID sets the "game_id" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableGameID(v *int64) *PlayerServicesUpdate {
	if v != nil {
		_u.SetGameID(*v)
	}
	return _u
}

// AddGameID adds value to the "game_id" field.
func (_u *PlayerServicesUpdate) AddGameID(v int64) *PlayerServicesUpdate {
	_u.mutation.AddGameID(v)
	return _u
}

// SetTitle sets the "title" field.
func (_u *PlayerServicesUpdate) SetTitle(v string) *PlayerServicesUpdate {
	_u.mutation.SetTitle(v)
	return _u
}

// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableTitle(v *string) *PlayerServicesUpdate {
	if v != nil {
		_u.SetTitle(*v)
	}
	return _u
}

// SetDescription sets the "description" field.
func (_u *PlayerServicesUpdate) SetDescription(v string) *PlayerServicesUpdate {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableDescription(v *string) *PlayerServicesUpdate {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *PlayerServicesUpdate) ClearDescription() *PlayerServicesUpdate {
	_u.mutation.ClearDescription()
	return _u
}

// SetPrice sets the "price" field.
func (_u *PlayerServicesUpdate) SetPrice(v decimal.Decimal) *PlayerServicesUpdate {
	_u.mutation.SetPrice(v)
	return _u
}

// SetNillablePrice sets the "price" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillablePrice(v *decimal.Decimal) *PlayerServicesUpdate {
	if v != nil {
		_u.SetPrice(*v)
	}
	return _u
}

// SetUnit sets the "unit" field.
func (_u *PlayerServicesUpdate) SetUnit(v string) *PlayerServicesUpdate {
	_u.mutation.SetUnit(v)
	return _u
}

// SetNillableUnit sets the "unit" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableUnit(v *string) *PlayerServicesUpdate {
	if v != nil {
		_u.SetUnit(*v)
	}
	return _u
}

// SetRankRange sets the "rank_range" field.
func (_u *PlayerServicesUpdate) SetRankRange(v string) *PlayerServicesUpdate {
	_u.mutation.SetRankRange(v)
	return _u
}

// SetNillableRankRange sets the "rank_range" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableRankRange(v *string) *PlayerServicesUpdate {
	if v != nil {
		_u.SetRankRange(*v)
	}
	return _u
}

// ClearRankRange clears the value of the "rank_range" field.
func (_u *PlayerServicesUpdate) ClearRankRange() *PlayerServicesUpdate {
	_u.mutation.ClearRankRange()
	return _u
}

// SetAvailability sets the "availability" field.
func (_u *PlayerServicesUpdate) SetAvailability(v []string) *PlayerServicesUpdate {
	_u.mutation.SetAvailability(v)
	return _u
}

// AppendAvailability appends value to the "availability" field.
func (_u *PlayerServicesUpdate) AppendAvailability(v []string) *PlayerServicesUpdate {
	_u.mutation.AppendAvailability(v)
	return _u
}

// ClearAvailability clears the value of the "availability" field.
func (_u *PlayerServicesUpdate) ClearAvailability() *PlayerServicesUpdate {
	_u.mutation.ClearAvailability()
	return _u
}

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

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

// SetIsActive sets the "is_active" field.
func (_u *PlayerServicesUpdate) SetIsActive(v bool) *PlayerServicesUpdate {
	_u.mutation.SetIsActive(v)
	return _u
}

// SetNillableIsActive sets the "is_active" field if the given value is not nil.
func (_u *PlayerServicesUpdate) SetNillableIsActive(v *bool) *PlayerServicesUpdate {
	if v != nil {
		_u.SetIsActive(*v)
	}
	return _u
}

// ClearIsActive clears the value of the "is_active" field.
func (_u *PlayerServicesUpdate) ClearIsActive() *PlayerServicesUpdate {
	_u.mutation.ClearIsActive()
	return _u
}

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

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

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *PlayerServicesUpdate) 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 *PlayerServicesUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *PlayerServicesUpdate) 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 *PlayerServicesUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := playerservices.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PlayerServicesUpdate) check() error {
	if v, ok := _u.mutation.Title(); ok {
		if err := playerservices.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "PlayerServices.title": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Unit(); ok {
		if err := playerservices.UnitValidator(v); err != nil {
			return &ValidationError{Name: "unit", err: fmt.Errorf(`models: validator failed for field "PlayerServices.unit": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RankRange(); ok {
		if err := playerservices.RankRangeValidator(v); err != nil {
			return &ValidationError{Name: "rank_range", err: fmt.Errorf(`models: validator failed for field "PlayerServices.rank_range": %w`, err)}
		}
	}
	return nil
}

func (_u *PlayerServicesUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(playerservices.Table, playerservices.Columns, sqlgraph.NewFieldSpec(playerservices.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.PlayerID(); ok {
		_spec.SetField(playerservices.FieldPlayerID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedPlayerID(); ok {
		_spec.AddField(playerservices.FieldPlayerID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.GameID(); ok {
		_spec.SetField(playerservices.FieldGameID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedGameID(); ok {
		_spec.AddField(playerservices.FieldGameID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.Title(); ok {
		_spec.SetField(playerservices.FieldTitle, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(playerservices.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(playerservices.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.Price(); ok {
		_spec.SetField(playerservices.FieldPrice, field.TypeOther, value)
	}
	if value, ok := _u.mutation.Unit(); ok {
		_spec.SetField(playerservices.FieldUnit, field.TypeString, value)
	}
	if value, ok := _u.mutation.RankRange(); ok {
		_spec.SetField(playerservices.FieldRankRange, field.TypeString, value)
	}
	if _u.mutation.RankRangeCleared() {
		_spec.ClearField(playerservices.FieldRankRange, field.TypeString)
	}
	if value, ok := _u.mutation.Availability(); ok {
		availability := types.TextArray{Elements: append([]string{}, value...), Valid: true}
		_spec.SetField(playerservices.FieldAvailability, field.TypeOther, availability)
	}
	if value, ok := _u.mutation.AppendedAvailability(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, playerservices.FieldAvailability, value)
		})
	}
	if _u.mutation.AvailabilityCleared() {
		_spec.ClearField(playerservices.FieldAvailability, field.TypeOther)
	}
	if value, ok := _u.mutation.Rating(); ok {
		_spec.SetField(playerservices.FieldRating, field.TypeOther, value)
	}
	if value, ok := _u.mutation.IsActive(); ok {
		_spec.SetField(playerservices.FieldIsActive, field.TypeBool, value)
	}
	if _u.mutation.IsActiveCleared() {
		_spec.ClearField(playerservices.FieldIsActive, field.TypeBool)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(playerservices.FieldUpdatedAt, field.TypeTime, value)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{playerservices.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// PlayerServicesUpdateOne is the builder for updating a single PlayerServices entity.
type PlayerServicesUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PlayerServicesMutation
}

// SetPlayerID sets the "player_id" field.
func (_u *PlayerServicesUpdateOne) SetPlayerID(v int64) *PlayerServicesUpdateOne {
	_u.mutation.ResetPlayerID()
	_u.mutation.SetPlayerID(v)
	return _u
}

// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillablePlayerID(v *int64) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetPlayerID(*v)
	}
	return _u
}

// AddPlayerID adds value to the "player_id" field.
func (_u *PlayerServicesUpdateOne) AddPlayerID(v int64) *PlayerServicesUpdateOne {
	_u.mutation.AddPlayerID(v)
	return _u
}

// SetGameID sets the "game_id" field.
func (_u *PlayerServicesUpdateOne) SetGameID(v int64) *PlayerServicesUpdateOne {
	_u.mutation.ResetGameID()
	_u.mutation.SetGameID(v)
	return _u
}

// SetNillableGameID sets the "game_id" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableGameID(v *int64) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetGameID(*v)
	}
	return _u
}

// AddGameID adds value to the "game_id" field.
func (_u *PlayerServicesUpdateOne) AddGameID(v int64) *PlayerServicesUpdateOne {
	_u.mutation.AddGameID(v)
	return _u
}

// SetTitle sets the "title" field.
func (_u *PlayerServicesUpdateOne) SetTitle(v string) *PlayerServicesUpdateOne {
	_u.mutation.SetTitle(v)
	return _u
}

// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableTitle(v *string) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetTitle(*v)
	}
	return _u
}

// SetDescription sets the "description" field.
func (_u *PlayerServicesUpdateOne) SetDescription(v string) *PlayerServicesUpdateOne {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableDescription(v *string) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *PlayerServicesUpdateOne) ClearDescription() *PlayerServicesUpdateOne {
	_u.mutation.ClearDescription()
	return _u
}

// SetPrice sets the "price" field.
func (_u *PlayerServicesUpdateOne) SetPrice(v decimal.Decimal) *PlayerServicesUpdateOne {
	_u.mutation.SetPrice(v)
	return _u
}

// SetNillablePrice sets the "price" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillablePrice(v *decimal.Decimal) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetPrice(*v)
	}
	return _u
}

// SetUnit sets the "unit" field.
func (_u *PlayerServicesUpdateOne) SetUnit(v string) *PlayerServicesUpdateOne {
	_u.mutation.SetUnit(v)
	return _u
}

// SetNillableUnit sets the "unit" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableUnit(v *string) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetUnit(*v)
	}
	return _u
}

// SetRankRange sets the "rank_range" field.
func (_u *PlayerServicesUpdateOne) SetRankRange(v string) *PlayerServicesUpdateOne {
	_u.mutation.SetRankRange(v)
	return _u
}

// SetNillableRankRange sets the "rank_range" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableRankRange(v *string) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetRankRange(*v)
	}
	return _u
}

// ClearRankRange clears the value of the "rank_range" field.
func (_u *PlayerServicesUpdateOne) ClearRankRange() *PlayerServicesUpdateOne {
	_u.mutation.ClearRankRange()
	return _u
}

// SetAvailability sets the "availability" field.
func (_u *PlayerServicesUpdateOne) SetAvailability(v []string) *PlayerServicesUpdateOne {
	_u.mutation.SetAvailability(v)
	return _u
}

// AppendAvailability appends value to the "availability" field.
func (_u *PlayerServicesUpdateOne) AppendAvailability(v []string) *PlayerServicesUpdateOne {
	_u.mutation.AppendAvailability(v)
	return _u
}

// ClearAvailability clears the value of the "availability" field.
func (_u *PlayerServicesUpdateOne) ClearAvailability() *PlayerServicesUpdateOne {
	_u.mutation.ClearAvailability()
	return _u
}

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

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

// SetIsActive sets the "is_active" field.
func (_u *PlayerServicesUpdateOne) SetIsActive(v bool) *PlayerServicesUpdateOne {
	_u.mutation.SetIsActive(v)
	return _u
}

// SetNillableIsActive sets the "is_active" field if the given value is not nil.
func (_u *PlayerServicesUpdateOne) SetNillableIsActive(v *bool) *PlayerServicesUpdateOne {
	if v != nil {
		_u.SetIsActive(*v)
	}
	return _u
}

// ClearIsActive clears the value of the "is_active" field.
func (_u *PlayerServicesUpdateOne) ClearIsActive() *PlayerServicesUpdateOne {
	_u.mutation.ClearIsActive()
	return _u
}

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

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

// Where appends a list predicates to the PlayerServicesUpdate builder.
func (_u *PlayerServicesUpdateOne) Where(ps ...predicate.PlayerServices) *PlayerServicesUpdateOne {
	_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 *PlayerServicesUpdateOne) Select(field string, fields ...string) *PlayerServicesUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

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

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *PlayerServicesUpdateOne) 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 *PlayerServicesUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := playerservices.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PlayerServicesUpdateOne) check() error {
	if v, ok := _u.mutation.Title(); ok {
		if err := playerservices.TitleValidator(v); err != nil {
			return &ValidationError{Name: "title", err: fmt.Errorf(`models: validator failed for field "PlayerServices.title": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Unit(); ok {
		if err := playerservices.UnitValidator(v); err != nil {
			return &ValidationError{Name: "unit", err: fmt.Errorf(`models: validator failed for field "PlayerServices.unit": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RankRange(); ok {
		if err := playerservices.RankRangeValidator(v); err != nil {
			return &ValidationError{Name: "rank_range", err: fmt.Errorf(`models: validator failed for field "PlayerServices.rank_range": %w`, err)}
		}
	}
	return nil
}

func (_u *PlayerServicesUpdateOne) sqlSave(ctx context.Context) (_node *PlayerServices, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(playerservices.Table, playerservices.Columns, sqlgraph.NewFieldSpec(playerservices.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "PlayerServices.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, playerservices.FieldID)
		for _, f := range fields {
			if !playerservices.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
			}
			if f != playerservices.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.PlayerID(); ok {
		_spec.SetField(playerservices.FieldPlayerID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedPlayerID(); ok {
		_spec.AddField(playerservices.FieldPlayerID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.GameID(); ok {
		_spec.SetField(playerservices.FieldGameID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedGameID(); ok {
		_spec.AddField(playerservices.FieldGameID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.Title(); ok {
		_spec.SetField(playerservices.FieldTitle, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(playerservices.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(playerservices.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.Price(); ok {
		_spec.SetField(playerservices.FieldPrice, field.TypeOther, value)
	}
	if value, ok := _u.mutation.Unit(); ok {
		_spec.SetField(playerservices.FieldUnit, field.TypeString, value)
	}
	if value, ok := _u.mutation.RankRange(); ok {
		_spec.SetField(playerservices.FieldRankRange, field.TypeString, value)
	}
	if _u.mutation.RankRangeCleared() {
		_spec.ClearField(playerservices.FieldRankRange, field.TypeString)
	}
	if value, ok := _u.mutation.Availability(); ok {
		availability := types.TextArray{Elements: append([]string{}, value...), Valid: true}
		_spec.SetField(playerservices.FieldAvailability, field.TypeOther, availability)
	}
	if value, ok := _u.mutation.AppendedAvailability(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, playerservices.FieldAvailability, value)
		})
	}
	if _u.mutation.AvailabilityCleared() {
		_spec.ClearField(playerservices.FieldAvailability, field.TypeOther)
	}
	if value, ok := _u.mutation.Rating(); ok {
		_spec.SetField(playerservices.FieldRating, field.TypeOther, value)
	}
	if value, ok := _u.mutation.IsActive(); ok {
		_spec.SetField(playerservices.FieldIsActive, field.TypeBool, value)
	}
	if _u.mutation.IsActiveCleared() {
		_spec.ClearField(playerservices.FieldIsActive, field.TypeBool)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(playerservices.FieldUpdatedAt, field.TypeTime, value)
	}
	_node = &PlayerServices{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{playerservices.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
