// Code generated by ent, DO NOT EDIT.

package ent

import (
	"PasswordManager/ent/challenge"
	"PasswordManager/ent/predicate"
	"PasswordManager/ent/session"
	"PasswordManager/ent/totpcredential"
	"PasswordManager/ent/user"
	"PasswordManager/ent/vault"
	"PasswordManager/ent/webauthncredential"
	"PasswordManager/ent/webauthnregisterchallenge"
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
)

// 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 (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
	uu.mutation.Where(ps...)
	return uu
}

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

// SetStrengthenedMasterHash sets the "strengthenedMasterHash" field.
func (uu *UserUpdate) SetStrengthenedMasterHash(b []byte) *UserUpdate {
	uu.mutation.SetStrengthenedMasterHash(b)
	return uu
}

// SetStrengthenedMasterHashSalt sets the "strengthenedMasterHashSalt" field.
func (uu *UserUpdate) SetStrengthenedMasterHashSalt(b []byte) *UserUpdate {
	uu.mutation.SetStrengthenedMasterHashSalt(b)
	return uu
}

// SetProtectedDatabaseKey sets the "protectedDatabaseKey" field.
func (uu *UserUpdate) SetProtectedDatabaseKey(b []byte) *UserUpdate {
	uu.mutation.SetProtectedDatabaseKey(b)
	return uu
}

// SetProtectedDatabaseKeyIv sets the "protectedDatabaseKeyIv" field.
func (uu *UserUpdate) SetProtectedDatabaseKeyIv(b []byte) *UserUpdate {
	uu.mutation.SetProtectedDatabaseKeyIv(b)
	return uu
}

// SetWebauthnEnabled sets the "webauthnEnabled" field.
func (uu *UserUpdate) SetWebauthnEnabled(b bool) *UserUpdate {
	uu.mutation.SetWebauthnEnabled(b)
	return uu
}

// SetNillableWebauthnEnabled sets the "webauthnEnabled" field if the given value is not nil.
func (uu *UserUpdate) SetNillableWebauthnEnabled(b *bool) *UserUpdate {
	if b != nil {
		uu.SetWebauthnEnabled(*b)
	}
	return uu
}

// SetTotpEnabled sets the "totpEnabled" field.
func (uu *UserUpdate) SetTotpEnabled(b bool) *UserUpdate {
	uu.mutation.SetTotpEnabled(b)
	return uu
}

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

// SetVerified sets the "verified" field.
func (uu *UserUpdate) SetVerified(b bool) *UserUpdate {
	uu.mutation.SetVerified(b)
	return uu
}

// SetNillableVerified sets the "verified" field if the given value is not nil.
func (uu *UserUpdate) SetNillableVerified(b *bool) *UserUpdate {
	if b != nil {
		uu.SetVerified(*b)
	}
	return uu
}

// SetTotpCredentialID sets the "totpCredential" edge to the TotpCredential entity by ID.
func (uu *UserUpdate) SetTotpCredentialID(id uuid.UUID) *UserUpdate {
	uu.mutation.SetTotpCredentialID(id)
	return uu
}

// SetNillableTotpCredentialID sets the "totpCredential" edge to the TotpCredential entity by ID if the given value is not nil.
func (uu *UserUpdate) SetNillableTotpCredentialID(id *uuid.UUID) *UserUpdate {
	if id != nil {
		uu = uu.SetTotpCredentialID(*id)
	}
	return uu
}

// SetTotpCredential sets the "totpCredential" edge to the TotpCredential entity.
func (uu *UserUpdate) SetTotpCredential(t *TotpCredential) *UserUpdate {
	return uu.SetTotpCredentialID(t.ID)
}

// AddWebauthnCredentialIDs adds the "webauthnCredentials" edge to the WebAuthnCredential entity by IDs.
func (uu *UserUpdate) AddWebauthnCredentialIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.AddWebauthnCredentialIDs(ids...)
	return uu
}

// AddWebauthnCredentials adds the "webauthnCredentials" edges to the WebAuthnCredential entity.
func (uu *UserUpdate) AddWebauthnCredentials(w ...*WebAuthnCredential) *UserUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uu.AddWebauthnCredentialIDs(ids...)
}

