package ent

import (
	"context"
	"fmt"
	"time"
	"user/internal/data/ent/predicate"
	"user/internal/data/ent/userextend"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

type UserExtendUpdate struct {
	config
	hooks    []Hook
	mutation *UserExtendMutation
}

func (ueu *UserExtendUpdate) Where(ps ...predicate.UserExtend) *UserExtendUpdate {
	ueu.mutation.predicates = append(ueu.mutation.predicates, ps...)
	return ueu
}

func (ueu *UserExtendUpdate) SetPlatUserID(u uint) *UserExtendUpdate {
	ueu.mutation.ResetPlatUserID()
	ueu.mutation.SetPlatUserID(u)
	return ueu
}

func (ueu *UserExtendUpdate) AddPlatUserID(u uint) *UserExtendUpdate {
	ueu.mutation.AddPlatUserID(u)
	return ueu
}

func (ueu *UserExtendUpdate) SetRealName(s string) *UserExtendUpdate {
	ueu.mutation.SetRealName(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableRealName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetRealName(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetIDNumber(s string) *UserExtendUpdate {
	ueu.mutation.SetIDNumber(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableIDNumber(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetIDNumber(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetAge(i int8) *UserExtendUpdate {
	ueu.mutation.ResetAge()
	ueu.mutation.SetAge(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableAge(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetAge(*i)
	}
	return ueu
}

func (ueu *UserExtendUpdate) AddAge(i int8) *UserExtendUpdate {
	ueu.mutation.AddAge(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetSex(i int8) *UserExtendUpdate {
	ueu.mutation.ResetSex()
	ueu.mutation.SetSex(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableSex(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetSex(*i)
	}
	return ueu
}

func (ueu *UserExtendUpdate) AddSex(i int8) *UserExtendUpdate {
	ueu.mutation.AddSex(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetBirth(i int) *UserExtendUpdate {
	ueu.mutation.ResetBirth()
	ueu.mutation.SetBirth(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableBirth(i *int) *UserExtendUpdate {
	if i != nil {
		ueu.SetBirth(*i)
	}
	return ueu
}

func (ueu *UserExtendUpdate) AddBirth(i int) *UserExtendUpdate {
	ueu.mutation.AddBirth(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetIcon(s string) *UserExtendUpdate {
	ueu.mutation.SetIcon(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableIcon(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetIcon(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetNickName(s string) *UserExtendUpdate {
	ueu.mutation.SetNickName(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableNickName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetNickName(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetImei(s string) *UserExtendUpdate {
	ueu.mutation.SetImei(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableImei(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetImei(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetOaid(s string) *UserExtendUpdate {
	ueu.mutation.SetOaid(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableOaid(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetOaid(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetDeviceID(s string) *UserExtendUpdate {
	ueu.mutation.SetDeviceID(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableDeviceID(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetDeviceID(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetSystemName(s string) *UserExtendUpdate {
	ueu.mutation.SetSystemName(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableSystemName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetSystemName(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetSystemVersion(s string) *UserExtendUpdate {
	ueu.mutation.SetSystemVersion(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableSystemVersion(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetSystemVersion(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetAdid(s string) *UserExtendUpdate {
	ueu.mutation.SetAdid(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableAdid(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetAdid(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetGameID(s string) *UserExtendUpdate {
	ueu.mutation.SetGameID(s)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableGameID(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetGameID(*s)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetThirdPlatformID(i int8) *UserExtendUpdate {
	ueu.mutation.ResetThirdPlatformID()
	ueu.mutation.SetThirdPlatformID(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableThirdPlatformID(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetThirdPlatformID(*i)
	}
	return ueu
}

func (ueu *UserExtendUpdate) AddThirdPlatformID(i int8) *UserExtendUpdate {
	ueu.mutation.AddThirdPlatformID(i)
	return ueu
}

func (ueu *UserExtendUpdate) SetCreatedAt(t time.Time) *UserExtendUpdate {
	ueu.mutation.SetCreatedAt(t)
	return ueu
}

func (ueu *UserExtendUpdate) SetNillableCreatedAt(t *time.Time) *UserExtendUpdate {
	if t != nil {
		ueu.SetCreatedAt(*t)
	}
	return ueu
}

func (ueu *UserExtendUpdate) SetUpdatedAt(t time.Time) *UserExtendUpdate {
	ueu.mutation.SetUpdatedAt(t)
	return ueu
}

func (ueu *UserExtendUpdate) Mutation() *UserExtendMutation {
	return ueu.mutation
}

func (ueu *UserExtendUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(ueu.hooks) == 0 {
		affected, err = ueu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*UserExtendMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			ueu.mutation = mutation
			affected, err = ueu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(ueu.hooks) - 1; i >= 0; i-- {
			mut = ueu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, ueu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}

func (ueu *UserExtendUpdate) SaveX(ctx context.Context) int {
	affected, err := ueu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

func (ueu *UserExtendUpdate) Exec(ctx context.Context) error {
	_, err := ueu.Save(ctx)
	return err
}

func (ueu *UserExtendUpdate) ExecX(ctx context.Context) {
	if err := ueu.Exec(ctx); err != nil {
		panic(err)
	}
}

func (ueu *UserExtendUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   userextend.Table,
			Columns: userextend.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: userextend.FieldID,
			},
		},
	}
	if ps := ueu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ueu.mutation.PlatUserID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueu.mutation.AddedPlatUserID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueu.mutation.RealName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldRealName,
		})
	}
	if value, ok := ueu.mutation.IDNumber(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIDNumber,
		})
	}
	if value, ok := ueu.mutation.Age(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueu.mutation.AddedAge(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueu.mutation.Sex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueu.mutation.AddedSex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueu.mutation.Birth(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueu.mutation.AddedBirth(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueu.mutation.Icon(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIcon,
		})
	}
	if value, ok := ueu.mutation.NickName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldNickName,
		})
	}
	if value, ok := ueu.mutation.Imei(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldImei,
		})
	}
	if value, ok := ueu.mutation.Oaid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldOaid,
		})
	}
	if value, ok := ueu.mutation.DeviceID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldDeviceID,
		})
	}
	if value, ok := ueu.mutation.SystemName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemName,
		})
	}
	if value, ok := ueu.mutation.SystemVersion(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemVersion,
		})
	}
	if value, ok := ueu.mutation.Adid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldAdid,
		})
	}
	if value, ok := ueu.mutation.GameID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldGameID,
		})
	}
	if value, ok := ueu.mutation.ThirdPlatformID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueu.mutation.AddedThirdPlatformID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueu.mutation.CreatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldCreatedAt,
		})
	}
	if value, ok := ueu.mutation.UpdatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldUpdatedAt,
		})
	}
	if n, err = sqlgraph.UpdateNodes(ctx, ueu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userextend.Label}
		} else if cerr, ok := isSQLConstraintError(err); ok {
			err = cerr
		}
		return 0, err
	}
	return n, nil
}

type UserExtendUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UserExtendMutation
}

func (ueuo *UserExtendUpdateOne) SetPlatUserID(u uint) *UserExtendUpdateOne {
	ueuo.mutation.ResetPlatUserID()
	ueuo.mutation.SetPlatUserID(u)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) AddPlatUserID(u uint) *UserExtendUpdateOne {
	ueuo.mutation.AddPlatUserID(u)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetRealName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetRealName(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableRealName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetRealName(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetIDNumber(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetIDNumber(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableIDNumber(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetIDNumber(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetAge(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetAge()
	ueuo.mutation.SetAge(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableAge(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetAge(*i)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) AddAge(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddAge(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetSex(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetSex()
	ueuo.mutation.SetSex(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableSex(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetSex(*i)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) AddSex(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddSex(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetBirth(i int) *UserExtendUpdateOne {
	ueuo.mutation.ResetBirth()
	ueuo.mutation.SetBirth(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableBirth(i *int) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetBirth(*i)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) AddBirth(i int) *UserExtendUpdateOne {
	ueuo.mutation.AddBirth(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetIcon(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetIcon(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableIcon(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetIcon(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNickName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetNickName(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableNickName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetNickName(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetImei(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetImei(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableImei(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetImei(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetOaid(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetOaid(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableOaid(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetOaid(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetDeviceID(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetDeviceID(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableDeviceID(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetDeviceID(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetSystemName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetSystemName(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableSystemName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetSystemName(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetSystemVersion(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetSystemVersion(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableSystemVersion(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetSystemVersion(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetAdid(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetAdid(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableAdid(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetAdid(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetGameID(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetGameID(s)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableGameID(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetGameID(*s)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetThirdPlatformID(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetThirdPlatformID()
	ueuo.mutation.SetThirdPlatformID(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableThirdPlatformID(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetThirdPlatformID(*i)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) AddThirdPlatformID(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddThirdPlatformID(i)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetCreatedAt(t time.Time) *UserExtendUpdateOne {
	ueuo.mutation.SetCreatedAt(t)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetNillableCreatedAt(t *time.Time) *UserExtendUpdateOne {
	if t != nil {
		ueuo.SetCreatedAt(*t)
	}
	return ueuo
}

func (ueuo *UserExtendUpdateOne) SetUpdatedAt(t time.Time) *UserExtendUpdateOne {
	ueuo.mutation.SetUpdatedAt(t)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) Mutation() *UserExtendMutation {
	return ueuo.mutation
}

func (ueuo *UserExtendUpdateOne) Select(field string, fields ...string) *UserExtendUpdateOne {
	ueuo.fields = append([]string{field}, fields...)
	return ueuo
}

func (ueuo *UserExtendUpdateOne) Save(ctx context.Context) (*UserExtend, error) {
	var (
		err  error
		node *UserExtend
	)
	if len(ueuo.hooks) == 0 {
		node, err = ueuo.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*UserExtendMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			ueuo.mutation = mutation
			node, err = ueuo.sqlSave(ctx)
			mutation.done = true
			return node, err
		})
		for i := len(ueuo.hooks) - 1; i >= 0; i-- {
			mut = ueuo.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, ueuo.mutation); err != nil {
			return nil, err
		}
	}
	return node, err
}

func (ueuo *UserExtendUpdateOne) SaveX(ctx context.Context) *UserExtend {
	node, err := ueuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

func (ueuo *UserExtendUpdateOne) Exec(ctx context.Context) error {
	_, err := ueuo.Save(ctx)
	return err
}

func (ueuo *UserExtendUpdateOne) ExecX(ctx context.Context) {
	if err := ueuo.Exec(ctx); err != nil {
		panic(err)
	}
}

func (ueuo *UserExtendUpdateOne) sqlSave(ctx context.Context) (_node *UserExtend, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   userextend.Table,
			Columns: userextend.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: userextend.FieldID,
			},
		},
	}
	id, ok := ueuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing UserExtend.ID for update")}
	}
	_spec.Node.ID.Value = id
	if fields := ueuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, userextend.FieldID)
		for _, f := range fields {
			if !userextend.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != userextend.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := ueuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ueuo.mutation.PlatUserID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueuo.mutation.AddedPlatUserID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueuo.mutation.RealName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldRealName,
		})
	}
	if value, ok := ueuo.mutation.IDNumber(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIDNumber,
		})
	}
	if value, ok := ueuo.mutation.Age(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueuo.mutation.AddedAge(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueuo.mutation.Sex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueuo.mutation.AddedSex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueuo.mutation.Birth(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueuo.mutation.AddedBirth(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueuo.mutation.Icon(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIcon,
		})
	}
	if value, ok := ueuo.mutation.NickName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldNickName,
		})
	}
	if value, ok := ueuo.mutation.Imei(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldImei,
		})
	}
	if value, ok := ueuo.mutation.Oaid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldOaid,
		})
	}
	if value, ok := ueuo.mutation.DeviceID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldDeviceID,
		})
	}
	if value, ok := ueuo.mutation.SystemName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemName,
		})
	}
	if value, ok := ueuo.mutation.SystemVersion(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemVersion,
		})
	}
	if value, ok := ueuo.mutation.Adid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldAdid,
		})
	}
	if value, ok := ueuo.mutation.GameID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldGameID,
		})
	}
	if value, ok := ueuo.mutation.ThirdPlatformID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueuo.mutation.AddedThirdPlatformID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueuo.mutation.CreatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldCreatedAt,
		})
	}
	if value, ok := ueuo.mutation.UpdatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldUpdatedAt,
		})
	}
	_node = &UserExtend{config: ueuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, ueuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userextend.Label}
		} else if cerr, ok := isSQLConstraintError(err); ok {
			err = cerr
		}
		return nil, err
	}
	return _node, nil
}
// Code generated by entc, DO NOT EDIT.

package ent

import (
	"context"
	"fmt"
	"time"
	"user/internal/data/ent/predicate"
	"user/internal/data/ent/userextend"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// UserExtendUpdate is the builder for updating UserExtend entities.
type UserExtendUpdate struct {
	config
	hooks    []Hook
	mutation *UserExtendMutation
}

// Where adds a new predicate for the UserExtendUpdate builder.
func (ueu *UserExtendUpdate) Where(ps ...predicate.UserExtend) *UserExtendUpdate {
	ueu.mutation.predicates = append(ueu.mutation.predicates, ps...)
	return ueu
}

// SetPlatUserID sets the "plat_user_id" field.
func (ueu *UserExtendUpdate) SetPlatUserID(u uint) *UserExtendUpdate {
	ueu.mutation.ResetPlatUserID()
	ueu.mutation.SetPlatUserID(u)
	return ueu
}

// AddPlatUserID adds u to the "plat_user_id" field.
func (ueu *UserExtendUpdate) AddPlatUserID(u uint) *UserExtendUpdate {
	ueu.mutation.AddPlatUserID(u)
	return ueu
}

// SetRealName sets the "real_name" field.
func (ueu *UserExtendUpdate) SetRealName(s string) *UserExtendUpdate {
	ueu.mutation.SetRealName(s)
	return ueu
}

// SetNillableRealName sets the "real_name" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableRealName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetRealName(*s)
	}
	return ueu
}

// SetIDNumber sets the "id_number" field.
func (ueu *UserExtendUpdate) SetIDNumber(s string) *UserExtendUpdate {
	ueu.mutation.SetIDNumber(s)
	return ueu
}

// SetNillableIDNumber sets the "id_number" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableIDNumber(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetIDNumber(*s)
	}
	return ueu
}

// SetAge sets the "age" field.
func (ueu *UserExtendUpdate) SetAge(i int8) *UserExtendUpdate {
	ueu.mutation.ResetAge()
	ueu.mutation.SetAge(i)
	return ueu
}

// SetNillableAge sets the "age" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableAge(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetAge(*i)
	}
	return ueu
}

// AddAge adds i to the "age" field.
func (ueu *UserExtendUpdate) AddAge(i int8) *UserExtendUpdate {
	ueu.mutation.AddAge(i)
	return ueu
}

// SetSex sets the "sex" field.
func (ueu *UserExtendUpdate) SetSex(i int8) *UserExtendUpdate {
	ueu.mutation.ResetSex()
	ueu.mutation.SetSex(i)
	return ueu
}

// SetNillableSex sets the "sex" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableSex(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetSex(*i)
	}
	return ueu
}

// AddSex adds i to the "sex" field.
func (ueu *UserExtendUpdate) AddSex(i int8) *UserExtendUpdate {
	ueu.mutation.AddSex(i)
	return ueu
}

// SetBirth sets the "birth" field.
func (ueu *UserExtendUpdate) SetBirth(i int) *UserExtendUpdate {
	ueu.mutation.ResetBirth()
	ueu.mutation.SetBirth(i)
	return ueu
}

// SetNillableBirth sets the "birth" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableBirth(i *int) *UserExtendUpdate {
	if i != nil {
		ueu.SetBirth(*i)
	}
	return ueu
}

// AddBirth adds i to the "birth" field.
func (ueu *UserExtendUpdate) AddBirth(i int) *UserExtendUpdate {
	ueu.mutation.AddBirth(i)
	return ueu
}

// SetIcon sets the "icon" field.
func (ueu *UserExtendUpdate) SetIcon(s string) *UserExtendUpdate {
	ueu.mutation.SetIcon(s)
	return ueu
}

// SetNillableIcon sets the "icon" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableIcon(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetIcon(*s)
	}
	return ueu
}

// SetNickName sets the "nick_name" field.
func (ueu *UserExtendUpdate) SetNickName(s string) *UserExtendUpdate {
	ueu.mutation.SetNickName(s)
	return ueu
}

// SetNillableNickName sets the "nick_name" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableNickName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetNickName(*s)
	}
	return ueu
}

// SetImei sets the "imei" field.
func (ueu *UserExtendUpdate) SetImei(s string) *UserExtendUpdate {
	ueu.mutation.SetImei(s)
	return ueu
}

// SetNillableImei sets the "imei" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableImei(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetImei(*s)
	}
	return ueu
}

// SetOaid sets the "oaid" field.
func (ueu *UserExtendUpdate) SetOaid(s string) *UserExtendUpdate {
	ueu.mutation.SetOaid(s)
	return ueu
}

// SetNillableOaid sets the "oaid" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableOaid(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetOaid(*s)
	}
	return ueu
}

// SetDeviceID sets the "device_id" field.
func (ueu *UserExtendUpdate) SetDeviceID(s string) *UserExtendUpdate {
	ueu.mutation.SetDeviceID(s)
	return ueu
}

// SetNillableDeviceID sets the "device_id" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableDeviceID(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetDeviceID(*s)
	}
	return ueu
}

// SetSystemName sets the "system_name" field.
func (ueu *UserExtendUpdate) SetSystemName(s string) *UserExtendUpdate {
	ueu.mutation.SetSystemName(s)
	return ueu
}

// SetNillableSystemName sets the "system_name" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableSystemName(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetSystemName(*s)
	}
	return ueu
}

// SetSystemVersion sets the "system_version" field.
func (ueu *UserExtendUpdate) SetSystemVersion(s string) *UserExtendUpdate {
	ueu.mutation.SetSystemVersion(s)
	return ueu
}

// SetNillableSystemVersion sets the "system_version" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableSystemVersion(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetSystemVersion(*s)
	}
	return ueu
}

// SetAdid sets the "adid" field.
func (ueu *UserExtendUpdate) SetAdid(s string) *UserExtendUpdate {
	ueu.mutation.SetAdid(s)
	return ueu
}

// SetNillableAdid sets the "adid" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableAdid(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetAdid(*s)
	}
	return ueu
}

// SetGameID sets the "game_id" field.
func (ueu *UserExtendUpdate) SetGameID(s string) *UserExtendUpdate {
	ueu.mutation.SetGameID(s)
	return ueu
}

// SetNillableGameID sets the "game_id" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableGameID(s *string) *UserExtendUpdate {
	if s != nil {
		ueu.SetGameID(*s)
	}
	return ueu
}

// SetThirdPlatformID sets the "third_platform_id" field.
func (ueu *UserExtendUpdate) SetThirdPlatformID(i int8) *UserExtendUpdate {
	ueu.mutation.ResetThirdPlatformID()
	ueu.mutation.SetThirdPlatformID(i)
	return ueu
}

// SetNillableThirdPlatformID sets the "third_platform_id" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableThirdPlatformID(i *int8) *UserExtendUpdate {
	if i != nil {
		ueu.SetThirdPlatformID(*i)
	}
	return ueu
}

// AddThirdPlatformID adds i to the "third_platform_id" field.
func (ueu *UserExtendUpdate) AddThirdPlatformID(i int8) *UserExtendUpdate {
	ueu.mutation.AddThirdPlatformID(i)
	return ueu
}

// SetCreatedAt sets the "created_at" field.
func (ueu *UserExtendUpdate) SetCreatedAt(t time.Time) *UserExtendUpdate {
	ueu.mutation.SetCreatedAt(t)
	return ueu
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (ueu *UserExtendUpdate) SetNillableCreatedAt(t *time.Time) *UserExtendUpdate {
	if t != nil {
		ueu.SetCreatedAt(*t)
	}
	return ueu
}

// SetUpdatedAt sets the "updated_at" field.
func (ueu *UserExtendUpdate) SetUpdatedAt(t time.Time) *UserExtendUpdate {
	ueu.mutation.SetUpdatedAt(t)
	return ueu
}

// Mutation returns the UserExtendMutation object of the builder.
func (ueu *UserExtendUpdate) Mutation() *UserExtendMutation {
	return ueu.mutation
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (ueu *UserExtendUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(ueu.hooks) == 0 {
		affected, err = ueu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*UserExtendMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			ueu.mutation = mutation
			affected, err = ueu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(ueu.hooks) - 1; i >= 0; i-- {
			mut = ueu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, ueu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}

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

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

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

func (ueu *UserExtendUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   userextend.Table,
			Columns: userextend.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: userextend.FieldID,
			},
		},
	}
	if ps := ueu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ueu.mutation.PlatUserID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueu.mutation.AddedPlatUserID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueu.mutation.RealName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldRealName,
		})
	}
	if value, ok := ueu.mutation.IDNumber(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIDNumber,
		})
	}
	if value, ok := ueu.mutation.Age(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueu.mutation.AddedAge(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueu.mutation.Sex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueu.mutation.AddedSex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueu.mutation.Birth(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueu.mutation.AddedBirth(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueu.mutation.Icon(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIcon,
		})
	}
	if value, ok := ueu.mutation.NickName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldNickName,
		})
	}
	if value, ok := ueu.mutation.Imei(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldImei,
		})
	}
	if value, ok := ueu.mutation.Oaid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldOaid,
		})
	}
	if value, ok := ueu.mutation.DeviceID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldDeviceID,
		})
	}
	if value, ok := ueu.mutation.SystemName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemName,
		})
	}
	if value, ok := ueu.mutation.SystemVersion(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemVersion,
		})
	}
	if value, ok := ueu.mutation.Adid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldAdid,
		})
	}
	if value, ok := ueu.mutation.GameID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldGameID,
		})
	}
	if value, ok := ueu.mutation.ThirdPlatformID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueu.mutation.AddedThirdPlatformID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueu.mutation.CreatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldCreatedAt,
		})
	}
	if value, ok := ueu.mutation.UpdatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldUpdatedAt,
		})
	}
	if n, err = sqlgraph.UpdateNodes(ctx, ueu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userextend.Label}
		} else if cerr, ok := isSQLConstraintError(err); ok {
			err = cerr
		}
		return 0, err
	}
	return n, nil
}

