// 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/announcementread"
	"github.com/Wei-Shaw/sub2api/ent/apikey"
	"github.com/Wei-Shaw/sub2api/ent/authidentity"
	"github.com/Wei-Shaw/sub2api/ent/group"
	"github.com/Wei-Shaw/sub2api/ent/paymentorder"
	"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
	"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
	"github.com/Wei-Shaw/sub2api/ent/redeemcode"
	"github.com/Wei-Shaw/sub2api/ent/usagelog"
	"github.com/Wei-Shaw/sub2api/ent/user"
	"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
	"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)

// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
	config
	hooks    []Hook
	mutation *UserMutation
}

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

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

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

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

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

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

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

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

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

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

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

// SetBalance sets the "balance" field.
func (_u *UserUpdate) SetBalance(v float64) *UserUpdate {
	_u.mutation.ResetBalance()
	_u.mutation.SetBalance(v)
	return _u
}

// SetNillableBalance sets the "balance" field if the given value is not nil.
func (_u *UserUpdate) SetNillableBalance(v *float64) *UserUpdate {
	if v != nil {
		_u.SetBalance(*v)
	}
	return _u
}

// AddBalance adds value to the "balance" field.
func (_u *UserUpdate) AddBalance(v float64) *UserUpdate {
	_u.mutation.AddBalance(v)
	return _u
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetTotpEnabled sets the "totp_enabled" field.
func (_u *UserUpdate) SetTotpEnabled(v bool) *UserUpdate {
	_u.mutation.SetTotpEnabled(v)
	return _u
}

// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func (_u *UserUpdate) SetNillableTotpEnabled(v *bool) *UserUpdate {
	if v != nil {
		_u.SetTotpEnabled(*v)
	}
	return _u
}

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

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

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

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

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

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

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

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

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

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

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

// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
func (_u *UserUpdate) SetBalanceNotifyEnabled(v bool) *UserUpdate {
	_u.mutation.SetBalanceNotifyEnabled(v)
	return _u
}

// SetNillableBalanceNotifyEnabled sets the "balance_notify_enabled" field if the given value is not nil.
func (_u *UserUpdate) SetNillableBalanceNotifyEnabled(v *bool) *UserUpdate {
	if v != nil {
		_u.SetBalanceNotifyEnabled(*v)
	}
	return _u
}

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

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

// SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
func (_u *UserUpdate) SetBalanceNotifyThreshold(v float64) *UserUpdate {
	_u.mutation.ResetBalanceNotifyThreshold()
	_u.mutation.SetBalanceNotifyThreshold(v)
	return _u
}

// SetNillableBalanceNotifyThreshold sets the "balance_notify_threshold" field if the given value is not nil.
func (_u *UserUpdate) SetNillableBalanceNotifyThreshold(v *float64) *UserUpdate {
	if v != nil {
		_u.SetBalanceNotifyThreshold(*v)
	}
	return _u
}

// AddBalanceNotifyThreshold adds value to the "balance_notify_threshold" field.
func (_u *UserUpdate) AddBalanceNotifyThreshold(v float64) *UserUpdate {
	_u.mutation.AddBalanceNotifyThreshold(v)
	return _u
}

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

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

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

// SetTotalRecharged sets the "total_recharged" field.
func (_u *UserUpdate) SetTotalRecharged(v float64) *UserUpdate {
	_u.mutation.ResetTotalRecharged()
	_u.mutation.SetTotalRecharged(v)
	return _u
}

// SetNillableTotalRecharged sets the "total_recharged" field if the given value is not nil.
func (_u *UserUpdate) SetNillableTotalRecharged(v *float64) *UserUpdate {
	if v != nil {
		_u.SetTotalRecharged(*v)
	}
	return _u
}

// AddTotalRecharged adds value to the "total_recharged" field.
func (_u *UserUpdate) AddTotalRecharged(v float64) *UserUpdate {
	_u.mutation.AddTotalRecharged(v)
	return _u
}

// SetRpmLimit sets the "rpm_limit" field.
func (_u *UserUpdate) SetRpmLimit(v int) *UserUpdate {
	_u.mutation.ResetRpmLimit()
	_u.mutation.SetRpmLimit(v)
	return _u
}

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

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

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *UserUpdate) AddAPIKeyIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAPIKeyIDs(ids...)
	return _u
}

// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
func (_u *UserUpdate) AddAPIKeys(v ...*APIKey) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAPIKeyIDs(ids...)
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
func (_u *UserUpdate) AddRedeemCodeIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddRedeemCodeIDs(ids...)
	return _u
}

// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
func (_u *UserUpdate) AddRedeemCodes(v ...*RedeemCode) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddRedeemCodeIDs(ids...)
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
func (_u *UserUpdate) AddSubscriptionIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddSubscriptionIDs(ids...)
	return _u
}

// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdate) AddSubscriptions(v ...*UserSubscription) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubscriptionIDs(ids...)
}