// AddWebauthnRegisterChallengeIDs adds the "webauthnRegisterChallenges" edge to the WebAuthnRegisterChallenge entity by IDs.
func (uu *UserUpdate) AddWebauthnRegisterChallengeIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.AddWebauthnRegisterChallengeIDs(ids...)
	return uu
}

// AddWebauthnRegisterChallenges adds the "webauthnRegisterChallenges" edges to the WebAuthnRegisterChallenge entity.
func (uu *UserUpdate) AddWebauthnRegisterChallenges(w ...*WebAuthnRegisterChallenge) *UserUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uu.AddWebauthnRegisterChallengeIDs(ids...)
}

// AddVaultIDs adds the "vaults" edge to the Vault entity by IDs.
func (uu *UserUpdate) AddVaultIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.AddVaultIDs(ids...)
	return uu
}

// AddVaults adds the "vaults" edges to the Vault entity.
func (uu *UserUpdate) AddVaults(v ...*Vault) *UserUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return uu.AddVaultIDs(ids...)
}

// AddSessionIDs adds the "sessions" edge to the Session entity by IDs.
func (uu *UserUpdate) AddSessionIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.AddSessionIDs(ids...)
	return uu
}

// AddSessions adds the "sessions" edges to the Session entity.
func (uu *UserUpdate) AddSessions(s ...*Session) *UserUpdate {
	ids := make([]uuid.UUID, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return uu.AddSessionIDs(ids...)
}

// AddChallengeIDs adds the "challenges" edge to the Challenge entity by IDs.
func (uu *UserUpdate) AddChallengeIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.AddChallengeIDs(ids...)
	return uu
}

// AddChallenges adds the "challenges" edges to the Challenge entity.
func (uu *UserUpdate) AddChallenges(c ...*Challenge) *UserUpdate {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return uu.AddChallengeIDs(ids...)
}

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

// ClearTotpCredential clears the "totpCredential" edge to the TotpCredential entity.
func (uu *UserUpdate) ClearTotpCredential() *UserUpdate {
	uu.mutation.ClearTotpCredential()
	return uu
}

// ClearWebauthnCredentials clears all "webauthnCredentials" edges to the WebAuthnCredential entity.
func (uu *UserUpdate) ClearWebauthnCredentials() *UserUpdate {
	uu.mutation.ClearWebauthnCredentials()
	return uu
}

// RemoveWebauthnCredentialIDs removes the "webauthnCredentials" edge to WebAuthnCredential entities by IDs.
func (uu *UserUpdate) RemoveWebauthnCredentialIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.RemoveWebauthnCredentialIDs(ids...)
	return uu
}

// RemoveWebauthnCredentials removes "webauthnCredentials" edges to WebAuthnCredential entities.
func (uu *UserUpdate) RemoveWebauthnCredentials(w ...*WebAuthnCredential) *UserUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uu.RemoveWebauthnCredentialIDs(ids...)
}

// ClearWebauthnRegisterChallenges clears all "webauthnRegisterChallenges" edges to the WebAuthnRegisterChallenge entity.
func (uu *UserUpdate) ClearWebauthnRegisterChallenges() *UserUpdate {
	uu.mutation.ClearWebauthnRegisterChallenges()
	return uu
}

// RemoveWebauthnRegisterChallengeIDs removes the "webauthnRegisterChallenges" edge to WebAuthnRegisterChallenge entities by IDs.
func (uu *UserUpdate) RemoveWebauthnRegisterChallengeIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.RemoveWebauthnRegisterChallengeIDs(ids...)
	return uu
}

// RemoveWebauthnRegisterChallenges removes "webauthnRegisterChallenges" edges to WebAuthnRegisterChallenge entities.
func (uu *UserUpdate) RemoveWebauthnRegisterChallenges(w ...*WebAuthnRegisterChallenge) *UserUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uu.RemoveWebauthnRegisterChallengeIDs(ids...)
}