// UserExtendUpdateOne is the builder for updating a single UserExtend entity.
type UserExtendUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UserExtendMutation
}

// SetPlatUserID sets the "plat_user_id" field.
func (ueuo *UserExtendUpdateOne) SetPlatUserID(u uint) *UserExtendUpdateOne {
	ueuo.mutation.ResetPlatUserID()
	ueuo.mutation.SetPlatUserID(u)
	return ueuo
}

// AddPlatUserID adds u to the "plat_user_id" field.
func (ueuo *UserExtendUpdateOne) AddPlatUserID(u uint) *UserExtendUpdateOne {
	ueuo.mutation.AddPlatUserID(u)
	return ueuo
}

// SetRealName sets the "real_name" field.
func (ueuo *UserExtendUpdateOne) SetRealName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetRealName(s)
	return ueuo
}

// SetNillableRealName sets the "real_name" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableRealName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetRealName(*s)
	}
	return ueuo
}

// SetIDNumber sets the "id_number" field.
func (ueuo *UserExtendUpdateOne) SetIDNumber(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetIDNumber(s)
	return ueuo
}

// SetNillableIDNumber sets the "id_number" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableIDNumber(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetIDNumber(*s)
	}
	return ueuo
}

// SetAge sets the "age" field.
func (ueuo *UserExtendUpdateOne) SetAge(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetAge()
	ueuo.mutation.SetAge(i)
	return ueuo
}