// AddAssignedSubscriptionIDs adds the "assigned_subscriptions" edge to the UserSubscription entity by IDs.
func (_u *UserUpdate) AddAssignedSubscriptionIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAssignedSubscriptionIDs(ids...)
	return _u
}

// AddAssignedSubscriptions adds the "assigned_subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdate) AddAssignedSubscriptions(v ...*UserSubscription) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAssignedSubscriptionIDs(ids...)
}

// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func (_u *UserUpdate) AddAnnouncementReadIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAnnouncementReadIDs(ids...)
	return _u
}

// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
func (_u *UserUpdate) AddAnnouncementReads(v ...*AnnouncementRead) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAnnouncementReadIDs(ids...)
}

// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
func (_u *UserUpdate) AddAllowedGroupIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAllowedGroupIDs(ids...)
	return _u
}

// AddAllowedGroups adds the "allowed_groups" edges to the Group entity.
func (_u *UserUpdate) AddAllowedGroups(v ...*Group) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAllowedGroupIDs(ids...)
}

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

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdate) AddUsageLogs(v ...*UsageLog) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(ids...)
}

// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
func (_u *UserUpdate) AddAttributeValueIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAttributeValueIDs(ids...)
	return _u
}

// AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
func (_u *UserUpdate) AddAttributeValues(v ...*UserAttributeValue) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAttributeValueIDs(ids...)
}

// AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
func (_u *UserUpdate) AddPromoCodeUsageIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddPromoCodeUsageIDs(ids...)
	return _u
}

// AddPromoCodeUsages adds the "promo_code_usages" edges to the PromoCodeUsage entity.
func (_u *UserUpdate) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPromoCodeUsageIDs(ids...)
}

// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
func (_u *UserUpdate) AddPaymentOrderIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddPaymentOrderIDs(ids...)
	return _u
}

// AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
func (_u *UserUpdate) AddPaymentOrders(v ...*PaymentOrder) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPaymentOrderIDs(ids...)
}

// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
func (_u *UserUpdate) AddAuthIdentityIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddAuthIdentityIDs(ids...)
	return _u
}

// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
func (_u *UserUpdate) AddAuthIdentities(v ...*AuthIdentity) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAuthIdentityIDs(ids...)
}

// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
func (_u *UserUpdate) AddPendingAuthSessionIDs(ids ...int64) *UserUpdate {
	_u.mutation.AddPendingAuthSessionIDs(ids...)
	return _u
}

// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
func (_u *UserUpdate) AddPendingAuthSessions(v ...*PendingAuthSession) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPendingAuthSessionIDs(ids...)
}

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

// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
func (_u *UserUpdate) ClearAPIKeys() *UserUpdate {
	_u.mutation.ClearAPIKeys()
	return _u
}

// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
func (_u *UserUpdate) RemoveAPIKeyIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAPIKeyIDs(ids...)
	return _u
}

// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
func (_u *UserUpdate) RemoveAPIKeys(v ...*APIKey) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAPIKeyIDs(ids...)
}

// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
func (_u *UserUpdate) ClearRedeemCodes() *UserUpdate {
	_u.mutation.ClearRedeemCodes()
	return _u
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
func (_u *UserUpdate) RemoveRedeemCodeIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveRedeemCodeIDs(ids...)
	return _u
}

// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
func (_u *UserUpdate) RemoveRedeemCodes(v ...*RedeemCode) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveRedeemCodeIDs(ids...)
}

// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdate) ClearSubscriptions() *UserUpdate {
	_u.mutation.ClearSubscriptions()
	return _u
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
func (_u *UserUpdate) RemoveSubscriptionIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveSubscriptionIDs(ids...)
	return _u
}

// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
func (_u *UserUpdate) RemoveSubscriptions(v ...*UserSubscription) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubscriptionIDs(ids...)
}

// ClearAssignedSubscriptions clears all "assigned_subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdate) ClearAssignedSubscriptions() *UserUpdate {
	_u.mutation.ClearAssignedSubscriptions()
	return _u
}

// RemoveAssignedSubscriptionIDs removes the "assigned_subscriptions" edge to UserSubscription entities by IDs.
func (_u *UserUpdate) RemoveAssignedSubscriptionIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAssignedSubscriptionIDs(ids...)
	return _u
}

// RemoveAssignedSubscriptions removes "assigned_subscriptions" edges to UserSubscription entities.
func (_u *UserUpdate) RemoveAssignedSubscriptions(v ...*UserSubscription) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAssignedSubscriptionIDs(ids...)
}

// ClearAnnouncementReads clears all "announcement_reads" edges to the AnnouncementRead entity.
func (_u *UserUpdate) ClearAnnouncementReads() *UserUpdate {
	_u.mutation.ClearAnnouncementReads()
	return _u
}

// RemoveAnnouncementReadIDs removes the "announcement_reads" edge to AnnouncementRead entities by IDs.
func (_u *UserUpdate) RemoveAnnouncementReadIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAnnouncementReadIDs(ids...)
	return _u
}