// ClearVaults clears all "vaults" edges to the Vault entity.
func (uu *UserUpdate) ClearVaults() *UserUpdate {
	uu.mutation.ClearVaults()
	return uu
}

// RemoveVaultIDs removes the "vaults" edge to Vault entities by IDs.
func (uu *UserUpdate) RemoveVaultIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.RemoveVaultIDs(ids...)
	return uu
}

// RemoveVaults removes "vaults" edges to Vault entities.
func (uu *UserUpdate) RemoveVaults(v ...*Vault) *UserUpdate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return uu.RemoveVaultIDs(ids...)
}

// ClearSessions clears all "sessions" edges to the Session entity.
func (uu *UserUpdate) ClearSessions() *UserUpdate {
	uu.mutation.ClearSessions()
	return uu
}

// RemoveSessionIDs removes the "sessions" edge to Session entities by IDs.
func (uu *UserUpdate) RemoveSessionIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.RemoveSessionIDs(ids...)
	return uu
}

// RemoveSessions removes "sessions" edges to Session entities.
func (uu *UserUpdate) RemoveSessions(s ...*Session) *UserUpdate {
	ids := make([]uuid.UUID, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return uu.RemoveSessionIDs(ids...)
}

// ClearChallenges clears all "challenges" edges to the Challenge entity.
func (uu *UserUpdate) ClearChallenges() *UserUpdate {
	uu.mutation.ClearChallenges()
	return uu
}

// RemoveChallengeIDs removes the "challenges" edge to Challenge entities by IDs.
func (uu *UserUpdate) RemoveChallengeIDs(ids ...uuid.UUID) *UserUpdate {
	uu.mutation.RemoveChallengeIDs(ids...)
	return uu
}

// RemoveChallenges removes "challenges" edges to Challenge entities.
func (uu *UserUpdate) RemoveChallenges(c ...*Challenge) *UserUpdate {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return uu.RemoveChallengeIDs(ids...)
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (uu *UserUpdate) check() error {
	if v, ok := uu.mutation.StrengthenedMasterHash(); ok {
		if err := user.StrengthenedMasterHashValidator(v); err != nil {
			return &ValidationError{Name: "strengthenedMasterHash", err: fmt.Errorf(`ent: validator failed for field "User.strengthenedMasterHash": %w`, err)}
		}
	}
	if v, ok := uu.mutation.StrengthenedMasterHashSalt(); ok {
		if err := user.StrengthenedMasterHashSaltValidator(v); err != nil {
			return &ValidationError{Name: "strengthenedMasterHashSalt", err: fmt.Errorf(`ent: validator failed for field "User.strengthenedMasterHashSalt": %w`, err)}
		}
	}
	if v, ok := uu.mutation.ProtectedDatabaseKey(); ok {
		if err := user.ProtectedDatabaseKeyValidator(v); err != nil {
			return &ValidationError{Name: "protectedDatabaseKey", err: fmt.Errorf(`ent: validator failed for field "User.protectedDatabaseKey": %w`, err)}
		}
	}
	if v, ok := uu.mutation.ProtectedDatabaseKeyIv(); ok {
		if err := user.ProtectedDatabaseKeyIvValidator(v); err != nil {
			return &ValidationError{Name: "protectedDatabaseKeyIv", err: fmt.Errorf(`ent: validator failed for field "User.protectedDatabaseKeyIv": %w`, err)}
		}
	}
	return nil
}

func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := uu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
	if ps := uu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := uu.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if value, ok := uu.mutation.StrengthenedMasterHash(); ok {
		_spec.SetField(user.FieldStrengthenedMasterHash, field.TypeBytes, value)
	}
	if value, ok := uu.mutation.StrengthenedMasterHashSalt(); ok {
		_spec.SetField(user.FieldStrengthenedMasterHashSalt, field.TypeBytes, value)
	}
	if value, ok := uu.mutation.ProtectedDatabaseKey(); ok {
		_spec.SetField(user.FieldProtectedDatabaseKey, field.TypeBytes, value)
	}
	if value, ok := uu.mutation.ProtectedDatabaseKeyIv(); ok {
		_spec.SetField(user.FieldProtectedDatabaseKeyIv, field.TypeBytes, value)
	}
	if value, ok := uu.mutation.WebauthnEnabled(); ok {
		_spec.SetField(user.FieldWebauthnEnabled, field.TypeBool, value)
	}
	if value, ok := uu.mutation.TotpEnabled(); ok {
		_spec.SetField(user.FieldTotpEnabled, field.TypeBool, value)
	}
	if value, ok := uu.mutation.Verified(); ok {
		_spec.SetField(user.FieldVerified, field.TypeBool, value)
	}
	if uu.mutation.TotpCredentialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   user.TotpCredentialTable,
			Columns: []string{user.TotpCredentialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(totpcredential.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.TotpCredentialIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   user.TotpCredentialTable,
			Columns: []string{user.TotpCredentialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(totpcredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uu.mutation.WebauthnCredentialsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.RemovedWebauthnCredentialsIDs(); len(nodes) > 0 && !uu.mutation.WebauthnCredentialsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.WebauthnCredentialsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uu.mutation.WebauthnRegisterChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.RemovedWebauthnRegisterChallengesIDs(); len(nodes) > 0 && !uu.mutation.WebauthnRegisterChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.WebauthnRegisterChallengesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uu.mutation.VaultsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.RemovedVaultsIDs(); len(nodes) > 0 && !uu.mutation.VaultsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.VaultsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uu.mutation.SessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !uu.mutation.SessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.SessionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uu.mutation.ChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.RemovedChallengesIDs(); len(nodes) > 0 && !uu.mutation.ChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uu.mutation.ChallengesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, uu.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
	}
	uu.mutation.done = true
	return n, nil
}

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

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

// SetStrengthenedMasterHash sets the "strengthenedMasterHash" field.
func (uuo *UserUpdateOne) SetStrengthenedMasterHash(b []byte) *UserUpdateOne {
	uuo.mutation.SetStrengthenedMasterHash(b)
	return uuo
}

// SetStrengthenedMasterHashSalt sets the "strengthenedMasterHashSalt" field.
func (uuo *UserUpdateOne) SetStrengthenedMasterHashSalt(b []byte) *UserUpdateOne {
	uuo.mutation.SetStrengthenedMasterHashSalt(b)
	return uuo
}

// SetProtectedDatabaseKey sets the "protectedDatabaseKey" field.
func (uuo *UserUpdateOne) SetProtectedDatabaseKey(b []byte) *UserUpdateOne {
	uuo.mutation.SetProtectedDatabaseKey(b)
	return uuo
}

// SetProtectedDatabaseKeyIv sets the "protectedDatabaseKeyIv" field.
func (uuo *UserUpdateOne) SetProtectedDatabaseKeyIv(b []byte) *UserUpdateOne {
	uuo.mutation.SetProtectedDatabaseKeyIv(b)
	return uuo
}

// SetWebauthnEnabled sets the "webauthnEnabled" field.
func (uuo *UserUpdateOne) SetWebauthnEnabled(b bool) *UserUpdateOne {
	uuo.mutation.SetWebauthnEnabled(b)
	return uuo
}

// SetNillableWebauthnEnabled sets the "webauthnEnabled" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableWebauthnEnabled(b *bool) *UserUpdateOne {
	if b != nil {
		uuo.SetWebauthnEnabled(*b)
	}
	return uuo
}

// SetTotpEnabled sets the "totpEnabled" field.
func (uuo *UserUpdateOne) SetTotpEnabled(b bool) *UserUpdateOne {
	uuo.mutation.SetTotpEnabled(b)
	return uuo
}

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

// SetVerified sets the "verified" field.
func (uuo *UserUpdateOne) SetVerified(b bool) *UserUpdateOne {
	uuo.mutation.SetVerified(b)
	return uuo
}

// SetNillableVerified sets the "verified" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableVerified(b *bool) *UserUpdateOne {
	if b != nil {
		uuo.SetVerified(*b)
	}
	return uuo
}

// SetTotpCredentialID sets the "totpCredential" edge to the TotpCredential entity by ID.
func (uuo *UserUpdateOne) SetTotpCredentialID(id uuid.UUID) *UserUpdateOne {
	uuo.mutation.SetTotpCredentialID(id)
	return uuo
}

// SetNillableTotpCredentialID sets the "totpCredential" edge to the TotpCredential entity by ID if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableTotpCredentialID(id *uuid.UUID) *UserUpdateOne {
	if id != nil {
		uuo = uuo.SetTotpCredentialID(*id)
	}
	return uuo
}

// SetTotpCredential sets the "totpCredential" edge to the TotpCredential entity.
func (uuo *UserUpdateOne) SetTotpCredential(t *TotpCredential) *UserUpdateOne {
	return uuo.SetTotpCredentialID(t.ID)
}

// AddWebauthnCredentialIDs adds the "webauthnCredentials" edge to the WebAuthnCredential entity by IDs.
func (uuo *UserUpdateOne) AddWebauthnCredentialIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.AddWebauthnCredentialIDs(ids...)
	return uuo
}