// SetNillableAge sets the "age" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableAge(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetAge(*i)
	}
	return ueuo
}

// AddAge adds i to the "age" field.
func (ueuo *UserExtendUpdateOne) AddAge(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddAge(i)
	return ueuo
}

// SetSex sets the "sex" field.
func (ueuo *UserExtendUpdateOne) SetSex(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetSex()
	ueuo.mutation.SetSex(i)
	return ueuo
}

// SetNillableSex sets the "sex" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableSex(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetSex(*i)
	}
	return ueuo
}

// AddSex adds i to the "sex" field.
func (ueuo *UserExtendUpdateOne) AddSex(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddSex(i)
	return ueuo
}

// SetBirth sets the "birth" field.
func (ueuo *UserExtendUpdateOne) SetBirth(i int) *UserExtendUpdateOne {
	ueuo.mutation.ResetBirth()
	ueuo.mutation.SetBirth(i)
	return ueuo
}

// SetNillableBirth sets the "birth" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableBirth(i *int) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetBirth(*i)
	}
	return ueuo
}

// AddBirth adds i to the "birth" field.
func (ueuo *UserExtendUpdateOne) AddBirth(i int) *UserExtendUpdateOne {
	ueuo.mutation.AddBirth(i)
	return ueuo
}

