// Code generated by ent, DO NOT EDIT.

package ent

import (
	"PasswordManager/ent/note"
	"PasswordManager/ent/password"
	"PasswordManager/ent/predicate"
	"PasswordManager/ent/user"
	"PasswordManager/ent/vault"
	"context"
	"errors"
	"fmt"
	"time"

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

// VaultUpdate is the builder for updating Vault entities.
type VaultUpdate struct {
	config
	hooks    []Hook
	mutation *VaultMutation
}

// Where appends a list predicates to the VaultUpdate builder.
func (vu *VaultUpdate) Where(ps ...predicate.Vault) *VaultUpdate {
	vu.mutation.Where(ps...)
	return vu
}

// SetCreatedAt sets the "createdAt" field.
func (vu *VaultUpdate) SetCreatedAt(t time.Time) *VaultUpdate {
	vu.mutation.SetCreatedAt(t)
	return vu
}

// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (vu *VaultUpdate) SetNillableCreatedAt(t *time.Time) *VaultUpdate {
	if t != nil {
		vu.SetCreatedAt(*t)
	}
	return vu
}

// SetName sets the "name" field.
func (vu *VaultUpdate) SetName(b []byte) *VaultUpdate {
	vu.mutation.SetName(b)
	return vu
}

// SetNameIv sets the "nameIv" field.
func (vu *VaultUpdate) SetNameIv(b []byte) *VaultUpdate {
	vu.mutation.SetNameIv(b)
	return vu
}

// SetColour sets the "colour" field.
func (vu *VaultUpdate) SetColour(b []byte) *VaultUpdate {
	vu.mutation.SetColour(b)
	return vu
}

// SetColourIv sets the "colourIv" field.
func (vu *VaultUpdate) SetColourIv(b []byte) *VaultUpdate {
	vu.mutation.SetColourIv(b)
	return vu
}

// AddPasswordIDs adds the "passwords" edge to the Password entity by IDs.
func (vu *VaultUpdate) AddPasswordIDs(ids ...uuid.UUID) *VaultUpdate {
	vu.mutation.AddPasswordIDs(ids...)
	return vu
}

// AddPasswords adds the "passwords" edges to the Password entity.
func (vu *VaultUpdate) AddPasswords(p ...*Password) *VaultUpdate {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return vu.AddPasswordIDs(ids...)
}

// AddNoteIDs adds the "notes" edge to the Note entity by IDs.
func (vu *VaultUpdate) AddNoteIDs(ids ...uuid.UUID) *VaultUpdate {
	vu.mutation.AddNoteIDs(ids...)
	return vu
}

// AddNotes adds the "notes" edges to the Note entity.
func (vu *VaultUpdate) AddNotes(n ...*Note) *VaultUpdate {
	ids := make([]uuid.UUID, len(n))
	for i := range n {
		ids[i] = n[i].ID
	}
	return vu.AddNoteIDs(ids...)
}

// SetUserID sets the "user" edge to the User entity by ID.
func (vu *VaultUpdate) SetUserID(id uuid.UUID) *VaultUpdate {
	vu.mutation.SetUserID(id)
	return vu
}

// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (vu *VaultUpdate) SetNillableUserID(id *uuid.UUID) *VaultUpdate {
	if id != nil {
		vu = vu.SetUserID(*id)
	}
	return vu
}

// SetUser sets the "user" edge to the User entity.
func (vu *VaultUpdate) SetUser(u *User) *VaultUpdate {
	return vu.SetUserID(u.ID)
}

// Mutation returns the VaultMutation object of the builder.
func (vu *VaultUpdate) Mutation() *VaultMutation {
	return vu.mutation
}

// ClearPasswords clears all "passwords" edges to the Password entity.
func (vu *VaultUpdate) ClearPasswords() *VaultUpdate {
	vu.mutation.ClearPasswords()
	return vu
}

// RemovePasswordIDs removes the "passwords" edge to Password entities by IDs.
func (vu *VaultUpdate) RemovePasswordIDs(ids ...uuid.UUID) *VaultUpdate {
	vu.mutation.RemovePasswordIDs(ids...)
	return vu
}