// AddWebauthnCredentials adds the "webauthnCredentials" edges to the WebAuthnCredential entity.
func (uuo *UserUpdateOne) AddWebauthnCredentials(w ...*WebAuthnCredential) *UserUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uuo.AddWebauthnCredentialIDs(ids...)
}

// AddWebauthnRegisterChallengeIDs adds the "webauthnRegisterChallenges" edge to the WebAuthnRegisterChallenge entity by IDs.
func (uuo *UserUpdateOne) AddWebauthnRegisterChallengeIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.AddWebauthnRegisterChallengeIDs(ids...)
	return uuo
}

// AddWebauthnRegisterChallenges adds the "webauthnRegisterChallenges" edges to the WebAuthnRegisterChallenge entity.
func (uuo *UserUpdateOne) AddWebauthnRegisterChallenges(w ...*WebAuthnRegisterChallenge) *UserUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uuo.AddWebauthnRegisterChallengeIDs(ids...)
}

// AddVaultIDs adds the "vaults" edge to the Vault entity by IDs.
func (uuo *UserUpdateOne) AddVaultIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.AddVaultIDs(ids...)
	return uuo
}

// AddVaults adds the "vaults" edges to the Vault entity.
func (uuo *UserUpdateOne) AddVaults(v ...*Vault) *UserUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return uuo.AddVaultIDs(ids...)
}