// SetIcon sets the "icon" field.
func (ueuo *UserExtendUpdateOne) SetIcon(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetIcon(s)
	return ueuo
}

// SetNillableIcon sets the "icon" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableIcon(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetIcon(*s)
	}
	return ueuo
}

// SetNickName sets the "nick_name" field.
func (ueuo *UserExtendUpdateOne) SetNickName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetNickName(s)
	return ueuo
}

// SetNillableNickName sets the "nick_name" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableNickName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetNickName(*s)
	}
	return ueuo
}

// SetImei sets the "imei" field.
func (ueuo *UserExtendUpdateOne) SetImei(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetImei(s)
	return ueuo
}

// SetNillableImei sets the "imei" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableImei(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetImei(*s)
	}
	return ueuo
}

// SetOaid sets the "oaid" field.
func (ueuo *UserExtendUpdateOne) SetOaid(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetOaid(s)
	return ueuo
}

// SetNillableOaid sets the "oaid" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableOaid(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetOaid(*s)
	}
	return ueuo
}

// SetDeviceID sets the "device_id" field.
func (ueuo *UserExtendUpdateOne) SetDeviceID(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetDeviceID(s)
	return ueuo
}

// SetNillableDeviceID sets the "device_id" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableDeviceID(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetDeviceID(*s)
	}
	return ueuo
}

