// 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/Wei-Shaw/sub2api/ent/account"
	"github.com/Wei-Shaw/sub2api/ent/group"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
)

// AccountUpdate is the builder for updating Account entities.
type AccountUpdate struct {
	config
	hooks    []Hook
	mutation *AccountMutation
}

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

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

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

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

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

// SetName sets the "name" field.
func (_u *AccountUpdate) SetName(v string) *AccountUpdate {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableName(v *string) *AccountUpdate {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetPlatform sets the "platform" field.
func (_u *AccountUpdate) SetPlatform(v string) *AccountUpdate {
	_u.mutation.SetPlatform(v)
	return _u
}

// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *AccountUpdate) SetNillablePlatform(v *string) *AccountUpdate {
	if v != nil {
		_u.SetPlatform(*v)
	}
	return _u
}

// SetType sets the "type" field.
func (_u *AccountUpdate) SetType(v string) *AccountUpdate {
	_u.mutation.SetType(v)
	return _u
}

// SetNillableType sets the "type" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableType(v *string) *AccountUpdate {
	if v != nil {
		_u.SetType(*v)
	}
	return _u
}

// SetCredentials sets the "credentials" field.
func (_u *AccountUpdate) SetCredentials(v map[string]interface{}) *AccountUpdate {
	_u.mutation.SetCredentials(v)
	return _u
}

// SetExtra sets the "extra" field.
func (_u *AccountUpdate) SetExtra(v map[string]interface{}) *AccountUpdate {
	_u.mutation.SetExtra(v)
	return _u
}

// SetProxyID sets the "proxy_id" field.
func (_u *AccountUpdate) SetProxyID(v int64) *AccountUpdate {
	_u.mutation.ResetProxyID()
	_u.mutation.SetProxyID(v)
	return _u
}

// SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableProxyID(v *int64) *AccountUpdate {
	if v != nil {
		_u.SetProxyID(*v)
	}
	return _u
}

// AddProxyID adds value to the "proxy_id" field.
func (_u *AccountUpdate) AddProxyID(v int64) *AccountUpdate {
	_u.mutation.AddProxyID(v)
	return _u
}

// ClearProxyID clears the value of the "proxy_id" field.
func (_u *AccountUpdate) ClearProxyID() *AccountUpdate {
	_u.mutation.ClearProxyID()
	return _u
}

// SetConcurrency sets the "concurrency" field.
func (_u *AccountUpdate) SetConcurrency(v int) *AccountUpdate {
	_u.mutation.ResetConcurrency()
	_u.mutation.SetConcurrency(v)
	return _u
}

// SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableConcurrency(v *int) *AccountUpdate {
	if v != nil {
		_u.SetConcurrency(*v)
	}
	return _u
}

// AddConcurrency adds value to the "concurrency" field.
func (_u *AccountUpdate) AddConcurrency(v int) *AccountUpdate {
	_u.mutation.AddConcurrency(v)
	return _u
}

// SetPriority sets the "priority" field.
func (_u *AccountUpdate) SetPriority(v int) *AccountUpdate {
	_u.mutation.ResetPriority()
	_u.mutation.SetPriority(v)
	return _u
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_u *AccountUpdate) SetNillablePriority(v *int) *AccountUpdate {
	if v != nil {
		_u.SetPriority(*v)
	}
	return _u
}

// AddPriority adds value to the "priority" field.
func (_u *AccountUpdate) AddPriority(v int) *AccountUpdate {
	_u.mutation.AddPriority(v)
	return _u
}

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

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