// AddSessionIDs adds the "sessions" edge to the Session entity by IDs.
func (uuo *UserUpdateOne) AddSessionIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.AddSessionIDs(ids...)
	return uuo
}

// AddSessions adds the "sessions" edges to the Session entity.
func (uuo *UserUpdateOne) AddSessions(s ...*Session) *UserUpdateOne {
	ids := make([]uuid.UUID, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return uuo.AddSessionIDs(ids...)
}

// AddChallengeIDs adds the "challenges" edge to the Challenge entity by IDs.
func (uuo *UserUpdateOne) AddChallengeIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.AddChallengeIDs(ids...)
	return uuo
}

// AddChallenges adds the "challenges" edges to the Challenge entity.
func (uuo *UserUpdateOne) AddChallenges(c ...*Challenge) *UserUpdateOne {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return uuo.AddChallengeIDs(ids...)
}

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

// ClearTotpCredential clears the "totpCredential" edge to the TotpCredential entity.
func (uuo *UserUpdateOne) ClearTotpCredential() *UserUpdateOne {
	uuo.mutation.ClearTotpCredential()
	return uuo
}

// ClearWebauthnCredentials clears all "webauthnCredentials" edges to the WebAuthnCredential entity.
func (uuo *UserUpdateOne) ClearWebauthnCredentials() *UserUpdateOne {
	uuo.mutation.ClearWebauthnCredentials()
	return uuo
}

// RemoveWebauthnCredentialIDs removes the "webauthnCredentials" edge to WebAuthnCredential entities by IDs.
func (uuo *UserUpdateOne) RemoveWebauthnCredentialIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.RemoveWebauthnCredentialIDs(ids...)
	return uuo
}