// SetSystemName sets the "system_name" field.
func (ueuo *UserExtendUpdateOne) SetSystemName(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetSystemName(s)
	return ueuo
}

// SetNillableSystemName sets the "system_name" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableSystemName(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetSystemName(*s)
	}
	return ueuo
}

// SetSystemVersion sets the "system_version" field.
func (ueuo *UserExtendUpdateOne) SetSystemVersion(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetSystemVersion(s)
	return ueuo
}

// SetNillableSystemVersion sets the "system_version" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableSystemVersion(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetSystemVersion(*s)
	}
	return ueuo
}

// SetAdid sets the "adid" field.
func (ueuo *UserExtendUpdateOne) SetAdid(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetAdid(s)
	return ueuo
}

// SetNillableAdid sets the "adid" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableAdid(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetAdid(*s)
	}
	return ueuo
}

// SetGameID sets the "game_id" field.
func (ueuo *UserExtendUpdateOne) SetGameID(s string) *UserExtendUpdateOne {
	ueuo.mutation.SetGameID(s)
	return ueuo
}

// SetNillableGameID sets the "game_id" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableGameID(s *string) *UserExtendUpdateOne {
	if s != nil {
		ueuo.SetGameID(*s)
	}
	return ueuo
}

// SetThirdPlatformID sets the "third_platform_id" field.
func (ueuo *UserExtendUpdateOne) SetThirdPlatformID(i int8) *UserExtendUpdateOne {
	ueuo.mutation.ResetThirdPlatformID()
	ueuo.mutation.SetThirdPlatformID(i)
	return ueuo
}

