// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/anzhiyu-c/anheyu-app/ent/comment"
	"github.com/anzhiyu-c/anheyu-app/ent/file"
	"github.com/anzhiyu-c/anheyu-app/ent/predicate"
	"github.com/anzhiyu-c/anheyu-app/ent/user"
	"github.com/anzhiyu-c/anheyu-app/ent/usergroup"
	"github.com/anzhiyu-c/anheyu-app/ent/userinstalledtheme"
)

// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
	config
	hooks     []Hook
	mutation  *UserMutation
	modifiers []func(*sql.UpdateBuilder)
}

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

// SetDeletedAt sets the "deleted_at" field.
func (_u *UserUpdate) SetDeletedAt(v time.Time) *UserUpdate {
	_u.mutation.SetDeletedAt(v)
	return _u
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *UserUpdate) SetNillableDeletedAt(v *time.Time) *UserUpdate {
	if v != nil {
		_u.SetDeletedAt(*v)
	}
	return _u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *UserUpdate) ClearDeletedAt() *UserUpdate {
	_u.mutation.ClearDeletedAt()
	return _u
}

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

// SetUsername sets the "username" field.
func (_u *UserUpdate) SetUsername(v string) *UserUpdate {
	_u.mutation.SetUsername(v)
	return _u
}

// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *UserUpdate) SetNillableUsername(v *string) *UserUpdate {
	if v != nil {
		_u.SetUsername(*v)
	}
	return _u
}

// SetPasswordHash sets the "password_hash" field.
func (_u *UserUpdate) SetPasswordHash(v string) *UserUpdate {
	_u.mutation.SetPasswordHash(v)
	return _u
}

// SetNillablePasswordHash sets the "password_hash" field if the given value is not nil.
func (_u *UserUpdate) SetNillablePasswordHash(v *string) *UserUpdate {
	if v != nil {
		_u.SetPasswordHash(*v)
	}
	return _u
}

// SetNickname sets the "nickname" field.
func (_u *UserUpdate) SetNickname(v string) *UserUpdate {
	_u.mutation.SetNickname(v)
	return _u
}

// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (_u *UserUpdate) SetNillableNickname(v *string) *UserUpdate {
	if v != nil {
		_u.SetNickname(*v)
	}
	return _u
}

// ClearNickname clears the value of the "nickname" field.
func (_u *UserUpdate) ClearNickname() *UserUpdate {
	_u.mutation.ClearNickname()
	return _u
}

// SetAvatar sets the "avatar" field.
func (_u *UserUpdate) SetAvatar(v string) *UserUpdate {
	_u.mutation.SetAvatar(v)
	return _u
}

// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (_u *UserUpdate) SetNillableAvatar(v *string) *UserUpdate {
	if v != nil {
		_u.SetAvatar(*v)
	}
	return _u
}

// ClearAvatar clears the value of the "avatar" field.
func (_u *UserUpdate) ClearAvatar() *UserUpdate {
	_u.mutation.ClearAvatar()
	return _u
}

// SetEmail sets the "email" field.
func (_u *UserUpdate) SetEmail(v string) *UserUpdate {
	_u.mutation.SetEmail(v)
	return _u
}

// SetNillableEmail sets the "email" field if the given value is not nil.
func (_u *UserUpdate) SetNillableEmail(v *string) *UserUpdate {
	if v != nil {
		_u.SetEmail(*v)
	}
	return _u
}

// ClearEmail clears the value of the "email" field.
func (_u *UserUpdate) ClearEmail() *UserUpdate {
	_u.mutation.ClearEmail()
	return _u
}

// SetWebsite sets the "website" field.
func (_u *UserUpdate) SetWebsite(v string) *UserUpdate {
	_u.mutation.SetWebsite(v)
	return _u
}

// SetNillableWebsite sets the "website" field if the given value is not nil.
func (_u *UserUpdate) SetNillableWebsite(v *string) *UserUpdate {
	if v != nil {
		_u.SetWebsite(*v)
	}
	return _u
}

// ClearWebsite clears the value of the "website" field.
func (_u *UserUpdate) ClearWebsite() *UserUpdate {
	_u.mutation.ClearWebsite()
	return _u
}

// SetLastLoginAt sets the "last_login_at" field.
func (_u *UserUpdate) SetLastLoginAt(v time.Time) *UserUpdate {
	_u.mutation.SetLastLoginAt(v)
	return _u
}

// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
func (_u *UserUpdate) SetNillableLastLoginAt(v *time.Time) *UserUpdate {
	if v != nil {
		_u.SetLastLoginAt(*v)
	}
	return _u
}