// RemoveWebauthnCredentials removes "webauthnCredentials" edges to WebAuthnCredential entities.
func (uuo *UserUpdateOne) RemoveWebauthnCredentials(w ...*WebAuthnCredential) *UserUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uuo.RemoveWebauthnCredentialIDs(ids...)
}

// ClearWebauthnRegisterChallenges clears all "webauthnRegisterChallenges" edges to the WebAuthnRegisterChallenge entity.
func (uuo *UserUpdateOne) ClearWebauthnRegisterChallenges() *UserUpdateOne {
	uuo.mutation.ClearWebauthnRegisterChallenges()
	return uuo
}

// RemoveWebauthnRegisterChallengeIDs removes the "webauthnRegisterChallenges" edge to WebAuthnRegisterChallenge entities by IDs.
func (uuo *UserUpdateOne) RemoveWebauthnRegisterChallengeIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.RemoveWebauthnRegisterChallengeIDs(ids...)
	return uuo
}

// RemoveWebauthnRegisterChallenges removes "webauthnRegisterChallenges" edges to WebAuthnRegisterChallenge entities.
func (uuo *UserUpdateOne) RemoveWebauthnRegisterChallenges(w ...*WebAuthnRegisterChallenge) *UserUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return uuo.RemoveWebauthnRegisterChallengeIDs(ids...)
}

// ClearVaults clears all "vaults" edges to the Vault entity.
func (uuo *UserUpdateOne) ClearVaults() *UserUpdateOne {
	uuo.mutation.ClearVaults()
	return uuo
}

// RemoveVaultIDs removes the "vaults" edge to Vault entities by IDs.
func (uuo *UserUpdateOne) RemoveVaultIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.RemoveVaultIDs(ids...)
	return uuo
}

// RemoveVaults removes "vaults" edges to Vault entities.
func (uuo *UserUpdateOne) RemoveVaults(v ...*Vault) *UserUpdateOne {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return uuo.RemoveVaultIDs(ids...)
}

// ClearSessions clears all "sessions" edges to the Session entity.
func (uuo *UserUpdateOne) ClearSessions() *UserUpdateOne {
	uuo.mutation.ClearSessions()
	return uuo
}

// RemoveSessionIDs removes the "sessions" edge to Session entities by IDs.
func (uuo *UserUpdateOne) RemoveSessionIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.RemoveSessionIDs(ids...)
	return uuo
}