// RemoveAnnouncementReads removes "announcement_reads" edges to AnnouncementRead entities.
func (_u *UserUpdate) RemoveAnnouncementReads(v ...*AnnouncementRead) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAnnouncementReadIDs(ids...)
}

// ClearAllowedGroups clears all "allowed_groups" edges to the Group entity.
func (_u *UserUpdate) ClearAllowedGroups() *UserUpdate {
	_u.mutation.ClearAllowedGroups()
	return _u
}

// RemoveAllowedGroupIDs removes the "allowed_groups" edge to Group entities by IDs.
func (_u *UserUpdate) RemoveAllowedGroupIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAllowedGroupIDs(ids...)
	return _u
}

// RemoveAllowedGroups removes "allowed_groups" edges to Group entities.
func (_u *UserUpdate) RemoveAllowedGroups(v ...*Group) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAllowedGroupIDs(ids...)
}

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

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

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *UserUpdate) RemoveUsageLogs(v ...*UsageLog) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(ids...)
}

// ClearAttributeValues clears all "attribute_values" edges to the UserAttributeValue entity.
func (_u *UserUpdate) ClearAttributeValues() *UserUpdate {
	_u.mutation.ClearAttributeValues()
	return _u
}

// RemoveAttributeValueIDs removes the "attribute_values" edge to UserAttributeValue entities by IDs.
func (_u *UserUpdate) RemoveAttributeValueIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAttributeValueIDs(ids...)
	return _u
}

// RemoveAttributeValues removes "attribute_values" edges to UserAttributeValue entities.
func (_u *UserUpdate) RemoveAttributeValues(v ...*UserAttributeValue) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAttributeValueIDs(ids...)
}

// ClearPromoCodeUsages clears all "promo_code_usages" edges to the PromoCodeUsage entity.
func (_u *UserUpdate) ClearPromoCodeUsages() *UserUpdate {
	_u.mutation.ClearPromoCodeUsages()
	return _u
}

// RemovePromoCodeUsageIDs removes the "promo_code_usages" edge to PromoCodeUsage entities by IDs.
func (_u *UserUpdate) RemovePromoCodeUsageIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemovePromoCodeUsageIDs(ids...)
	return _u
}

// RemovePromoCodeUsages removes "promo_code_usages" edges to PromoCodeUsage entities.
func (_u *UserUpdate) RemovePromoCodeUsages(v ...*PromoCodeUsage) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePromoCodeUsageIDs(ids...)
}

// ClearPaymentOrders clears all "payment_orders" edges to the PaymentOrder entity.
func (_u *UserUpdate) ClearPaymentOrders() *UserUpdate {
	_u.mutation.ClearPaymentOrders()
	return _u
}

// RemovePaymentOrderIDs removes the "payment_orders" edge to PaymentOrder entities by IDs.
func (_u *UserUpdate) RemovePaymentOrderIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemovePaymentOrderIDs(ids...)
	return _u
}

// RemovePaymentOrders removes "payment_orders" edges to PaymentOrder entities.
func (_u *UserUpdate) RemovePaymentOrders(v ...*PaymentOrder) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePaymentOrderIDs(ids...)
}

// ClearAuthIdentities clears all "auth_identities" edges to the AuthIdentity entity.
func (_u *UserUpdate) ClearAuthIdentities() *UserUpdate {
	_u.mutation.ClearAuthIdentities()
	return _u
}

// RemoveAuthIdentityIDs removes the "auth_identities" edge to AuthIdentity entities by IDs.
func (_u *UserUpdate) RemoveAuthIdentityIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemoveAuthIdentityIDs(ids...)
	return _u
}

// RemoveAuthIdentities removes "auth_identities" edges to AuthIdentity entities.
func (_u *UserUpdate) RemoveAuthIdentities(v ...*AuthIdentity) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAuthIdentityIDs(ids...)
}

// ClearPendingAuthSessions clears all "pending_auth_sessions" edges to the PendingAuthSession entity.
func (_u *UserUpdate) ClearPendingAuthSessions() *UserUpdate {
	_u.mutation.ClearPendingAuthSessions()
	return _u
}

// RemovePendingAuthSessionIDs removes the "pending_auth_sessions" edge to PendingAuthSession entities by IDs.
func (_u *UserUpdate) RemovePendingAuthSessionIDs(ids ...int64) *UserUpdate {
	_u.mutation.RemovePendingAuthSessionIDs(ids...)
	return _u
}