// ClearLastLoginAt clears the value of the "last_login_at" field.
func (_u *UserUpdate) ClearLastLoginAt() *UserUpdate {
	_u.mutation.ClearLastLoginAt()
	return _u
}

// SetStatus sets the "status" field.
func (_u *UserUpdate) SetStatus(v int) *UserUpdate {
	_u.mutation.ResetStatus()
	_u.mutation.SetStatus(v)
	return _u
}

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

// AddStatus adds value to the "status" field.
func (_u *UserUpdate) AddStatus(v int) *UserUpdate {
	_u.mutation.AddStatus(v)
	return _u
}

// SetUserGroupID sets the "user_group" edge to the UserGroup entity by ID.
func (_u *UserUpdate) SetUserGroupID(id uint) *UserUpdate {
	_u.mutation.SetUserGroupID(id)
	return _u
}

// SetUserGroup sets the "user_group" edge to the UserGroup entity.
func (_u *UserUpdate) SetUserGroup(v *UserGroup) *UserUpdate {
	return _u.SetUserGroupID(v.ID)
}

// AddFileIDs adds the "files" edge to the File entity by IDs.
func (_u *UserUpdate) AddFileIDs(ids ...uint) *UserUpdate {
	_u.mutation.AddFileIDs(ids...)
	return _u
}

// AddFiles adds the "files" edges to the File entity.
func (_u *UserUpdate) AddFiles(v ...*File) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddFileIDs(ids...)
}

// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
func (_u *UserUpdate) AddCommentIDs(ids ...uint) *UserUpdate {
	_u.mutation.AddCommentIDs(ids...)
	return _u
}

// AddComments adds the "comments" edges to the Comment entity.
func (_u *UserUpdate) AddComments(v ...*Comment) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCommentIDs(ids...)
}

// AddInstalledThemeIDs adds the "installed_themes" edge to the UserInstalledTheme entity by IDs.
func (_u *UserUpdate) AddInstalledThemeIDs(ids ...uint) *UserUpdate {
	_u.mutation.AddInstalledThemeIDs(ids...)
	return _u
}

// AddInstalledThemes adds the "installed_themes" edges to the UserInstalledTheme entity.
func (_u *UserUpdate) AddInstalledThemes(v ...*UserInstalledTheme) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddInstalledThemeIDs(ids...)
}

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

// ClearUserGroup clears the "user_group" edge to the UserGroup entity.
func (_u *UserUpdate) ClearUserGroup() *UserUpdate {
	_u.mutation.ClearUserGroup()
	return _u
}

// ClearFiles clears all "files" edges to the File entity.
func (_u *UserUpdate) ClearFiles() *UserUpdate {
	_u.mutation.ClearFiles()
	return _u
}

// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (_u *UserUpdate) RemoveFileIDs(ids ...uint) *UserUpdate {
	_u.mutation.RemoveFileIDs(ids...)
	return _u
}

// RemoveFiles removes "files" edges to File entities.
func (_u *UserUpdate) RemoveFiles(v ...*File) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveFileIDs(ids...)
}

// ClearComments clears all "comments" edges to the Comment entity.
func (_u *UserUpdate) ClearComments() *UserUpdate {
	_u.mutation.ClearComments()
	return _u
}

// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
func (_u *UserUpdate) RemoveCommentIDs(ids ...uint) *UserUpdate {
	_u.mutation.RemoveCommentIDs(ids...)
	return _u
}

// RemoveComments removes "comments" edges to Comment entities.
func (_u *UserUpdate) RemoveComments(v ...*Comment) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCommentIDs(ids...)
}

// ClearInstalledThemes clears all "installed_themes" edges to the UserInstalledTheme entity.
func (_u *UserUpdate) ClearInstalledThemes() *UserUpdate {
	_u.mutation.ClearInstalledThemes()
	return _u
}

// RemoveInstalledThemeIDs removes the "installed_themes" edge to UserInstalledTheme entities by IDs.
func (_u *UserUpdate) RemoveInstalledThemeIDs(ids ...uint) *UserUpdate {
	_u.mutation.RemoveInstalledThemeIDs(ids...)
	return _u
}

