// 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"
	"github.com/Wei-Shaw/sub2api/ent/proxy"
	"github.com/Wei-Shaw/sub2api/ent/usagelog"
)

// 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
}

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

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

// ClearNotes clears the value of the "notes" field.
func (_u *AccountUpdate) ClearNotes() *AccountUpdate {
	_u.mutation.ClearNotes()
	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.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
}

// 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
}

// SetLoadFactor sets the "load_factor" field.
func (_u *AccountUpdate) SetLoadFactor(v int) *AccountUpdate {
	_u.mutation.ResetLoadFactor()
	_u.mutation.SetLoadFactor(v)
	return _u
}

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

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

// ClearLoadFactor clears the value of the "load_factor" field.
func (_u *AccountUpdate) ClearLoadFactor() *AccountUpdate {
	_u.mutation.ClearLoadFactor()
	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
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *AccountUpdate) SetRateMultiplier(v float64) *AccountUpdate {
	_u.mutation.ResetRateMultiplier()
	_u.mutation.SetRateMultiplier(v)
	return _u
}

// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableRateMultiplier(v *float64) *AccountUpdate {
	if v != nil {
		_u.SetRateMultiplier(*v)
	}
	return _u
}

// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *AccountUpdate) AddRateMultiplier(v float64) *AccountUpdate {
	_u.mutation.AddRateMultiplier(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
}

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

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

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

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

// SetNillableAutoPauseOnExpired sets the "auto_pause_on_expired" field if the given value is not nil.
func (_u *AccountUpdate) SetNillableAutoPauseOnExpired(v *bool) *AccountUpdate {
	if v != nil {
		_u.SetAutoPauseOnExpired(*v)
	}
	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
}

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

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

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

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

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

// ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
func (_u *AccountUpdate) ClearTempUnschedulableReason() *AccountUpdate {
	_u.mutation.ClearTempUnschedulableReason()
	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...)
}

// SetProxy sets the "proxy" edge to the Proxy entity.
func (_u *AccountUpdate) SetProxy(v *Proxy) *AccountUpdate {
	return _u.SetProxyID(v.ID)
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *AccountUpdate) AddUsageLogIDs(ids ...int64) *AccountUpdate {
	_u.mutation.AddUsageLogIDs(ids...)
	return _u
}

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *AccountUpdate) AddUsageLogs(v ...*UsageLog) *AccountUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(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...)
}

// ClearProxy clears the "proxy" edge to the Proxy entity.
func (_u *AccountUpdate) ClearProxy() *AccountUpdate {
	_u.mutation.ClearProxy()
	return _u
}

// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *AccountUpdate) ClearUsageLogs() *AccountUpdate {
	_u.mutation.ClearUsageLogs()
	return _u
}

// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *AccountUpdate) RemoveUsageLogIDs(ids ...int64) *AccountUpdate {
	_u.mutation.RemoveUsageLogIDs(ids...)
	return _u
}

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *AccountUpdate) RemoveUsageLogs(v ...*UsageLog) *AccountUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(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.Notes(); ok {
		_spec.SetField(account.FieldNotes, field.TypeString, value)
	}
	if _u.mutation.NotesCleared() {
		_spec.ClearField(account.FieldNotes, field.TypeString)
	}
	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.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.LoadFactor(); ok {
		_spec.SetField(account.FieldLoadFactor, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedLoadFactor(); ok {
		_spec.AddField(account.FieldLoadFactor, field.TypeInt, value)
	}
	if _u.mutation.LoadFactorCleared() {
		_spec.ClearField(account.FieldLoadFactor, field.TypeInt)
	}
	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.RateMultiplier(); ok {
		_spec.SetField(account.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(account.FieldRateMultiplier, field.TypeFloat64, 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.ExpiresAt(); ok {
		_spec.SetField(account.FieldExpiresAt, field.TypeTime, value)
	}
	if _u.mutation.ExpiresAtCleared() {
		_spec.ClearField(account.FieldExpiresAt, field.TypeTime)
	}
	if value, ok := _u.mutation.AutoPauseOnExpired(); ok {
		_spec.SetField(account.FieldAutoPauseOnExpired, field.TypeBool, value)
	}
	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.TempUnschedulableUntil(); ok {
		_spec.SetField(account.FieldTempUnschedulableUntil, field.TypeTime, value)
	}
	if _u.mutation.TempUnschedulableUntilCleared() {
		_spec.ClearField(account.FieldTempUnschedulableUntil, field.TypeTime)
	}
	if value, ok := _u.mutation.TempUnschedulableReason(); ok {
		_spec.SetField(account.FieldTempUnschedulableReason, field.TypeString, value)
	}
	if _u.mutation.TempUnschedulableReasonCleared() {
		_spec.ClearField(account.FieldTempUnschedulableReason, field.TypeString)
	}
	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 _u.mutation.ProxyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   account.ProxyTable,
			Columns: []string{account.ProxyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ProxyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   account.ProxyTable,
			Columns: []string{account.ProxyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_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
}

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

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

// ClearNotes clears the value of the "notes" field.
func (_u *AccountUpdateOne) ClearNotes() *AccountUpdateOne {
	_u.mutation.ClearNotes()
	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.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
}

// 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
}

// SetLoadFactor sets the "load_factor" field.
func (_u *AccountUpdateOne) SetLoadFactor(v int) *AccountUpdateOne {
	_u.mutation.ResetLoadFactor()
	_u.mutation.SetLoadFactor(v)
	return _u
}

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

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

// ClearLoadFactor clears the value of the "load_factor" field.
func (_u *AccountUpdateOne) ClearLoadFactor() *AccountUpdateOne {
	_u.mutation.ClearLoadFactor()
	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
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *AccountUpdateOne) SetRateMultiplier(v float64) *AccountUpdateOne {
	_u.mutation.ResetRateMultiplier()
	_u.mutation.SetRateMultiplier(v)
	return _u
}

// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableRateMultiplier(v *float64) *AccountUpdateOne {
	if v != nil {
		_u.SetRateMultiplier(*v)
	}
	return _u
}

// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *AccountUpdateOne) AddRateMultiplier(v float64) *AccountUpdateOne {
	_u.mutation.AddRateMultiplier(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
}

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

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

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

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

// SetNillableAutoPauseOnExpired sets the "auto_pause_on_expired" field if the given value is not nil.
func (_u *AccountUpdateOne) SetNillableAutoPauseOnExpired(v *bool) *AccountUpdateOne {
	if v != nil {
		_u.SetAutoPauseOnExpired(*v)
	}
	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
}

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

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

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

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

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

// ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
func (_u *AccountUpdateOne) ClearTempUnschedulableReason() *AccountUpdateOne {
	_u.mutation.ClearTempUnschedulableReason()
	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...)
}

// SetProxy sets the "proxy" edge to the Proxy entity.
func (_u *AccountUpdateOne) SetProxy(v *Proxy) *AccountUpdateOne {
	return _u.SetProxyID(v.ID)
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *AccountUpdateOne) AddUsageLogIDs(ids ...int64) *AccountUpdateOne {
	_u.mutation.AddUsageLogIDs(ids...)
	return _u
}

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *AccountUpdateOne) AddUsageLogs(v ...*UsageLog) *AccountUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(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...)
}

// ClearProxy clears the "proxy" edge to the Proxy entity.
func (_u *AccountUpdateOne) ClearProxy() *AccountUpdateOne {
	_u.mutation.ClearProxy()
	return _u
}

// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *AccountUpdateOne) ClearUsageLogs() *AccountUpdateOne {
	_u.mutation.ClearUsageLogs()
	return _u
}

// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *AccountUpdateOne) RemoveUsageLogIDs(ids ...int64) *AccountUpdateOne {
	_u.mutation.RemoveUsageLogIDs(ids...)
	return _u
}

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *AccountUpdateOne) RemoveUsageLogs(v ...*UsageLog) *AccountUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(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.Notes(); ok {
		_spec.SetField(account.FieldNotes, field.TypeString, value)
	}
	if _u.mutation.NotesCleared() {
		_spec.ClearField(account.FieldNotes, field.TypeString)
	}
	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.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.LoadFactor(); ok {
		_spec.SetField(account.FieldLoadFactor, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedLoadFactor(); ok {
		_spec.AddField(account.FieldLoadFactor, field.TypeInt, value)
	}
	if _u.mutation.LoadFactorCleared() {
		_spec.ClearField(account.FieldLoadFactor, field.TypeInt)
	}
	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.RateMultiplier(); ok {
		_spec.SetField(account.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(account.FieldRateMultiplier, field.TypeFloat64, 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.ExpiresAt(); ok {
		_spec.SetField(account.FieldExpiresAt, field.TypeTime, value)
	}
	if _u.mutation.ExpiresAtCleared() {
		_spec.ClearField(account.FieldExpiresAt, field.TypeTime)
	}
	if value, ok := _u.mutation.AutoPauseOnExpired(); ok {
		_spec.SetField(account.FieldAutoPauseOnExpired, field.TypeBool, value)
	}
	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.TempUnschedulableUntil(); ok {
		_spec.SetField(account.FieldTempUnschedulableUntil, field.TypeTime, value)
	}
	if _u.mutation.TempUnschedulableUntilCleared() {
		_spec.ClearField(account.FieldTempUnschedulableUntil, field.TypeTime)
	}
	if value, ok := _u.mutation.TempUnschedulableReason(); ok {
		_spec.SetField(account.FieldTempUnschedulableReason, field.TypeString, value)
	}
	if _u.mutation.TempUnschedulableReasonCleared() {
		_spec.ClearField(account.FieldTempUnschedulableReason, field.TypeString)
	}
	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 _u.mutation.ProxyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   account.ProxyTable,
			Columns: []string{account.ProxyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.ProxyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   account.ProxyTable,
			Columns: []string{account.ProxyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.UsageLogsTable,
			Columns: []string{account.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_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
}