// SetNillableThirdPlatformID sets the "third_platform_id" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableThirdPlatformID(i *int8) *UserExtendUpdateOne {
	if i != nil {
		ueuo.SetThirdPlatformID(*i)
	}
	return ueuo
}

// AddThirdPlatformID adds i to the "third_platform_id" field.
func (ueuo *UserExtendUpdateOne) AddThirdPlatformID(i int8) *UserExtendUpdateOne {
	ueuo.mutation.AddThirdPlatformID(i)
	return ueuo
}

// SetCreatedAt sets the "created_at" field.
func (ueuo *UserExtendUpdateOne) SetCreatedAt(t time.Time) *UserExtendUpdateOne {
	ueuo.mutation.SetCreatedAt(t)
	return ueuo
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (ueuo *UserExtendUpdateOne) SetNillableCreatedAt(t *time.Time) *UserExtendUpdateOne {
	if t != nil {
		ueuo.SetCreatedAt(*t)
	}
	return ueuo
}

// SetUpdatedAt sets the "updated_at" field.
func (ueuo *UserExtendUpdateOne) SetUpdatedAt(t time.Time) *UserExtendUpdateOne {
	ueuo.mutation.SetUpdatedAt(t)
	return ueuo
}

// Mutation returns the UserExtendMutation object of the builder.
func (ueuo *UserExtendUpdateOne) Mutation() *UserExtendMutation {
	return ueuo.mutation
}

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

// Save executes the query and returns the updated UserExtend entity.
func (ueuo *UserExtendUpdateOne) Save(ctx context.Context) (*UserExtend, error) {
	var (
		err  error
		node *UserExtend
	)
	if len(ueuo.hooks) == 0 {
		node, err = ueuo.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*UserExtendMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			ueuo.mutation = mutation
			node, err = ueuo.sqlSave(ctx)
			mutation.done = true
			return node, err
		})
		for i := len(ueuo.hooks) - 1; i >= 0; i-- {
			mut = ueuo.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, ueuo.mutation); err != nil {
			return nil, err
		}
	}
	return node, err
}

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

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

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