// RemovePasswords removes "passwords" edges to Password entities.
func (vu *VaultUpdate) RemovePasswords(p ...*Password) *VaultUpdate {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return vu.RemovePasswordIDs(ids...)
}

// ClearNotes clears all "notes" edges to the Note entity.
func (vu *VaultUpdate) ClearNotes() *VaultUpdate {
	vu.mutation.ClearNotes()
	return vu
}

// RemoveNoteIDs removes the "notes" edge to Note entities by IDs.
func (vu *VaultUpdate) RemoveNoteIDs(ids ...uuid.UUID) *VaultUpdate {
	vu.mutation.RemoveNoteIDs(ids...)
	return vu
}

// RemoveNotes removes "notes" edges to Note entities.
func (vu *VaultUpdate) RemoveNotes(n ...*Note) *VaultUpdate {
	ids := make([]uuid.UUID, len(n))
	for i := range n {
		ids[i] = n[i].ID
	}
	return vu.RemoveNoteIDs(ids...)
}

// ClearUser clears the "user" edge to the User entity.
func (vu *VaultUpdate) ClearUser() *VaultUpdate {
	vu.mutation.ClearUser()
	return vu
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (vu *VaultUpdate) check() error {
	if v, ok := vu.mutation.Name(); ok {
		if err := vault.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Vault.name": %w`, err)}
		}
	}
	if v, ok := vu.mutation.NameIv(); ok {
		if err := vault.NameIvValidator(v); err != nil {
			return &ValidationError{Name: "nameIv", err: fmt.Errorf(`ent: validator failed for field "Vault.nameIv": %w`, err)}
		}
	}
	if v, ok := vu.mutation.Colour(); ok {
		if err := vault.ColourValidator(v); err != nil {
			return &ValidationError{Name: "colour", err: fmt.Errorf(`ent: validator failed for field "Vault.colour": %w`, err)}
		}
	}
	if v, ok := vu.mutation.ColourIv(); ok {
		if err := vault.ColourIvValidator(v); err != nil {
			return &ValidationError{Name: "colourIv", err: fmt.Errorf(`ent: validator failed for field "Vault.colourIv": %w`, err)}
		}
	}
	return nil
}