// RemoveInstalledThemes removes "installed_themes" edges to UserInstalledTheme entities.
func (_u *UserUpdate) RemoveInstalledThemes(v ...*UserInstalledTheme) *UserUpdate {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveInstalledThemeIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
	if err := _u.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *UserUpdate) 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 *UserUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if user.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized user.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := user.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *UserUpdate) check() error {
	if v, ok := _u.mutation.Username(); ok {
		if err := user.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PasswordHash(); ok {
		if err := user.PasswordHashValidator(v); err != nil {
			return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Nickname(); ok {
		if err := user.NicknameValidator(v); err != nil {
			return &ValidationError{Name: "nickname", err: fmt.Errorf(`ent: validator failed for field "User.nickname": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Avatar(); ok {
		if err := user.AvatarValidator(v); err != nil {
			return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "User.avatar": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Email(); ok {
		if err := user.EmailValidator(v); err != nil {
			return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Website(); ok {
		if err := user.WebsiteValidator(v); err != nil {
			return &ValidationError{Name: "website", err: fmt.Errorf(`ent: validator failed for field "User.website": %w`, err)}
		}
	}
	if _u.mutation.UserGroupCleared() && len(_u.mutation.UserGroupIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "User.user_group"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdate {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint))
	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.DeletedAt(); ok {
		_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Username(); ok {
		_spec.SetField(user.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(user.FieldNickname, field.TypeString, value)
	}
	if _u.mutation.NicknameCleared() {
		_spec.ClearField(user.FieldNickname, field.TypeString)
	}
	if value, ok := _u.mutation.Avatar(); ok {
		_spec.SetField(user.FieldAvatar, field.TypeString, value)
	}
	if _u.mutation.AvatarCleared() {
		_spec.ClearField(user.FieldAvatar, field.TypeString)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if _u.mutation.EmailCleared() {
		_spec.ClearField(user.FieldEmail, field.TypeString)
	}
	if value, ok := _u.mutation.Website(); ok {
		_spec.SetField(user.FieldWebsite, field.TypeString, value)
	}
	if _u.mutation.WebsiteCleared() {
		_spec.ClearField(user.FieldWebsite, field.TypeString)
	}
	if value, ok := _u.mutation.LastLoginAt(); ok {
		_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
	}
	if _u.mutation.LastLoginAtCleared() {
		_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(user.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedStatus(); ok {
		_spec.AddField(user.FieldStatus, field.TypeInt, value)
	}
	if _u.mutation.UserGroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   user.UserGroupTable,
			Columns: []string{user.UserGroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserGroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   user.UserGroupTable,
			Columns: []string{user.UserGroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedFilesIDs(); len(nodes) > 0 && !_u.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.FilesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !_u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.CommentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.InstalledThemesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedInstalledThemesIDs(); len(nodes) > 0 && !_u.mutation.InstalledThemesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.InstalledThemesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{user.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// UserUpdateOne is the builder for updating a single User entity.
type UserUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *UserMutation
	modifiers []func(*sql.UpdateBuilder)
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *UserUpdateOne) SetDeletedAt(v time.Time) *UserUpdateOne {
	_u.mutation.SetDeletedAt(v)
	return _u
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableDeletedAt(v *time.Time) *UserUpdateOne {
	if v != nil {
		_u.SetDeletedAt(*v)
	}
	return _u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *UserUpdateOne) ClearDeletedAt() *UserUpdateOne {
	_u.mutation.ClearDeletedAt()
	return _u
}

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

// SetUsername sets the "username" field.
func (_u *UserUpdateOne) SetUsername(v string) *UserUpdateOne {
	_u.mutation.SetUsername(v)
	return _u
}

// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableUsername(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetUsername(*v)
	}
	return _u
}

// SetPasswordHash sets the "password_hash" field.
func (_u *UserUpdateOne) SetPasswordHash(v string) *UserUpdateOne {
	_u.mutation.SetPasswordHash(v)
	return _u
}

// SetNillablePasswordHash sets the "password_hash" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillablePasswordHash(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetPasswordHash(*v)
	}
	return _u
}

// SetNickname sets the "nickname" field.
func (_u *UserUpdateOne) SetNickname(v string) *UserUpdateOne {
	_u.mutation.SetNickname(v)
	return _u
}

// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableNickname(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetNickname(*v)
	}
	return _u
}

// ClearNickname clears the value of the "nickname" field.
func (_u *UserUpdateOne) ClearNickname() *UserUpdateOne {
	_u.mutation.ClearNickname()
	return _u
}

// SetAvatar sets the "avatar" field.
func (_u *UserUpdateOne) SetAvatar(v string) *UserUpdateOne {
	_u.mutation.SetAvatar(v)
	return _u
}

// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableAvatar(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetAvatar(*v)
	}
	return _u
}

// ClearAvatar clears the value of the "avatar" field.
func (_u *UserUpdateOne) ClearAvatar() *UserUpdateOne {
	_u.mutation.ClearAvatar()
	return _u
}

// SetEmail sets the "email" field.
func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne {
	_u.mutation.SetEmail(v)
	return _u
}

// SetNillableEmail sets the "email" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableEmail(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetEmail(*v)
	}
	return _u
}

// ClearEmail clears the value of the "email" field.
func (_u *UserUpdateOne) ClearEmail() *UserUpdateOne {
	_u.mutation.ClearEmail()
	return _u
}

// SetWebsite sets the "website" field.
func (_u *UserUpdateOne) SetWebsite(v string) *UserUpdateOne {
	_u.mutation.SetWebsite(v)
	return _u
}

// SetNillableWebsite sets the "website" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableWebsite(v *string) *UserUpdateOne {
	if v != nil {
		_u.SetWebsite(*v)
	}
	return _u
}

// ClearWebsite clears the value of the "website" field.
func (_u *UserUpdateOne) ClearWebsite() *UserUpdateOne {
	_u.mutation.ClearWebsite()
	return _u
}

// SetLastLoginAt sets the "last_login_at" field.
func (_u *UserUpdateOne) SetLastLoginAt(v time.Time) *UserUpdateOne {
	_u.mutation.SetLastLoginAt(v)
	return _u
}

// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableLastLoginAt(v *time.Time) *UserUpdateOne {
	if v != nil {
		_u.SetLastLoginAt(*v)
	}
	return _u
}

// ClearLastLoginAt clears the value of the "last_login_at" field.
func (_u *UserUpdateOne) ClearLastLoginAt() *UserUpdateOne {
	_u.mutation.ClearLastLoginAt()
	return _u
}

// SetStatus sets the "status" field.
func (_u *UserUpdateOne) SetStatus(v int) *UserUpdateOne {
	_u.mutation.ResetStatus()
	_u.mutation.SetStatus(v)
	return _u
}

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

// AddStatus adds value to the "status" field.
func (_u *UserUpdateOne) AddStatus(v int) *UserUpdateOne {
	_u.mutation.AddStatus(v)
	return _u
}

// SetUserGroupID sets the "user_group" edge to the UserGroup entity by ID.
func (_u *UserUpdateOne) SetUserGroupID(id uint) *UserUpdateOne {
	_u.mutation.SetUserGroupID(id)
	return _u
}

// SetUserGroup sets the "user_group" edge to the UserGroup entity.
func (_u *UserUpdateOne) SetUserGroup(v *UserGroup) *UserUpdateOne {
	return _u.SetUserGroupID(v.ID)
}

// AddFileIDs adds the "files" edge to the File entity by IDs.
func (_u *UserUpdateOne) AddFileIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.AddFileIDs(ids...)
	return _u
}

// AddFiles adds the "files" edges to the File entity.
func (_u *UserUpdateOne) AddFiles(v ...*File) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddFileIDs(ids...)
}

// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
func (_u *UserUpdateOne) AddCommentIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.AddCommentIDs(ids...)
	return _u
}

// AddComments adds the "comments" edges to the Comment entity.
func (_u *UserUpdateOne) AddComments(v ...*Comment) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddCommentIDs(ids...)
}

// AddInstalledThemeIDs adds the "installed_themes" edge to the UserInstalledTheme entity by IDs.
func (_u *UserUpdateOne) AddInstalledThemeIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.AddInstalledThemeIDs(ids...)
	return _u
}

// AddInstalledThemes adds the "installed_themes" edges to the UserInstalledTheme entity.
func (_u *UserUpdateOne) AddInstalledThemes(v ...*UserInstalledTheme) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddInstalledThemeIDs(ids...)
}

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

// ClearUserGroup clears the "user_group" edge to the UserGroup entity.
func (_u *UserUpdateOne) ClearUserGroup() *UserUpdateOne {
	_u.mutation.ClearUserGroup()
	return _u
}

// ClearFiles clears all "files" edges to the File entity.
func (_u *UserUpdateOne) ClearFiles() *UserUpdateOne {
	_u.mutation.ClearFiles()
	return _u
}

// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (_u *UserUpdateOne) RemoveFileIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.RemoveFileIDs(ids...)
	return _u
}

// RemoveFiles removes "files" edges to File entities.
func (_u *UserUpdateOne) RemoveFiles(v ...*File) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveFileIDs(ids...)
}

// ClearComments clears all "comments" edges to the Comment entity.
func (_u *UserUpdateOne) ClearComments() *UserUpdateOne {
	_u.mutation.ClearComments()
	return _u
}

// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
func (_u *UserUpdateOne) RemoveCommentIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.RemoveCommentIDs(ids...)
	return _u
}

// RemoveComments removes "comments" edges to Comment entities.
func (_u *UserUpdateOne) RemoveComments(v ...*Comment) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveCommentIDs(ids...)
}

// ClearInstalledThemes clears all "installed_themes" edges to the UserInstalledTheme entity.
func (_u *UserUpdateOne) ClearInstalledThemes() *UserUpdateOne {
	_u.mutation.ClearInstalledThemes()
	return _u
}

// RemoveInstalledThemeIDs removes the "installed_themes" edge to UserInstalledTheme entities by IDs.
func (_u *UserUpdateOne) RemoveInstalledThemeIDs(ids ...uint) *UserUpdateOne {
	_u.mutation.RemoveInstalledThemeIDs(ids...)
	return _u
}

// RemoveInstalledThemes removes "installed_themes" edges to UserInstalledTheme entities.
func (_u *UserUpdateOne) RemoveInstalledThemes(v ...*UserInstalledTheme) *UserUpdateOne {
	ids := make([]uint, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveInstalledThemeIDs(ids...)
}

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

// Save executes the query and returns the updated User entity.
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
	if err := _u.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_u *UserUpdateOne) 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 *UserUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if user.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized user.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := user.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *UserUpdateOne) check() error {
	if v, ok := _u.mutation.Username(); ok {
		if err := user.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PasswordHash(); ok {
		if err := user.PasswordHashValidator(v); err != nil {
			return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Nickname(); ok {
		if err := user.NicknameValidator(v); err != nil {
			return &ValidationError{Name: "nickname", err: fmt.Errorf(`ent: validator failed for field "User.nickname": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Avatar(); ok {
		if err := user.AvatarValidator(v); err != nil {
			return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "User.avatar": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Email(); ok {
		if err := user.EmailValidator(v); err != nil {
			return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Website(); ok {
		if err := user.WebsiteValidator(v); err != nil {
			return &ValidationError{Name: "website", err: fmt.Errorf(`ent: validator failed for field "User.website": %w`, err)}
		}
	}
	if _u.mutation.UserGroupCleared() && len(_u.mutation.UserGroupIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "User.user_group"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdateOne {
	_u.modifiers = append(_u.modifiers, modifiers...)
	return _u
}

func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.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, user.FieldID)
		for _, f := range fields {
			if !user.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != user.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.DeletedAt(); ok {
		_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Username(); ok {
		_spec.SetField(user.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(user.FieldNickname, field.TypeString, value)
	}
	if _u.mutation.NicknameCleared() {
		_spec.ClearField(user.FieldNickname, field.TypeString)
	}
	if value, ok := _u.mutation.Avatar(); ok {
		_spec.SetField(user.FieldAvatar, field.TypeString, value)
	}
	if _u.mutation.AvatarCleared() {
		_spec.ClearField(user.FieldAvatar, field.TypeString)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if _u.mutation.EmailCleared() {
		_spec.ClearField(user.FieldEmail, field.TypeString)
	}
	if value, ok := _u.mutation.Website(); ok {
		_spec.SetField(user.FieldWebsite, field.TypeString, value)
	}
	if _u.mutation.WebsiteCleared() {
		_spec.ClearField(user.FieldWebsite, field.TypeString)
	}
	if value, ok := _u.mutation.LastLoginAt(); ok {
		_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
	}
	if _u.mutation.LastLoginAtCleared() {
		_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(user.FieldStatus, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedStatus(); ok {
		_spec.AddField(user.FieldStatus, field.TypeInt, value)
	}
	if _u.mutation.UserGroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   user.UserGroupTable,
			Columns: []string{user.UserGroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserGroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   user.UserGroupTable,
			Columns: []string{user.UserGroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedFilesIDs(); len(nodes) > 0 && !_u.mutation.FilesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.FilesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.FilesTable,
			Columns: []string{user.FilesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !_u.mutation.CommentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.CommentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.CommentsTable,
			Columns: []string{user.CommentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.InstalledThemesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedInstalledThemesIDs(); len(nodes) > 0 && !_u.mutation.InstalledThemesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.InstalledThemesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.InstalledThemesTable,
			Columns: []string{user.InstalledThemesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userinstalledtheme.FieldID, field.TypeUint),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(_u.modifiers...)
	_node = &User{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{user.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