func (ueuo *UserExtendUpdateOne) sqlSave(ctx context.Context) (_node *UserExtend, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   userextend.Table,
			Columns: userextend.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: userextend.FieldID,
			},
		},
	}
	id, ok := ueuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing UserExtend.ID for update")}
	}
	_spec.Node.ID.Value = id
	if fields := ueuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, userextend.FieldID)
		for _, f := range fields {
			if !userextend.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != userextend.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := ueuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ueuo.mutation.PlatUserID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueuo.mutation.AddedPlatUserID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeUint,
			Value:  value,
			Column: userextend.FieldPlatUserID,
		})
	}
	if value, ok := ueuo.mutation.RealName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldRealName,
		})
	}
	if value, ok := ueuo.mutation.IDNumber(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIDNumber,
		})
	}
	if value, ok := ueuo.mutation.Age(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueuo.mutation.AddedAge(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldAge,
		})
	}
	if value, ok := ueuo.mutation.Sex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueuo.mutation.AddedSex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldSex,
		})
	}
	if value, ok := ueuo.mutation.Birth(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueuo.mutation.AddedBirth(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: userextend.FieldBirth,
		})
	}
	if value, ok := ueuo.mutation.Icon(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldIcon,
		})
	}
	if value, ok := ueuo.mutation.NickName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldNickName,
		})
	}
	if value, ok := ueuo.mutation.Imei(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldImei,
		})
	}
	if value, ok := ueuo.mutation.Oaid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldOaid,
		})
	}
	if value, ok := ueuo.mutation.DeviceID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldDeviceID,
		})
	}
	if value, ok := ueuo.mutation.SystemName(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemName,
		})
	}
	if value, ok := ueuo.mutation.SystemVersion(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldSystemVersion,
		})
	}
	if value, ok := ueuo.mutation.Adid(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldAdid,
		})
	}
	if value, ok := ueuo.mutation.GameID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: userextend.FieldGameID,
		})
	}
	if value, ok := ueuo.mutation.ThirdPlatformID(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueuo.mutation.AddedThirdPlatformID(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt8,
			Value:  value,
			Column: userextend.FieldThirdPlatformID,
		})
	}
	if value, ok := ueuo.mutation.CreatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldCreatedAt,
		})
	}
	if value, ok := ueuo.mutation.UpdatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: userextend.FieldUpdatedAt,
		})
	}
	_node = &UserExtend{config: ueuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, ueuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{userextend.Label}
		} else if cerr, ok := isSQLConstraintError(err); ok {
			err = cerr
		}
		return nil, err
	}
	return _node, nil
}