// RemovePendingAuthSessions removes "pending_auth_sessions" edges to PendingAuthSession entities.
func (_u *UserUpdate) RemovePendingAuthSessions(v ...*PendingAuthSession) *UserUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePendingAuthSessionIDs(ids...)
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (_u *UserUpdate) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if user.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized user.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := user.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *UserUpdate) check() error {
	if v, ok := _u.mutation.Email(); ok {
		if err := user.EmailValidator(v); err != nil {
			return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PasswordHash(); ok {
		if err := user.PasswordHashValidator(v); err != nil {
			return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Role(); ok {
		if err := user.RoleValidator(v); err != nil {
			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := user.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Username(); ok {
		if err := user.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SignupSource(); ok {
		if err := user.SignupSourceValidator(v); err != nil {
			return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
		}
	}
	return nil
}

func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.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(user.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Role(); ok {
		_spec.SetField(user.FieldRole, field.TypeString, value)
	}
	if value, ok := _u.mutation.Balance(); ok {
		_spec.SetField(user.FieldBalance, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBalance(); ok {
		_spec.AddField(user.FieldBalance, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.Concurrency(); ok {
		_spec.SetField(user.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedConcurrency(); ok {
		_spec.AddField(user.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(user.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Username(); ok {
		_spec.SetField(user.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.Notes(); ok {
		_spec.SetField(user.FieldNotes, field.TypeString, value)
	}
	if value, ok := _u.mutation.TotpSecretEncrypted(); ok {
		_spec.SetField(user.FieldTotpSecretEncrypted, field.TypeString, value)
	}
	if _u.mutation.TotpSecretEncryptedCleared() {
		_spec.ClearField(user.FieldTotpSecretEncrypted, field.TypeString)
	}
	if value, ok := _u.mutation.TotpEnabled(); ok {
		_spec.SetField(user.FieldTotpEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.TotpEnabledAt(); ok {
		_spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
	}
	if _u.mutation.TotpEnabledAtCleared() {
		_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
	}
	if value, ok := _u.mutation.SignupSource(); ok {
		_spec.SetField(user.FieldSignupSource, field.TypeString, value)
	}
	if value, ok := _u.mutation.LastLoginAt(); ok {
		_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
	}
	if _u.mutation.LastLoginAtCleared() {
		_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := _u.mutation.LastActiveAt(); ok {
		_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
	}
	if _u.mutation.LastActiveAtCleared() {
		_spec.ClearField(user.FieldLastActiveAt, field.TypeTime)
	}
	if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
		_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.BalanceNotifyThresholdType(); ok {
		_spec.SetField(user.FieldBalanceNotifyThresholdType, field.TypeString, value)
	}
	if value, ok := _u.mutation.BalanceNotifyThreshold(); ok {
		_spec.SetField(user.FieldBalanceNotifyThreshold, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBalanceNotifyThreshold(); ok {
		_spec.AddField(user.FieldBalanceNotifyThreshold, field.TypeFloat64, value)
	}
	if _u.mutation.BalanceNotifyThresholdCleared() {
		_spec.ClearField(user.FieldBalanceNotifyThreshold, field.TypeFloat64)
	}
	if value, ok := _u.mutation.BalanceNotifyExtraEmails(); ok {
		_spec.SetField(user.FieldBalanceNotifyExtraEmails, field.TypeString, value)
	}
	if value, ok := _u.mutation.TotalRecharged(); ok {
		_spec.SetField(user.FieldTotalRecharged, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedTotalRecharged(); ok {
		_spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RpmLimit(); ok {
		_spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedRpmLimit(); ok {
		_spec.AddField(user.FieldRpmLimit, field.TypeInt, value)
	}
	if _u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.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.APIKeysIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.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.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.RedeemCodesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.SubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AssignedSubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAssignedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.AssignedSubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AssignedSubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AnnouncementReadsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAnnouncementReadsIDs(); len(nodes) > 0 && !_u.mutation.AnnouncementReadsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.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.AnnouncementReadsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.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.AllowedGroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_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.RemovedAllowedGroupsIDs(); len(nodes) > 0 && !_u.mutation.AllowedGroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			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 := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_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.AllowedGroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			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 := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.UsageLogsTable,
			Columns: []string{user.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:   user.UsageLogsTable,
			Columns: []string{user.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:   user.UsageLogsTable,
			Columns: []string{user.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 _u.mutation.AttributeValuesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAttributeValuesIDs(); len(nodes) > 0 && !_u.mutation.AttributeValuesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.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.AttributeValuesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.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.PromoCodeUsagesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPromoCodeUsagesIDs(); len(nodes) > 0 && !_u.mutation.PromoCodeUsagesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.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.PromoCodeUsagesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.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.PaymentOrdersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPaymentOrdersIDs(); len(nodes) > 0 && !_u.mutation.PaymentOrdersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.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.PaymentOrdersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.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.AuthIdentitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAuthIdentitiesIDs(); len(nodes) > 0 && !_u.mutation.AuthIdentitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.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.AuthIdentitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.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.PendingAuthSessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPendingAuthSessionsIDs(); len(nodes) > 0 && !_u.mutation.PendingAuthSessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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.PendingAuthSessionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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{user.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

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

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

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

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

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

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

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

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

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

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

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

// SetBalance sets the "balance" field.
func (_u *UserUpdateOne) SetBalance(v float64) *UserUpdateOne {
	_u.mutation.ResetBalance()
	_u.mutation.SetBalance(v)
	return _u
}

// SetNillableBalance sets the "balance" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableBalance(v *float64) *UserUpdateOne {
	if v != nil {
		_u.SetBalance(*v)
	}
	return _u
}

// AddBalance adds value to the "balance" field.
func (_u *UserUpdateOne) AddBalance(v float64) *UserUpdateOne {
	_u.mutation.AddBalance(v)
	return _u
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetTotpEnabled sets the "totp_enabled" field.
func (_u *UserUpdateOne) SetTotpEnabled(v bool) *UserUpdateOne {
	_u.mutation.SetTotpEnabled(v)
	return _u
}

// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableTotpEnabled(v *bool) *UserUpdateOne {
	if v != nil {
		_u.SetTotpEnabled(*v)
	}
	return _u
}

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

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

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

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

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

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

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

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

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

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

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

// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
func (_u *UserUpdateOne) SetBalanceNotifyEnabled(v bool) *UserUpdateOne {
	_u.mutation.SetBalanceNotifyEnabled(v)
	return _u
}

// SetNillableBalanceNotifyEnabled sets the "balance_notify_enabled" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableBalanceNotifyEnabled(v *bool) *UserUpdateOne {
	if v != nil {
		_u.SetBalanceNotifyEnabled(*v)
	}
	return _u
}

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

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

// SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
func (_u *UserUpdateOne) SetBalanceNotifyThreshold(v float64) *UserUpdateOne {
	_u.mutation.ResetBalanceNotifyThreshold()
	_u.mutation.SetBalanceNotifyThreshold(v)
	return _u
}

// SetNillableBalanceNotifyThreshold sets the "balance_notify_threshold" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableBalanceNotifyThreshold(v *float64) *UserUpdateOne {
	if v != nil {
		_u.SetBalanceNotifyThreshold(*v)
	}
	return _u
}

// AddBalanceNotifyThreshold adds value to the "balance_notify_threshold" field.
func (_u *UserUpdateOne) AddBalanceNotifyThreshold(v float64) *UserUpdateOne {
	_u.mutation.AddBalanceNotifyThreshold(v)
	return _u
}

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

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

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

// SetTotalRecharged sets the "total_recharged" field.
func (_u *UserUpdateOne) SetTotalRecharged(v float64) *UserUpdateOne {
	_u.mutation.ResetTotalRecharged()
	_u.mutation.SetTotalRecharged(v)
	return _u
}

// SetNillableTotalRecharged sets the "total_recharged" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableTotalRecharged(v *float64) *UserUpdateOne {
	if v != nil {
		_u.SetTotalRecharged(*v)
	}
	return _u
}

// AddTotalRecharged adds value to the "total_recharged" field.
func (_u *UserUpdateOne) AddTotalRecharged(v float64) *UserUpdateOne {
	_u.mutation.AddTotalRecharged(v)
	return _u
}

// SetRpmLimit sets the "rpm_limit" field.
func (_u *UserUpdateOne) SetRpmLimit(v int) *UserUpdateOne {
	_u.mutation.ResetRpmLimit()
	_u.mutation.SetRpmLimit(v)
	return _u
}

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

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

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *UserUpdateOne) AddAPIKeyIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAPIKeyIDs(ids...)
	return _u
}

// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
func (_u *UserUpdateOne) AddAPIKeys(v ...*APIKey) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAPIKeyIDs(ids...)
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
func (_u *UserUpdateOne) AddRedeemCodeIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddRedeemCodeIDs(ids...)
	return _u
}

// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
func (_u *UserUpdateOne) AddRedeemCodes(v ...*RedeemCode) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddRedeemCodeIDs(ids...)
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
func (_u *UserUpdateOne) AddSubscriptionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddSubscriptionIDs(ids...)
	return _u
}

// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdateOne) AddSubscriptions(v ...*UserSubscription) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubscriptionIDs(ids...)
}

// AddAssignedSubscriptionIDs adds the "assigned_subscriptions" edge to the UserSubscription entity by IDs.
func (_u *UserUpdateOne) AddAssignedSubscriptionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAssignedSubscriptionIDs(ids...)
	return _u
}

// AddAssignedSubscriptions adds the "assigned_subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdateOne) AddAssignedSubscriptions(v ...*UserSubscription) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAssignedSubscriptionIDs(ids...)
}

// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func (_u *UserUpdateOne) AddAnnouncementReadIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAnnouncementReadIDs(ids...)
	return _u
}

// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
func (_u *UserUpdateOne) AddAnnouncementReads(v ...*AnnouncementRead) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAnnouncementReadIDs(ids...)
}

// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
func (_u *UserUpdateOne) AddAllowedGroupIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAllowedGroupIDs(ids...)
	return _u
}

// AddAllowedGroups adds the "allowed_groups" edges to the Group entity.
func (_u *UserUpdateOne) AddAllowedGroups(v ...*Group) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAllowedGroupIDs(ids...)
}

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

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdateOne) AddUsageLogs(v ...*UsageLog) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(ids...)
}

// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
func (_u *UserUpdateOne) AddAttributeValueIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAttributeValueIDs(ids...)
	return _u
}

// AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
func (_u *UserUpdateOne) AddAttributeValues(v ...*UserAttributeValue) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAttributeValueIDs(ids...)
}

// AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
func (_u *UserUpdateOne) AddPromoCodeUsageIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddPromoCodeUsageIDs(ids...)
	return _u
}

// AddPromoCodeUsages adds the "promo_code_usages" edges to the PromoCodeUsage entity.
func (_u *UserUpdateOne) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPromoCodeUsageIDs(ids...)
}

// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
func (_u *UserUpdateOne) AddPaymentOrderIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddPaymentOrderIDs(ids...)
	return _u
}

// AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
func (_u *UserUpdateOne) AddPaymentOrders(v ...*PaymentOrder) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPaymentOrderIDs(ids...)
}

// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
func (_u *UserUpdateOne) AddAuthIdentityIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddAuthIdentityIDs(ids...)
	return _u
}

// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
func (_u *UserUpdateOne) AddAuthIdentities(v ...*AuthIdentity) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAuthIdentityIDs(ids...)
}

// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
func (_u *UserUpdateOne) AddPendingAuthSessionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.AddPendingAuthSessionIDs(ids...)
	return _u
}

// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
func (_u *UserUpdateOne) AddPendingAuthSessions(v ...*PendingAuthSession) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddPendingAuthSessionIDs(ids...)
}

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

// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
func (_u *UserUpdateOne) ClearAPIKeys() *UserUpdateOne {
	_u.mutation.ClearAPIKeys()
	return _u
}

// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
func (_u *UserUpdateOne) RemoveAPIKeyIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAPIKeyIDs(ids...)
	return _u
}

// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
func (_u *UserUpdateOne) RemoveAPIKeys(v ...*APIKey) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAPIKeyIDs(ids...)
}

// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
func (_u *UserUpdateOne) ClearRedeemCodes() *UserUpdateOne {
	_u.mutation.ClearRedeemCodes()
	return _u
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
func (_u *UserUpdateOne) RemoveRedeemCodeIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveRedeemCodeIDs(ids...)
	return _u
}

// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
func (_u *UserUpdateOne) RemoveRedeemCodes(v ...*RedeemCode) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveRedeemCodeIDs(ids...)
}

// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdateOne) ClearSubscriptions() *UserUpdateOne {
	_u.mutation.ClearSubscriptions()
	return _u
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
func (_u *UserUpdateOne) RemoveSubscriptionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveSubscriptionIDs(ids...)
	return _u
}

// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
func (_u *UserUpdateOne) RemoveSubscriptions(v ...*UserSubscription) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubscriptionIDs(ids...)
}

