// Code generated by ent, DO NOT EDIT.

package models

import (
	"context"
	"errors"
	"fmt"
	"juwan-backend/app/users/rpc/internal/models/predicate"
	"juwan-backend/app/users/rpc/internal/models/schema"
	"juwan-backend/app/users/rpc/internal/models/users"
	"juwan-backend/pkg/types"
	"time"

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

// UsersUpdate is the builder for updating Users entities.
type UsersUpdate struct {
	config
	hooks    []Hook
	mutation *UsersMutation
}

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

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

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

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

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

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

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

// SetPhone sets the "phone" field.
func (_u *UsersUpdate) SetPhone(v string) *UsersUpdate {
	_u.mutation.SetPhone(v)
	return _u
}

// SetNillablePhone sets the "phone" field if the given value is not nil.
func (_u *UsersUpdate) SetNillablePhone(v *string) *UsersUpdate {
	if v != nil {
		_u.SetPhone(*v)
	}
	return _u
}

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

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

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

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

// SetBio sets the "bio" field.
func (_u *UsersUpdate) SetBio(v string) *UsersUpdate {
	_u.mutation.SetBio(v)
	return _u
}

// SetNillableBio sets the "bio" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableBio(v *string) *UsersUpdate {
	if v != nil {
		_u.SetBio(*v)
	}
	return _u
}

// SetCurrentRole sets the "current_role" field.
func (_u *UsersUpdate) SetCurrentRole(v string) *UsersUpdate {
	_u.mutation.SetCurrentRole(v)
	return _u
}

// SetNillableCurrentRole sets the "current_role" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableCurrentRole(v *string) *UsersUpdate {
	if v != nil {
		_u.SetCurrentRole(*v)
	}
	return _u
}

// SetVerificationStatus sets the "verificationStatus" field.
func (_u *UsersUpdate) SetVerificationStatus(v schema.VerificationStatusStruct) *UsersUpdate {
	_u.mutation.SetVerificationStatus(v)
	return _u
}

// SetNillableVerificationStatus sets the "verificationStatus" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableVerificationStatus(v *schema.VerificationStatusStruct) *UsersUpdate {
	if v != nil {
		_u.SetVerificationStatus(*v)
	}
	return _u
}

// ClearVerificationStatus clears the value of the "verificationStatus" field.
func (_u *UsersUpdate) ClearVerificationStatus() *UsersUpdate {
	_u.mutation.ClearVerificationStatus()
	return _u
}

// SetIsAdmin sets the "is_admin" field.
func (_u *UsersUpdate) SetIsAdmin(v bool) *UsersUpdate {
	_u.mutation.SetIsAdmin(v)
	return _u
}

// SetNillableIsAdmin sets the "is_admin" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableIsAdmin(v *bool) *UsersUpdate {
	if v != nil {
		_u.SetIsAdmin(*v)
	}
	return _u
}

// SetCreatedAt sets the "created_at" field.
func (_u *UsersUpdate) SetCreatedAt(v time.Time) *UsersUpdate {
	_u.mutation.SetCreatedAt(v)
	return _u
}

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

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

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableUpdatedAt(v *time.Time) *UsersUpdate {
	if v != nil {
		_u.SetUpdatedAt(*v)
	}
	return _u
}

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

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

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

// SetVerifiedRoles sets the "verified_roles" field.
func (_u *UsersUpdate) SetVerifiedRoles(v types.TextArray) *UsersUpdate {
	_u.mutation.SetVerifiedRoles(v)
	return _u
}

// SetNillableVerifiedRoles sets the "verified_roles" field if the given value is not nil.
func (_u *UsersUpdate) SetNillableVerifiedRoles(v *types.TextArray) *UsersUpdate {
	if v != nil {
		_u.SetVerifiedRoles(*v)
	}
	return _u
}

// ClearVerifiedRoles clears the value of the "verified_roles" field.
func (_u *UsersUpdate) ClearVerifiedRoles() *UsersUpdate {
	_u.mutation.ClearVerifiedRoles()
	return _u
}

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

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

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

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

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

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