// RemoveSessions removes "sessions" edges to Session entities.
func (uuo *UserUpdateOne) RemoveSessions(s ...*Session) *UserUpdateOne {
	ids := make([]uuid.UUID, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return uuo.RemoveSessionIDs(ids...)
}

// ClearChallenges clears all "challenges" edges to the Challenge entity.
func (uuo *UserUpdateOne) ClearChallenges() *UserUpdateOne {
	uuo.mutation.ClearChallenges()
	return uuo
}

// RemoveChallengeIDs removes the "challenges" edge to Challenge entities by IDs.
func (uuo *UserUpdateOne) RemoveChallengeIDs(ids ...uuid.UUID) *UserUpdateOne {
	uuo.mutation.RemoveChallengeIDs(ids...)
	return uuo
}

// RemoveChallenges removes "challenges" edges to Challenge entities.
func (uuo *UserUpdateOne) RemoveChallenges(c ...*Challenge) *UserUpdateOne {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return uuo.RemoveChallengeIDs(ids...)
}

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

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

// Save executes the query and returns the updated User entity.
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
	return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (uuo *UserUpdateOne) check() error {
	if v, ok := uuo.mutation.StrengthenedMasterHash(); ok {
		if err := user.StrengthenedMasterHashValidator(v); err != nil {
			return &ValidationError{Name: "strengthenedMasterHash", err: fmt.Errorf(`ent: validator failed for field "User.strengthenedMasterHash": %w`, err)}
		}
	}
	if v, ok := uuo.mutation.StrengthenedMasterHashSalt(); ok {
		if err := user.StrengthenedMasterHashSaltValidator(v); err != nil {
			return &ValidationError{Name: "strengthenedMasterHashSalt", err: fmt.Errorf(`ent: validator failed for field "User.strengthenedMasterHashSalt": %w`, err)}
		}
	}
	if v, ok := uuo.mutation.ProtectedDatabaseKey(); ok {
		if err := user.ProtectedDatabaseKeyValidator(v); err != nil {
			return &ValidationError{Name: "protectedDatabaseKey", err: fmt.Errorf(`ent: validator failed for field "User.protectedDatabaseKey": %w`, err)}
		}
	}
	if v, ok := uuo.mutation.ProtectedDatabaseKeyIv(); ok {
		if err := user.ProtectedDatabaseKeyIvValidator(v); err != nil {
			return &ValidationError{Name: "protectedDatabaseKeyIv", err: fmt.Errorf(`ent: validator failed for field "User.protectedDatabaseKeyIv": %w`, err)}
		}
	}
	return nil
}

func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
	if err := uuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
	id, ok := uuo.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 := uuo.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 := uuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := uuo.mutation.Email(); ok {
		_spec.SetField(user.FieldEmail, field.TypeString, value)
	}
	if value, ok := uuo.mutation.StrengthenedMasterHash(); ok {
		_spec.SetField(user.FieldStrengthenedMasterHash, field.TypeBytes, value)
	}
	if value, ok := uuo.mutation.StrengthenedMasterHashSalt(); ok {
		_spec.SetField(user.FieldStrengthenedMasterHashSalt, field.TypeBytes, value)
	}
	if value, ok := uuo.mutation.ProtectedDatabaseKey(); ok {
		_spec.SetField(user.FieldProtectedDatabaseKey, field.TypeBytes, value)
	}
	if value, ok := uuo.mutation.ProtectedDatabaseKeyIv(); ok {
		_spec.SetField(user.FieldProtectedDatabaseKeyIv, field.TypeBytes, value)
	}
	if value, ok := uuo.mutation.WebauthnEnabled(); ok {
		_spec.SetField(user.FieldWebauthnEnabled, field.TypeBool, value)
	}
	if value, ok := uuo.mutation.TotpEnabled(); ok {
		_spec.SetField(user.FieldTotpEnabled, field.TypeBool, value)
	}
	if value, ok := uuo.mutation.Verified(); ok {
		_spec.SetField(user.FieldVerified, field.TypeBool, value)
	}
	if uuo.mutation.TotpCredentialCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   user.TotpCredentialTable,
			Columns: []string{user.TotpCredentialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(totpcredential.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.TotpCredentialIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   user.TotpCredentialTable,
			Columns: []string{user.TotpCredentialColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(totpcredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uuo.mutation.WebauthnCredentialsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.RemovedWebauthnCredentialsIDs(); len(nodes) > 0 && !uuo.mutation.WebauthnCredentialsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.WebauthnCredentialsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnCredentialsTable,
			Columns: []string{user.WebauthnCredentialsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthncredential.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uuo.mutation.WebauthnRegisterChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.RemovedWebauthnRegisterChallengesIDs(); len(nodes) > 0 && !uuo.mutation.WebauthnRegisterChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.WebauthnRegisterChallengesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.WebauthnRegisterChallengesTable,
			Columns: []string{user.WebauthnRegisterChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(webauthnregisterchallenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uuo.mutation.VaultsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.RemovedVaultsIDs(); len(nodes) > 0 && !uuo.mutation.VaultsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.VaultsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.VaultsTable,
			Columns: []string{user.VaultsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uuo.mutation.SessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !uuo.mutation.SessionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.SessionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.SessionsTable,
			Columns: []string{user.SessionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if uuo.mutation.ChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.RemovedChallengesIDs(); len(nodes) > 0 && !uuo.mutation.ChallengesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := uuo.mutation.ChallengesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.ChallengesTable,
			Columns: []string{user.ChallengesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(challenge.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &User{config: uuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, uuo.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
	}
	uuo.mutation.done = true
	return _node, nil
}