// SetErrorMessage sets the "error_message" field.
func (_u *AccountUpdate) SetErrorMessage(v string) *AccountUpdate {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableErrorMessage(v *string) *AccountUpdate {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *AccountUpdate) ClearErrorMessage() *AccountUpdate {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetLastUsedAt sets the "last_used_at" field.
func (_u *AccountUpdate) SetLastUsedAt(v time.Time) *AccountUpdate {
	_u.mutation.SetLastUsedAt(v)
	return _u
}

// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableLastUsedAt(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetLastUsedAt(*v)
	}
	return _u
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (_u *AccountUpdate) ClearLastUsedAt() *AccountUpdate {
	_u.mutation.ClearLastUsedAt()
	return _u
}

// SetSchedulable sets the "schedulable" field.
func (_u *AccountUpdate) SetSchedulable(v bool) *AccountUpdate {
	_u.mutation.SetSchedulable(v)
	return _u
}

// SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableSchedulable(v *bool) *AccountUpdate {
	if v != nil {
		_u.SetSchedulable(*v)
	}
	return _u
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (_u *AccountUpdate) SetRateLimitedAt(v time.Time) *AccountUpdate {
	_u.mutation.SetRateLimitedAt(v)
	return _u
}

// SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableRateLimitedAt(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetRateLimitedAt(*v)
	}
	return _u
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (_u *AccountUpdate) ClearRateLimitedAt() *AccountUpdate {
	_u.mutation.ClearRateLimitedAt()
	return _u
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (_u *AccountUpdate) SetRateLimitResetAt(v time.Time) *AccountUpdate {
	_u.mutation.SetRateLimitResetAt(v)
	return _u
}

// SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableRateLimitResetAt(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetRateLimitResetAt(*v)
	}
	return _u
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (_u *AccountUpdate) ClearRateLimitResetAt() *AccountUpdate {
	_u.mutation.ClearRateLimitResetAt()
	return _u
}

// SetOverloadUntil sets the "overload_until" field.
func (_u *AccountUpdate) SetOverloadUntil(v time.Time) *AccountUpdate {
	_u.mutation.SetOverloadUntil(v)
	return _u
}

// SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableOverloadUntil(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetOverloadUntil(*v)
	}
	return _u
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (_u *AccountUpdate) ClearOverloadUntil() *AccountUpdate {
	_u.mutation.ClearOverloadUntil()
	return _u
}

// SetSessionWindowStart sets the "session_window_start" field.
func (_u *AccountUpdate) SetSessionWindowStart(v time.Time) *AccountUpdate {
	_u.mutation.SetSessionWindowStart(v)
	return _u
}

// SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableSessionWindowStart(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetSessionWindowStart(*v)
	}
	return _u
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (_u *AccountUpdate) ClearSessionWindowStart() *AccountUpdate {
	_u.mutation.ClearSessionWindowStart()
	return _u
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (_u *AccountUpdate) SetSessionWindowEnd(v time.Time) *AccountUpdate {
	_u.mutation.SetSessionWindowEnd(v)
	return _u
}

// SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableSessionWindowEnd(v *time.Time) *AccountUpdate {
	if v != nil {
		_u.SetSessionWindowEnd(*v)
	}
	return _u
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (_u *AccountUpdate) ClearSessionWindowEnd() *AccountUpdate {
	_u.mutation.ClearSessionWindowEnd()
	return _u
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (_u *AccountUpdate) SetSessionWindowStatus(v string) *AccountUpdate {
	_u.mutation.SetSessionWindowStatus(v)
	return _u
}

// SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableSessionWindowStatus(v *string) *AccountUpdate {
	if v != nil {
		_u.SetSessionWindowStatus(*v)
	}
	return _u
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (_u *AccountUpdate) ClearSessionWindowStatus() *AccountUpdate {
	_u.mutation.ClearSessionWindowStatus()
	return _u
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (_u *AccountUpdate) AddGroupIDs(ids ...int64) *AccountUpdate {
	_u.mutation.AddGroupIDs(ids...)
	return _u
}

// AddGroups adds the "groups" edges to the Group entity.
func (_u *AccountUpdate) AddGroups(v ...*Group) *AccountUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddGroupIDs(ids...)
}

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

// ClearGroups clears all "groups" edges to the Group entity.
func (_u *AccountUpdate) ClearGroups() *AccountUpdate {
	_u.mutation.ClearGroups()
	return _u
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (_u *AccountUpdate) RemoveGroupIDs(ids ...int64) *AccountUpdate {
	_u.mutation.RemoveGroupIDs(ids...)
	return _u
}

// RemoveGroups removes "groups" edges to Group entities.
func (_u *AccountUpdate) RemoveGroups(v ...*Group) *AccountUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveGroupIDs(ids...)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *AccountUpdate) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := account.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Platform(); ok {
		if err := account.PlatformValidator(v); err != nil {
			return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.GetType(); ok {
		if err := account.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := account.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SessionWindowStatus(); ok {
		if err := account.SessionWindowStatusValidator(v); err != nil {
			return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
		}
	}
	return nil
}

func (_u *AccountUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.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.UpdatedAt(); ok {
		_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(account.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(account.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platform(); ok {
		_spec.SetField(account.FieldPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.GetType(); ok {
		_spec.SetField(account.FieldType, field.TypeString, value)
	}
	if value, ok := _u.mutation.Credentials(); ok {
		_spec.SetField(account.FieldCredentials, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.Extra(); ok {
		_spec.SetField(account.FieldExtra, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.ProxyID(); ok {
		_spec.SetField(account.FieldProxyID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedProxyID(); ok {
		_spec.AddField(account.FieldProxyID, field.TypeInt64, value)
	}
	if _u.mutation.ProxyIDCleared() {
		_spec.ClearField(account.FieldProxyID, field.TypeInt64)
	}
	if value, ok := _u.mutation.Concurrency(); ok {
		_spec.SetField(account.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedConcurrency(); ok {
		_spec.AddField(account.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(account.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(account.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(account.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(account.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(account.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.LastUsedAt(); ok {
		_spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
	}
	if _u.mutation.LastUsedAtCleared() {
		_spec.ClearField(account.FieldLastUsedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Schedulable(); ok {
		_spec.SetField(account.FieldSchedulable, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RateLimitedAt(); ok {
		_spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
	}
	if _u.mutation.RateLimitedAtCleared() {
		_spec.ClearField(account.FieldRateLimitedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.RateLimitResetAt(); ok {
		_spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
	}
	if _u.mutation.RateLimitResetAtCleared() {
		_spec.ClearField(account.FieldRateLimitResetAt, field.TypeTime)
	}
	if value, ok := _u.mutation.OverloadUntil(); ok {
		_spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
	}
	if _u.mutation.OverloadUntilCleared() {
		_spec.ClearField(account.FieldOverloadUntil, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowStart(); ok {
		_spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
	}
	if _u.mutation.SessionWindowStartCleared() {
		_spec.ClearField(account.FieldSessionWindowStart, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowEnd(); ok {
		_spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
	}
	if _u.mutation.SessionWindowEndCleared() {
		_spec.ClearField(account.FieldSessionWindowEnd, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowStatus(); ok {
		_spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
	}
	if _u.mutation.SessionWindowStatusCleared() {
		_spec.ClearField(account.FieldSessionWindowStatus, field.TypeString)
	}
	if _u.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// AccountUpdateOne is the builder for updating a single Account entity.
type AccountUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *AccountMutation
}

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

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

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

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

// SetName sets the "name" field.
func (_u *AccountUpdateOne) SetName(v string) *AccountUpdateOne {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableName(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetPlatform sets the "platform" field.
func (_u *AccountUpdateOne) SetPlatform(v string) *AccountUpdateOne {
	_u.mutation.SetPlatform(v)
	return _u
}

// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillablePlatform(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetPlatform(*v)
	}
	return _u
}

// SetType sets the "type" field.
func (_u *AccountUpdateOne) SetType(v string) *AccountUpdateOne {
	_u.mutation.SetType(v)
	return _u
}

// SetNillableType sets the "type" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableType(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetType(*v)
	}
	return _u
}

// SetCredentials sets the "credentials" field.
func (_u *AccountUpdateOne) SetCredentials(v map[string]interface{}) *AccountUpdateOne {
	_u.mutation.SetCredentials(v)
	return _u
}

// SetExtra sets the "extra" field.
func (_u *AccountUpdateOne) SetExtra(v map[string]interface{}) *AccountUpdateOne {
	_u.mutation.SetExtra(v)
	return _u
}

// SetProxyID sets the "proxy_id" field.
func (_u *AccountUpdateOne) SetProxyID(v int64) *AccountUpdateOne {
	_u.mutation.ResetProxyID()
	_u.mutation.SetProxyID(v)
	return _u
}

// SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableProxyID(v *int64) *AccountUpdateOne {
	if v != nil {
		_u.SetProxyID(*v)
	}
	return _u
}

// AddProxyID adds value to the "proxy_id" field.
func (_u *AccountUpdateOne) AddProxyID(v int64) *AccountUpdateOne {
	_u.mutation.AddProxyID(v)
	return _u
}

// ClearProxyID clears the value of the "proxy_id" field.
func (_u *AccountUpdateOne) ClearProxyID() *AccountUpdateOne {
	_u.mutation.ClearProxyID()
	return _u
}

// SetConcurrency sets the "concurrency" field.
func (_u *AccountUpdateOne) SetConcurrency(v int) *AccountUpdateOne {
	_u.mutation.ResetConcurrency()
	_u.mutation.SetConcurrency(v)
	return _u
}

// SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableConcurrency(v *int) *AccountUpdateOne {
	if v != nil {
		_u.SetConcurrency(*v)
	}
	return _u
}

// AddConcurrency adds value to the "concurrency" field.
func (_u *AccountUpdateOne) AddConcurrency(v int) *AccountUpdateOne {
	_u.mutation.AddConcurrency(v)
	return _u
}

// SetPriority sets the "priority" field.
func (_u *AccountUpdateOne) SetPriority(v int) *AccountUpdateOne {
	_u.mutation.ResetPriority()
	_u.mutation.SetPriority(v)
	return _u
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillablePriority(v *int) *AccountUpdateOne {
	if v != nil {
		_u.SetPriority(*v)
	}
	return _u
}

// AddPriority adds value to the "priority" field.
func (_u *AccountUpdateOne) AddPriority(v int) *AccountUpdateOne {
	_u.mutation.AddPriority(v)
	return _u
}

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

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

// SetErrorMessage sets the "error_message" field.
func (_u *AccountUpdateOne) SetErrorMessage(v string) *AccountUpdateOne {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableErrorMessage(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *AccountUpdateOne) ClearErrorMessage() *AccountUpdateOne {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetLastUsedAt sets the "last_used_at" field.
func (_u *AccountUpdateOne) SetLastUsedAt(v time.Time) *AccountUpdateOne {
	_u.mutation.SetLastUsedAt(v)
	return _u
}

// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableLastUsedAt(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetLastUsedAt(*v)
	}
	return _u
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (_u *AccountUpdateOne) ClearLastUsedAt() *AccountUpdateOne {
	_u.mutation.ClearLastUsedAt()
	return _u
}

// SetSchedulable sets the "schedulable" field.
func (_u *AccountUpdateOne) SetSchedulable(v bool) *AccountUpdateOne {
	_u.mutation.SetSchedulable(v)
	return _u
}

// SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableSchedulable(v *bool) *AccountUpdateOne {
	if v != nil {
		_u.SetSchedulable(*v)
	}
	return _u
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (_u *AccountUpdateOne) SetRateLimitedAt(v time.Time) *AccountUpdateOne {
	_u.mutation.SetRateLimitedAt(v)
	return _u
}

// SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableRateLimitedAt(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetRateLimitedAt(*v)
	}
	return _u
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (_u *AccountUpdateOne) ClearRateLimitedAt() *AccountUpdateOne {
	_u.mutation.ClearRateLimitedAt()
	return _u
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (_u *AccountUpdateOne) SetRateLimitResetAt(v time.Time) *AccountUpdateOne {
	_u.mutation.SetRateLimitResetAt(v)
	return _u
}

// SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableRateLimitResetAt(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetRateLimitResetAt(*v)
	}
	return _u
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (_u *AccountUpdateOne) ClearRateLimitResetAt() *AccountUpdateOne {
	_u.mutation.ClearRateLimitResetAt()
	return _u
}

// SetOverloadUntil sets the "overload_until" field.
func (_u *AccountUpdateOne) SetOverloadUntil(v time.Time) *AccountUpdateOne {
	_u.mutation.SetOverloadUntil(v)
	return _u
}

// SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableOverloadUntil(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetOverloadUntil(*v)
	}
	return _u
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (_u *AccountUpdateOne) ClearOverloadUntil() *AccountUpdateOne {
	_u.mutation.ClearOverloadUntil()
	return _u
}

// SetSessionWindowStart sets the "session_window_start" field.
func (_u *AccountUpdateOne) SetSessionWindowStart(v time.Time) *AccountUpdateOne {
	_u.mutation.SetSessionWindowStart(v)
	return _u
}

// SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableSessionWindowStart(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetSessionWindowStart(*v)
	}
	return _u
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (_u *AccountUpdateOne) ClearSessionWindowStart() *AccountUpdateOne {
	_u.mutation.ClearSessionWindowStart()
	return _u
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (_u *AccountUpdateOne) SetSessionWindowEnd(v time.Time) *AccountUpdateOne {
	_u.mutation.SetSessionWindowEnd(v)
	return _u
}

// SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableSessionWindowEnd(v *time.Time) *AccountUpdateOne {
	if v != nil {
		_u.SetSessionWindowEnd(*v)
	}
	return _u
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (_u *AccountUpdateOne) ClearSessionWindowEnd() *AccountUpdateOne {
	_u.mutation.ClearSessionWindowEnd()
	return _u
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (_u *AccountUpdateOne) SetSessionWindowStatus(v string) *AccountUpdateOne {
	_u.mutation.SetSessionWindowStatus(v)
	return _u
}

// SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableSessionWindowStatus(v *string) *AccountUpdateOne {
	if v != nil {
		_u.SetSessionWindowStatus(*v)
	}
	return _u
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (_u *AccountUpdateOne) ClearSessionWindowStatus() *AccountUpdateOne {
	_u.mutation.ClearSessionWindowStatus()
	return _u
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (_u *AccountUpdateOne) AddGroupIDs(ids ...int64) *AccountUpdateOne {
	_u.mutation.AddGroupIDs(ids...)
	return _u
}

// AddGroups adds the "groups" edges to the Group entity.
func (_u *AccountUpdateOne) AddGroups(v ...*Group) *AccountUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddGroupIDs(ids...)
}

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

// ClearGroups clears all "groups" edges to the Group entity.
func (_u *AccountUpdateOne) ClearGroups() *AccountUpdateOne {
	_u.mutation.ClearGroups()
	return _u
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (_u *AccountUpdateOne) RemoveGroupIDs(ids ...int64) *AccountUpdateOne {
	_u.mutation.RemoveGroupIDs(ids...)
	return _u
}

// RemoveGroups removes "groups" edges to Group entities.
func (_u *AccountUpdateOne) RemoveGroups(v ...*Group) *AccountUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveGroupIDs(ids...)
}

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

// Save executes the query and returns the updated Account entity.
func (_u *AccountUpdateOne) Save(ctx context.Context) (*Account, 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 *AccountUpdateOne) SaveX(ctx context.Context) *Account {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *AccountUpdateOne) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := account.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Platform(); ok {
		if err := account.PlatformValidator(v); err != nil {
			return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.GetType(); ok {
		if err := account.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := account.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SessionWindowStatus(); ok {
		if err := account.SessionWindowStatusValidator(v); err != nil {
			return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
		}
	}
	return nil
}

func (_u *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.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, account.FieldID)
		for _, f := range fields {
			if !account.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != account.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.UpdatedAt(); ok {
		_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(account.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(account.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platform(); ok {
		_spec.SetField(account.FieldPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.GetType(); ok {
		_spec.SetField(account.FieldType, field.TypeString, value)
	}
	if value, ok := _u.mutation.Credentials(); ok {
		_spec.SetField(account.FieldCredentials, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.Extra(); ok {
		_spec.SetField(account.FieldExtra, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.ProxyID(); ok {
		_spec.SetField(account.FieldProxyID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedProxyID(); ok {
		_spec.AddField(account.FieldProxyID, field.TypeInt64, value)
	}
	if _u.mutation.ProxyIDCleared() {
		_spec.ClearField(account.FieldProxyID, field.TypeInt64)
	}
	if value, ok := _u.mutation.Concurrency(); ok {
		_spec.SetField(account.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedConcurrency(); ok {
		_spec.AddField(account.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Priority(); ok {
		_spec.SetField(account.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedPriority(); ok {
		_spec.AddField(account.FieldPriority, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(account.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(account.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(account.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.LastUsedAt(); ok {
		_spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
	}
	if _u.mutation.LastUsedAtCleared() {
		_spec.ClearField(account.FieldLastUsedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Schedulable(); ok {
		_spec.SetField(account.FieldSchedulable, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RateLimitedAt(); ok {
		_spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
	}
	if _u.mutation.RateLimitedAtCleared() {
		_spec.ClearField(account.FieldRateLimitedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.RateLimitResetAt(); ok {
		_spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
	}
	if _u.mutation.RateLimitResetAtCleared() {
		_spec.ClearField(account.FieldRateLimitResetAt, field.TypeTime)
	}
	if value, ok := _u.mutation.OverloadUntil(); ok {
		_spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
	}
	if _u.mutation.OverloadUntilCleared() {
		_spec.ClearField(account.FieldOverloadUntil, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowStart(); ok {
		_spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
	}
	if _u.mutation.SessionWindowStartCleared() {
		_spec.ClearField(account.FieldSessionWindowStart, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowEnd(); ok {
		_spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
	}
	if _u.mutation.SessionWindowEndCleared() {
		_spec.ClearField(account.FieldSessionWindowEnd, field.TypeTime)
	}
	if value, ok := _u.mutation.SessionWindowStatus(); ok {
		_spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
	}
	if _u.mutation.SessionWindowStatusCleared() {
		_spec.ClearField(account.FieldSessionWindowStatus, field.TypeString)
	}
	if _u.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Account{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{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