// ClearAssignedSubscriptions clears all "assigned_subscriptions" edges to the UserSubscription entity.
func (_u *UserUpdateOne) ClearAssignedSubscriptions() *UserUpdateOne {
	_u.mutation.ClearAssignedSubscriptions()
	return _u
}

// RemoveAssignedSubscriptionIDs removes the "assigned_subscriptions" edge to UserSubscription entities by IDs.
func (_u *UserUpdateOne) RemoveAssignedSubscriptionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAssignedSubscriptionIDs(ids...)
	return _u
}

// RemoveAssignedSubscriptions removes "assigned_subscriptions" edges to UserSubscription entities.
func (_u *UserUpdateOne) RemoveAssignedSubscriptions(v ...*UserSubscription) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAssignedSubscriptionIDs(ids...)
}

// ClearAnnouncementReads clears all "announcement_reads" edges to the AnnouncementRead entity.
func (_u *UserUpdateOne) ClearAnnouncementReads() *UserUpdateOne {
	_u.mutation.ClearAnnouncementReads()
	return _u
}

// RemoveAnnouncementReadIDs removes the "announcement_reads" edge to AnnouncementRead entities by IDs.
func (_u *UserUpdateOne) RemoveAnnouncementReadIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAnnouncementReadIDs(ids...)
	return _u
}