func (vu *VaultUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := vu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(vault.Table, vault.Columns, sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID))
	if ps := vu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := vu.mutation.CreatedAt(); ok {
		_spec.SetField(vault.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := vu.mutation.Name(); ok {
		_spec.SetField(vault.FieldName, field.TypeBytes, value)
	}
	if value, ok := vu.mutation.NameIv(); ok {
		_spec.SetField(vault.FieldNameIv, field.TypeBytes, value)
	}
	if value, ok := vu.mutation.Colour(); ok {
		_spec.SetField(vault.FieldColour, field.TypeBytes, value)
	}
	if value, ok := vu.mutation.ColourIv(); ok {
		_spec.SetField(vault.FieldColourIv, field.TypeBytes, value)
	}
	if vu.mutation.PasswordsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vu.mutation.RemovedPasswordsIDs(); len(nodes) > 0 && !vu.mutation.PasswordsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.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 := vu.mutation.PasswordsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if vu.mutation.NotesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vu.mutation.RemovedNotesIDs(); len(nodes) > 0 && !vu.mutation.NotesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.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 := vu.mutation.NotesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if vu.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   vault.UserTable,
			Columns: []string{vault.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vu.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   vault.UserTable,
			Columns: []string{vault.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.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, vu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{vault.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	vu.mutation.done = true
	return n, nil
}

// VaultUpdateOne is the builder for updating a single Vault entity.
type VaultUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *VaultMutation
}

// SetCreatedAt sets the "createdAt" field.
func (vuo *VaultUpdateOne) SetCreatedAt(t time.Time) *VaultUpdateOne {
	vuo.mutation.SetCreatedAt(t)
	return vuo
}

// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (vuo *VaultUpdateOne) SetNillableCreatedAt(t *time.Time) *VaultUpdateOne {
	if t != nil {
		vuo.SetCreatedAt(*t)
	}
	return vuo
}

// SetName sets the "name" field.
func (vuo *VaultUpdateOne) SetName(b []byte) *VaultUpdateOne {
	vuo.mutation.SetName(b)
	return vuo
}

// SetNameIv sets the "nameIv" field.
func (vuo *VaultUpdateOne) SetNameIv(b []byte) *VaultUpdateOne {
	vuo.mutation.SetNameIv(b)
	return vuo
}

// SetColour sets the "colour" field.
func (vuo *VaultUpdateOne) SetColour(b []byte) *VaultUpdateOne {
	vuo.mutation.SetColour(b)
	return vuo
}

// SetColourIv sets the "colourIv" field.
func (vuo *VaultUpdateOne) SetColourIv(b []byte) *VaultUpdateOne {
	vuo.mutation.SetColourIv(b)
	return vuo
}

// AddPasswordIDs adds the "passwords" edge to the Password entity by IDs.
func (vuo *VaultUpdateOne) AddPasswordIDs(ids ...uuid.UUID) *VaultUpdateOne {
	vuo.mutation.AddPasswordIDs(ids...)
	return vuo
}

// AddPasswords adds the "passwords" edges to the Password entity.
func (vuo *VaultUpdateOne) AddPasswords(p ...*Password) *VaultUpdateOne {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return vuo.AddPasswordIDs(ids...)
}

// AddNoteIDs adds the "notes" edge to the Note entity by IDs.
func (vuo *VaultUpdateOne) AddNoteIDs(ids ...uuid.UUID) *VaultUpdateOne {
	vuo.mutation.AddNoteIDs(ids...)
	return vuo
}

// AddNotes adds the "notes" edges to the Note entity.
func (vuo *VaultUpdateOne) AddNotes(n ...*Note) *VaultUpdateOne {
	ids := make([]uuid.UUID, len(n))
	for i := range n {
		ids[i] = n[i].ID
	}
	return vuo.AddNoteIDs(ids...)
}

// SetUserID sets the "user" edge to the User entity by ID.
func (vuo *VaultUpdateOne) SetUserID(id uuid.UUID) *VaultUpdateOne {
	vuo.mutation.SetUserID(id)
	return vuo
}

// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (vuo *VaultUpdateOne) SetNillableUserID(id *uuid.UUID) *VaultUpdateOne {
	if id != nil {
		vuo = vuo.SetUserID(*id)
	}
	return vuo
}

// SetUser sets the "user" edge to the User entity.
func (vuo *VaultUpdateOne) SetUser(u *User) *VaultUpdateOne {
	return vuo.SetUserID(u.ID)
}

// Mutation returns the VaultMutation object of the builder.
func (vuo *VaultUpdateOne) Mutation() *VaultMutation {
	return vuo.mutation
}

// ClearPasswords clears all "passwords" edges to the Password entity.
func (vuo *VaultUpdateOne) ClearPasswords() *VaultUpdateOne {
	vuo.mutation.ClearPasswords()
	return vuo
}

// RemovePasswordIDs removes the "passwords" edge to Password entities by IDs.
func (vuo *VaultUpdateOne) RemovePasswordIDs(ids ...uuid.UUID) *VaultUpdateOne {
	vuo.mutation.RemovePasswordIDs(ids...)
	return vuo
}

// RemovePasswords removes "passwords" edges to Password entities.
func (vuo *VaultUpdateOne) RemovePasswords(p ...*Password) *VaultUpdateOne {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return vuo.RemovePasswordIDs(ids...)
}

// ClearNotes clears all "notes" edges to the Note entity.
func (vuo *VaultUpdateOne) ClearNotes() *VaultUpdateOne {
	vuo.mutation.ClearNotes()
	return vuo
}

// RemoveNoteIDs removes the "notes" edge to Note entities by IDs.
func (vuo *VaultUpdateOne) RemoveNoteIDs(ids ...uuid.UUID) *VaultUpdateOne {
	vuo.mutation.RemoveNoteIDs(ids...)
	return vuo
}

// RemoveNotes removes "notes" edges to Note entities.
func (vuo *VaultUpdateOne) RemoveNotes(n ...*Note) *VaultUpdateOne {
	ids := make([]uuid.UUID, len(n))
	for i := range n {
		ids[i] = n[i].ID
	}
	return vuo.RemoveNoteIDs(ids...)
}

// ClearUser clears the "user" edge to the User entity.
func (vuo *VaultUpdateOne) ClearUser() *VaultUpdateOne {
	vuo.mutation.ClearUser()
	return vuo
}

// Where appends a list predicates to the VaultUpdate builder.
func (vuo *VaultUpdateOne) Where(ps ...predicate.Vault) *VaultUpdateOne {
	vuo.mutation.Where(ps...)
	return vuo
}

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

// Save executes the query and returns the updated Vault entity.
func (vuo *VaultUpdateOne) Save(ctx context.Context) (*Vault, error) {
	return withHooks[*Vault, VaultMutation](ctx, vuo.sqlSave, vuo.mutation, vuo.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (vuo *VaultUpdateOne) check() error {
	if v, ok := vuo.mutation.Name(); ok {
		if err := vault.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Vault.name": %w`, err)}
		}
	}
	if v, ok := vuo.mutation.NameIv(); ok {
		if err := vault.NameIvValidator(v); err != nil {
			return &ValidationError{Name: "nameIv", err: fmt.Errorf(`ent: validator failed for field "Vault.nameIv": %w`, err)}
		}
	}
	if v, ok := vuo.mutation.Colour(); ok {
		if err := vault.ColourValidator(v); err != nil {
			return &ValidationError{Name: "colour", err: fmt.Errorf(`ent: validator failed for field "Vault.colour": %w`, err)}
		}
	}
	if v, ok := vuo.mutation.ColourIv(); ok {
		if err := vault.ColourIvValidator(v); err != nil {
			return &ValidationError{Name: "colourIv", err: fmt.Errorf(`ent: validator failed for field "Vault.colourIv": %w`, err)}
		}
	}
	return nil
}

func (vuo *VaultUpdateOne) sqlSave(ctx context.Context) (_node *Vault, err error) {
	if err := vuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(vault.Table, vault.Columns, sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID))
	id, ok := vuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Vault.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := vuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, vault.FieldID)
		for _, f := range fields {
			if !vault.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != vault.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := vuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := vuo.mutation.CreatedAt(); ok {
		_spec.SetField(vault.FieldCreatedAt, field.TypeTime, value)
	}
	if value, ok := vuo.mutation.Name(); ok {
		_spec.SetField(vault.FieldName, field.TypeBytes, value)
	}
	if value, ok := vuo.mutation.NameIv(); ok {
		_spec.SetField(vault.FieldNameIv, field.TypeBytes, value)
	}
	if value, ok := vuo.mutation.Colour(); ok {
		_spec.SetField(vault.FieldColour, field.TypeBytes, value)
	}
	if value, ok := vuo.mutation.ColourIv(); ok {
		_spec.SetField(vault.FieldColourIv, field.TypeBytes, value)
	}
	if vuo.mutation.PasswordsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vuo.mutation.RemovedPasswordsIDs(); len(nodes) > 0 && !vuo.mutation.PasswordsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.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 := vuo.mutation.PasswordsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.PasswordsTable,
			Columns: []string{vault.PasswordsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if vuo.mutation.NotesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vuo.mutation.RemovedNotesIDs(); len(nodes) > 0 && !vuo.mutation.NotesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.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 := vuo.mutation.NotesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   vault.NotesTable,
			Columns: []string{vault.NotesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if vuo.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   vault.UserTable,
			Columns: []string{vault.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := vuo.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   vault.UserTable,
			Columns: []string{vault.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Vault{config: vuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, vuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{vault.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	vuo.mutation.done = true
	return _node, nil
}