func (_u *UsersUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(users.Table, users.Columns, sqlgraph.NewFieldSpec(users.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.Username(); ok {
		_spec.SetField(users.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(users.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(users.FieldEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.Phone(); ok {
		_spec.SetField(users.FieldPhone, field.TypeString, value)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(users.FieldNickname, field.TypeString, value)
	}
	if value, ok := _u.mutation.Avatar(); ok {
		_spec.SetField(users.FieldAvatar, field.TypeString, value)
	}
	if value, ok := _u.mutation.Bio(); ok {
		_spec.SetField(users.FieldBio, field.TypeString, value)
	}
	if value, ok := _u.mutation.CurrentRole(); ok {
		_spec.SetField(users.FieldCurrentRole, field.TypeString, value)
	}
	if value, ok := _u.mutation.VerificationStatus(); ok {
		_spec.SetField(users.FieldVerificationStatus, field.TypeJSON, value)
	}
	if _u.mutation.VerificationStatusCleared() {
		_spec.ClearField(users.FieldVerificationStatus, field.TypeJSON)
	}
	if value, ok := _u.mutation.IsAdmin(); ok {
		_spec.SetField(users.FieldIsAdmin, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(users.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(users.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(users.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(users.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.VerifiedRoles(); ok {
		_spec.SetField(users.FieldVerifiedRoles, field.TypeOther, value)
	}
	if _u.mutation.VerifiedRolesCleared() {
		_spec.ClearField(users.FieldVerifiedRoles, field.TypeOther)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{users.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// UsersUpdateOne is the builder for updating a single Users entity.
type UsersUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UsersMutation
}

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

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

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

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

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

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

// SetPhone sets the "phone" field.
func (_u *UsersUpdateOne) SetPhone(v string) *UsersUpdateOne {
	_u.mutation.SetPhone(v)
	return _u
}

// SetNillablePhone sets the "phone" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillablePhone(v *string) *UsersUpdateOne {
	if v != nil {
		_u.SetPhone(*v)
	}
	return _u
}

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

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

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

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

// SetBio sets the "bio" field.
func (_u *UsersUpdateOne) SetBio(v string) *UsersUpdateOne {
	_u.mutation.SetBio(v)
	return _u
}

// SetNillableBio sets the "bio" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableBio(v *string) *UsersUpdateOne {
	if v != nil {
		_u.SetBio(*v)
	}
	return _u
}

// SetCurrentRole sets the "current_role" field.
func (_u *UsersUpdateOne) SetCurrentRole(v string) *UsersUpdateOne {
	_u.mutation.SetCurrentRole(v)
	return _u
}

// SetNillableCurrentRole sets the "current_role" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableCurrentRole(v *string) *UsersUpdateOne {
	if v != nil {
		_u.SetCurrentRole(*v)
	}
	return _u
}

// SetVerificationStatus sets the "verificationStatus" field.
func (_u *UsersUpdateOne) SetVerificationStatus(v schema.VerificationStatusStruct) *UsersUpdateOne {
	_u.mutation.SetVerificationStatus(v)
	return _u
}

// SetNillableVerificationStatus sets the "verificationStatus" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableVerificationStatus(v *schema.VerificationStatusStruct) *UsersUpdateOne {
	if v != nil {
		_u.SetVerificationStatus(*v)
	}
	return _u
}

// ClearVerificationStatus clears the value of the "verificationStatus" field.
func (_u *UsersUpdateOne) ClearVerificationStatus() *UsersUpdateOne {
	_u.mutation.ClearVerificationStatus()
	return _u
}

// SetIsAdmin sets the "is_admin" field.
func (_u *UsersUpdateOne) SetIsAdmin(v bool) *UsersUpdateOne {
	_u.mutation.SetIsAdmin(v)
	return _u
}

// SetNillableIsAdmin sets the "is_admin" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableIsAdmin(v *bool) *UsersUpdateOne {
	if v != nil {
		_u.SetIsAdmin(*v)
	}
	return _u
}

// SetCreatedAt sets the "created_at" field.
func (_u *UsersUpdateOne) SetCreatedAt(v time.Time) *UsersUpdateOne {
	_u.mutation.SetCreatedAt(v)
	return _u
}

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

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

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableUpdatedAt(v *time.Time) *UsersUpdateOne {
	if v != nil {
		_u.SetUpdatedAt(*v)
	}
	return _u
}

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

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

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

// SetVerifiedRoles sets the "verified_roles" field.
func (_u *UsersUpdateOne) SetVerifiedRoles(v types.TextArray) *UsersUpdateOne {
	_u.mutation.SetVerifiedRoles(v)
	return _u
}

// SetNillableVerifiedRoles sets the "verified_roles" field if the given value is not nil.
func (_u *UsersUpdateOne) SetNillableVerifiedRoles(v *types.TextArray) *UsersUpdateOne {
	if v != nil {
		_u.SetVerifiedRoles(*v)
	}
	return _u
}

// ClearVerifiedRoles clears the value of the "verified_roles" field.
func (_u *UsersUpdateOne) ClearVerifiedRoles() *UsersUpdateOne {
	_u.mutation.ClearVerifiedRoles()
	return _u
}

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

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

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

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

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

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

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

func (_u *UsersUpdateOne) sqlSave(ctx context.Context) (_node *Users, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(users.Table, users.Columns, sqlgraph.NewFieldSpec(users.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Users.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, users.FieldID)
		for _, f := range fields {
			if !users.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
			}
			if f != users.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.Username(); ok {
		_spec.SetField(users.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(users.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(users.FieldEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.Phone(); ok {
		_spec.SetField(users.FieldPhone, field.TypeString, value)
	}
	if value, ok := _u.mutation.Nickname(); ok {
		_spec.SetField(users.FieldNickname, field.TypeString, value)
	}
	if value, ok := _u.mutation.Avatar(); ok {
		_spec.SetField(users.FieldAvatar, field.TypeString, value)
	}
	if value, ok := _u.mutation.Bio(); ok {
		_spec.SetField(users.FieldBio, field.TypeString, value)
	}
	if value, ok := _u.mutation.CurrentRole(); ok {
		_spec.SetField(users.FieldCurrentRole, field.TypeString, value)
	}
	if value, ok := _u.mutation.VerificationStatus(); ok {
		_spec.SetField(users.FieldVerificationStatus, field.TypeJSON, value)
	}
	if _u.mutation.VerificationStatusCleared() {
		_spec.ClearField(users.FieldVerificationStatus, field.TypeJSON)
	}
	if value, ok := _u.mutation.IsAdmin(); ok {
		_spec.SetField(users.FieldIsAdmin, field.TypeBool, value)
	}
	if value, ok := _u.mutation.CreatedAt(); ok {
		_spec.SetField(users.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(users.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(users.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(users.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.VerifiedRoles(); ok {
		_spec.SetField(users.FieldVerifiedRoles, field.TypeOther, value)
	}
	if _u.mutation.VerifiedRolesCleared() {
		_spec.ClearField(users.FieldVerifiedRoles, field.TypeOther)
	}
	_node = &Users{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{users.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