// RemoveAnnouncementReads removes "announcement_reads" edges to AnnouncementRead entities.
func (_u *UserUpdateOne) RemoveAnnouncementReads(v ...*AnnouncementRead) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAnnouncementReadIDs(ids...)
}

// ClearAllowedGroups clears all "allowed_groups" edges to the Group entity.
func (_u *UserUpdateOne) ClearAllowedGroups() *UserUpdateOne {
	_u.mutation.ClearAllowedGroups()
	return _u
}

// RemoveAllowedGroupIDs removes the "allowed_groups" edge to Group entities by IDs.
func (_u *UserUpdateOne) RemoveAllowedGroupIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAllowedGroupIDs(ids...)
	return _u
}

// RemoveAllowedGroups removes "allowed_groups" edges to Group entities.
func (_u *UserUpdateOne) RemoveAllowedGroups(v ...*Group) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAllowedGroupIDs(ids...)
}

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

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

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *UserUpdateOne) RemoveUsageLogs(v ...*UsageLog) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(ids...)
}

// ClearAttributeValues clears all "attribute_values" edges to the UserAttributeValue entity.
func (_u *UserUpdateOne) ClearAttributeValues() *UserUpdateOne {
	_u.mutation.ClearAttributeValues()
	return _u
}

// RemoveAttributeValueIDs removes the "attribute_values" edge to UserAttributeValue entities by IDs.
func (_u *UserUpdateOne) RemoveAttributeValueIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAttributeValueIDs(ids...)
	return _u
}

// RemoveAttributeValues removes "attribute_values" edges to UserAttributeValue entities.
func (_u *UserUpdateOne) RemoveAttributeValues(v ...*UserAttributeValue) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAttributeValueIDs(ids...)
}

// ClearPromoCodeUsages clears all "promo_code_usages" edges to the PromoCodeUsage entity.
func (_u *UserUpdateOne) ClearPromoCodeUsages() *UserUpdateOne {
	_u.mutation.ClearPromoCodeUsages()
	return _u
}

// RemovePromoCodeUsageIDs removes the "promo_code_usages" edge to PromoCodeUsage entities by IDs.
func (_u *UserUpdateOne) RemovePromoCodeUsageIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemovePromoCodeUsageIDs(ids...)
	return _u
}

// RemovePromoCodeUsages removes "promo_code_usages" edges to PromoCodeUsage entities.
func (_u *UserUpdateOne) RemovePromoCodeUsages(v ...*PromoCodeUsage) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePromoCodeUsageIDs(ids...)
}

// ClearPaymentOrders clears all "payment_orders" edges to the PaymentOrder entity.
func (_u *UserUpdateOne) ClearPaymentOrders() *UserUpdateOne {
	_u.mutation.ClearPaymentOrders()
	return _u
}

// RemovePaymentOrderIDs removes the "payment_orders" edge to PaymentOrder entities by IDs.
func (_u *UserUpdateOne) RemovePaymentOrderIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemovePaymentOrderIDs(ids...)
	return _u
}

// RemovePaymentOrders removes "payment_orders" edges to PaymentOrder entities.
func (_u *UserUpdateOne) RemovePaymentOrders(v ...*PaymentOrder) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePaymentOrderIDs(ids...)
}

// ClearAuthIdentities clears all "auth_identities" edges to the AuthIdentity entity.
func (_u *UserUpdateOne) ClearAuthIdentities() *UserUpdateOne {
	_u.mutation.ClearAuthIdentities()
	return _u
}

// RemoveAuthIdentityIDs removes the "auth_identities" edge to AuthIdentity entities by IDs.
func (_u *UserUpdateOne) RemoveAuthIdentityIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemoveAuthIdentityIDs(ids...)
	return _u
}

// RemoveAuthIdentities removes "auth_identities" edges to AuthIdentity entities.
func (_u *UserUpdateOne) RemoveAuthIdentities(v ...*AuthIdentity) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAuthIdentityIDs(ids...)
}

// ClearPendingAuthSessions clears all "pending_auth_sessions" edges to the PendingAuthSession entity.
func (_u *UserUpdateOne) ClearPendingAuthSessions() *UserUpdateOne {
	_u.mutation.ClearPendingAuthSessions()
	return _u
}

// RemovePendingAuthSessionIDs removes the "pending_auth_sessions" edge to PendingAuthSession entities by IDs.
func (_u *UserUpdateOne) RemovePendingAuthSessionIDs(ids ...int64) *UserUpdateOne {
	_u.mutation.RemovePendingAuthSessionIDs(ids...)
	return _u
}

// RemovePendingAuthSessions removes "pending_auth_sessions" edges to PendingAuthSession entities.
func (_u *UserUpdateOne) RemovePendingAuthSessions(v ...*PendingAuthSession) *UserUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemovePendingAuthSessionIDs(ids...)
}

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

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

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

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

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

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

// defaults sets the default values of the builder before save.
func (_u *UserUpdateOne) defaults() error {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		if user.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized user.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := user.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_u *UserUpdateOne) check() error {
	if v, ok := _u.mutation.Email(); ok {
		if err := user.EmailValidator(v); err != nil {
			return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PasswordHash(); ok {
		if err := user.PasswordHashValidator(v); err != nil {
			return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Role(); ok {
		if err := user.RoleValidator(v); err != nil {
			return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := user.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Username(); ok {
		if err := user.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SignupSource(); ok {
		if err := user.SignupSourceValidator(v); err != nil {
			return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
		}
	}
	return nil
}

func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
		for _, f := range fields {
			if !user.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != user.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(user.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.PasswordHash(); ok {
		_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
	}
	if value, ok := _u.mutation.Role(); ok {
		_spec.SetField(user.FieldRole, field.TypeString, value)
	}
	if value, ok := _u.mutation.Balance(); ok {
		_spec.SetField(user.FieldBalance, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBalance(); ok {
		_spec.AddField(user.FieldBalance, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.Concurrency(); ok {
		_spec.SetField(user.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedConcurrency(); ok {
		_spec.AddField(user.FieldConcurrency, field.TypeInt, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(user.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Username(); ok {
		_spec.SetField(user.FieldUsername, field.TypeString, value)
	}
	if value, ok := _u.mutation.Notes(); ok {
		_spec.SetField(user.FieldNotes, field.TypeString, value)
	}
	if value, ok := _u.mutation.TotpSecretEncrypted(); ok {
		_spec.SetField(user.FieldTotpSecretEncrypted, field.TypeString, value)
	}
	if _u.mutation.TotpSecretEncryptedCleared() {
		_spec.ClearField(user.FieldTotpSecretEncrypted, field.TypeString)
	}
	if value, ok := _u.mutation.TotpEnabled(); ok {
		_spec.SetField(user.FieldTotpEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.TotpEnabledAt(); ok {
		_spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
	}
	if _u.mutation.TotpEnabledAtCleared() {
		_spec.ClearField(user.FieldTotpEnabledAt, field.TypeTime)
	}
	if value, ok := _u.mutation.SignupSource(); ok {
		_spec.SetField(user.FieldSignupSource, field.TypeString, value)
	}
	if value, ok := _u.mutation.LastLoginAt(); ok {
		_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
	}
	if _u.mutation.LastLoginAtCleared() {
		_spec.ClearField(user.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := _u.mutation.LastActiveAt(); ok {
		_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
	}
	if _u.mutation.LastActiveAtCleared() {
		_spec.ClearField(user.FieldLastActiveAt, field.TypeTime)
	}
	if value, ok := _u.mutation.BalanceNotifyEnabled(); ok {
		_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.BalanceNotifyThresholdType(); ok {
		_spec.SetField(user.FieldBalanceNotifyThresholdType, field.TypeString, value)
	}
	if value, ok := _u.mutation.BalanceNotifyThreshold(); ok {
		_spec.SetField(user.FieldBalanceNotifyThreshold, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedBalanceNotifyThreshold(); ok {
		_spec.AddField(user.FieldBalanceNotifyThreshold, field.TypeFloat64, value)
	}
	if _u.mutation.BalanceNotifyThresholdCleared() {
		_spec.ClearField(user.FieldBalanceNotifyThreshold, field.TypeFloat64)
	}
	if value, ok := _u.mutation.BalanceNotifyExtraEmails(); ok {
		_spec.SetField(user.FieldBalanceNotifyExtraEmails, field.TypeString, value)
	}
	if value, ok := _u.mutation.TotalRecharged(); ok {
		_spec.SetField(user.FieldTotalRecharged, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedTotalRecharged(); ok {
		_spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RpmLimit(); ok {
		_spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedRpmLimit(); ok {
		_spec.AddField(user.FieldRpmLimit, field.TypeInt, value)
	}
	if _u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.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.APIKeysIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.APIKeysTable,
			Columns: []string{user.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.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.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.RedeemCodesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.RedeemCodesTable,
			Columns: []string{user.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.SubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SubscriptionsTable,
			Columns: []string{user.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AssignedSubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAssignedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.AssignedSubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AssignedSubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AssignedSubscriptionsTable,
			Columns: []string{user.AssignedSubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.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.AnnouncementReadsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAnnouncementReadsIDs(); len(nodes) > 0 && !_u.mutation.AnnouncementReadsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.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.AnnouncementReadsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AnnouncementReadsTable,
			Columns: []string{user.AnnouncementReadsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(announcementread.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.AllowedGroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_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.RemovedAllowedGroupsIDs(); len(nodes) > 0 && !_u.mutation.AllowedGroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			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 := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_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.AllowedGroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   user.AllowedGroupsTable,
			Columns: user.AllowedGroupsPrimaryKey,
			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 := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.UsageLogsTable,
			Columns: []string{user.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:   user.UsageLogsTable,
			Columns: []string{user.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:   user.UsageLogsTable,
			Columns: []string{user.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 _u.mutation.AttributeValuesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAttributeValuesIDs(); len(nodes) > 0 && !_u.mutation.AttributeValuesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.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.AttributeValuesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AttributeValuesTable,
			Columns: []string{user.AttributeValuesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(userattributevalue.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.PromoCodeUsagesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPromoCodeUsagesIDs(); len(nodes) > 0 && !_u.mutation.PromoCodeUsagesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.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.PromoCodeUsagesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PromoCodeUsagesTable,
			Columns: []string{user.PromoCodeUsagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(promocodeusage.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.PaymentOrdersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPaymentOrdersIDs(); len(nodes) > 0 && !_u.mutation.PaymentOrdersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.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.PaymentOrdersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PaymentOrdersTable,
			Columns: []string{user.PaymentOrdersColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentorder.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.AuthIdentitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAuthIdentitiesIDs(); len(nodes) > 0 && !_u.mutation.AuthIdentitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.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.AuthIdentitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.AuthIdentitiesTable,
			Columns: []string{user.AuthIdentitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(authidentity.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.PendingAuthSessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedPendingAuthSessionsIDs(); len(nodes) > 0 && !_u.mutation.PendingAuthSessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.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.PendingAuthSessionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.PendingAuthSessionsTable,
			Columns: []string{user.PendingAuthSessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &User{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{user.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
