// Code generated by ent, DO NOT EDIT.

package ent

import (
	"PasswordManager/ent/additionalfield"
	"PasswordManager/ent/password"
	"PasswordManager/ent/predicate"
	"PasswordManager/ent/url"
	"PasswordManager/ent/vault"
	"context"
	"errors"
	"fmt"

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

// PasswordUpdate is the builder for updating Password entities.
type PasswordUpdate struct {
	config
	hooks    []Hook
	mutation *PasswordMutation
}

// Where appends a list predicates to the PasswordUpdate builder.
func (pu *PasswordUpdate) Where(ps ...predicate.Password) *PasswordUpdate {
	pu.mutation.Where(ps...)
	return pu
}

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

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

// SetUsername sets the "username" field.
func (pu *PasswordUpdate) SetUsername(b []byte) *PasswordUpdate {
	pu.mutation.SetUsername(b)
	return pu
}

// SetUsernameIv sets the "usernameIv" field.
func (pu *PasswordUpdate) SetUsernameIv(b []byte) *PasswordUpdate {
	pu.mutation.SetUsernameIv(b)
	return pu
}

// SetPassword sets the "password" field.
func (pu *PasswordUpdate) SetPassword(b []byte) *PasswordUpdate {
	pu.mutation.SetPassword(b)
	return pu
}

// SetPasswordIv sets the "passwordIv" field.
func (pu *PasswordUpdate) SetPasswordIv(b []byte) *PasswordUpdate {
	pu.mutation.SetPasswordIv(b)
	return pu
}

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

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

// AddAdditionalFieldIDs adds the "additionalFields" edge to the AdditionalField entity by IDs.
func (pu *PasswordUpdate) AddAdditionalFieldIDs(ids ...uuid.UUID) *PasswordUpdate {
	pu.mutation.AddAdditionalFieldIDs(ids...)
	return pu
}

// AddAdditionalFields adds the "additionalFields" edges to the AdditionalField entity.
func (pu *PasswordUpdate) AddAdditionalFields(a ...*AdditionalField) *PasswordUpdate {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return pu.AddAdditionalFieldIDs(ids...)
}

// AddURLIDs adds the "urls" edge to the Url entity by IDs.
func (pu *PasswordUpdate) AddURLIDs(ids ...uuid.UUID) *PasswordUpdate {
	pu.mutation.AddURLIDs(ids...)
	return pu
}

// AddUrls adds the "urls" edges to the Url entity.
func (pu *PasswordUpdate) AddUrls(u ...*Url) *PasswordUpdate {
	ids := make([]uuid.UUID, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return pu.AddURLIDs(ids...)
}

// SetVaultID sets the "vault" edge to the Vault entity by ID.
func (pu *PasswordUpdate) SetVaultID(id uuid.UUID) *PasswordUpdate {
	pu.mutation.SetVaultID(id)
	return pu
}

// SetNillableVaultID sets the "vault" edge to the Vault entity by ID if the given value is not nil.
func (pu *PasswordUpdate) SetNillableVaultID(id *uuid.UUID) *PasswordUpdate {
	if id != nil {
		pu = pu.SetVaultID(*id)
	}
	return pu
}

// SetVault sets the "vault" edge to the Vault entity.
func (pu *PasswordUpdate) SetVault(v *Vault) *PasswordUpdate {
	return pu.SetVaultID(v.ID)
}

// Mutation returns the PasswordMutation object of the builder.
func (pu *PasswordUpdate) Mutation() *PasswordMutation {
	return pu.mutation
}

// ClearAdditionalFields clears all "additionalFields" edges to the AdditionalField entity.
func (pu *PasswordUpdate) ClearAdditionalFields() *PasswordUpdate {
	pu.mutation.ClearAdditionalFields()
	return pu
}

// RemoveAdditionalFieldIDs removes the "additionalFields" edge to AdditionalField entities by IDs.
func (pu *PasswordUpdate) RemoveAdditionalFieldIDs(ids ...uuid.UUID) *PasswordUpdate {
	pu.mutation.RemoveAdditionalFieldIDs(ids...)
	return pu
}

// RemoveAdditionalFields removes "additionalFields" edges to AdditionalField entities.
func (pu *PasswordUpdate) RemoveAdditionalFields(a ...*AdditionalField) *PasswordUpdate {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return pu.RemoveAdditionalFieldIDs(ids...)
}

// ClearUrls clears all "urls" edges to the Url entity.
func (pu *PasswordUpdate) ClearUrls() *PasswordUpdate {
	pu.mutation.ClearUrls()
	return pu
}

// RemoveURLIDs removes the "urls" edge to Url entities by IDs.
func (pu *PasswordUpdate) RemoveURLIDs(ids ...uuid.UUID) *PasswordUpdate {
	pu.mutation.RemoveURLIDs(ids...)
	return pu
}

// RemoveUrls removes "urls" edges to Url entities.
func (pu *PasswordUpdate) RemoveUrls(u ...*Url) *PasswordUpdate {
	ids := make([]uuid.UUID, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return pu.RemoveURLIDs(ids...)
}

// ClearVault clears the "vault" edge to the Vault entity.
func (pu *PasswordUpdate) ClearVault() *PasswordUpdate {
	pu.mutation.ClearVault()
	return pu
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (pu *PasswordUpdate) check() error {
	if v, ok := pu.mutation.Name(); ok {
		if err := password.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Password.name": %w`, err)}
		}
	}
	if v, ok := pu.mutation.NameIv(); ok {
		if err := password.NameIvValidator(v); err != nil {
			return &ValidationError{Name: "nameIv", err: fmt.Errorf(`ent: validator failed for field "Password.nameIv": %w`, err)}
		}
	}
	if v, ok := pu.mutation.Username(); ok {
		if err := password.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Password.username": %w`, err)}
		}
	}
	if v, ok := pu.mutation.UsernameIv(); ok {
		if err := password.UsernameIvValidator(v); err != nil {
			return &ValidationError{Name: "usernameIv", err: fmt.Errorf(`ent: validator failed for field "Password.usernameIv": %w`, err)}
		}
	}
	if v, ok := pu.mutation.Password(); ok {
		if err := password.PasswordValidator(v); err != nil {
			return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Password.password": %w`, err)}
		}
	}
	if v, ok := pu.mutation.PasswordIv(); ok {
		if err := password.PasswordIvValidator(v); err != nil {
			return &ValidationError{Name: "passwordIv", err: fmt.Errorf(`ent: validator failed for field "Password.passwordIv": %w`, err)}
		}
	}
	if v, ok := pu.mutation.Colour(); ok {
		if err := password.ColourValidator(v); err != nil {
			return &ValidationError{Name: "colour", err: fmt.Errorf(`ent: validator failed for field "Password.colour": %w`, err)}
		}
	}
	if v, ok := pu.mutation.ColourIv(); ok {
		if err := password.ColourIvValidator(v); err != nil {
			return &ValidationError{Name: "colourIv", err: fmt.Errorf(`ent: validator failed for field "Password.colourIv": %w`, err)}
		}
	}
	return nil
}

func (pu *PasswordUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := pu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID))
	if ps := pu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := pu.mutation.Name(); ok {
		_spec.SetField(password.FieldName, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.NameIv(); ok {
		_spec.SetField(password.FieldNameIv, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.Username(); ok {
		_spec.SetField(password.FieldUsername, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.UsernameIv(); ok {
		_spec.SetField(password.FieldUsernameIv, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.Password(); ok {
		_spec.SetField(password.FieldPassword, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.PasswordIv(); ok {
		_spec.SetField(password.FieldPasswordIv, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.Colour(); ok {
		_spec.SetField(password.FieldColour, field.TypeBytes, value)
	}
	if value, ok := pu.mutation.ColourIv(); ok {
		_spec.SetField(password.FieldColourIv, field.TypeBytes, value)
	}
	if pu.mutation.AdditionalFieldsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := pu.mutation.RemovedAdditionalFieldsIDs(); len(nodes) > 0 && !pu.mutation.AdditionalFieldsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.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 := pu.mutation.AdditionalFieldsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if pu.mutation.UrlsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := pu.mutation.RemovedUrlsIDs(); len(nodes) > 0 && !pu.mutation.UrlsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.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 := pu.mutation.UrlsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if pu.mutation.VaultCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   password.VaultTable,
			Columns: []string{password.VaultColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := pu.mutation.VaultIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   password.VaultTable,
			Columns: []string{password.VaultColumn},
			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 n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{password.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	pu.mutation.done = true
	return n, nil
}

// PasswordUpdateOne is the builder for updating a single Password entity.
type PasswordUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PasswordMutation
}

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

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

// SetUsername sets the "username" field.
func (puo *PasswordUpdateOne) SetUsername(b []byte) *PasswordUpdateOne {
	puo.mutation.SetUsername(b)
	return puo
}

// SetUsernameIv sets the "usernameIv" field.
func (puo *PasswordUpdateOne) SetUsernameIv(b []byte) *PasswordUpdateOne {
	puo.mutation.SetUsernameIv(b)
	return puo
}

// SetPassword sets the "password" field.
func (puo *PasswordUpdateOne) SetPassword(b []byte) *PasswordUpdateOne {
	puo.mutation.SetPassword(b)
	return puo
}

// SetPasswordIv sets the "passwordIv" field.
func (puo *PasswordUpdateOne) SetPasswordIv(b []byte) *PasswordUpdateOne {
	puo.mutation.SetPasswordIv(b)
	return puo
}

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

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

// AddAdditionalFieldIDs adds the "additionalFields" edge to the AdditionalField entity by IDs.
func (puo *PasswordUpdateOne) AddAdditionalFieldIDs(ids ...uuid.UUID) *PasswordUpdateOne {
	puo.mutation.AddAdditionalFieldIDs(ids...)
	return puo
}

// AddAdditionalFields adds the "additionalFields" edges to the AdditionalField entity.
func (puo *PasswordUpdateOne) AddAdditionalFields(a ...*AdditionalField) *PasswordUpdateOne {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return puo.AddAdditionalFieldIDs(ids...)
}

// AddURLIDs adds the "urls" edge to the Url entity by IDs.
func (puo *PasswordUpdateOne) AddURLIDs(ids ...uuid.UUID) *PasswordUpdateOne {
	puo.mutation.AddURLIDs(ids...)
	return puo
}

// AddUrls adds the "urls" edges to the Url entity.
func (puo *PasswordUpdateOne) AddUrls(u ...*Url) *PasswordUpdateOne {
	ids := make([]uuid.UUID, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return puo.AddURLIDs(ids...)
}

// SetVaultID sets the "vault" edge to the Vault entity by ID.
func (puo *PasswordUpdateOne) SetVaultID(id uuid.UUID) *PasswordUpdateOne {
	puo.mutation.SetVaultID(id)
	return puo
}

// SetNillableVaultID sets the "vault" edge to the Vault entity by ID if the given value is not nil.
func (puo *PasswordUpdateOne) SetNillableVaultID(id *uuid.UUID) *PasswordUpdateOne {
	if id != nil {
		puo = puo.SetVaultID(*id)
	}
	return puo
}

// SetVault sets the "vault" edge to the Vault entity.
func (puo *PasswordUpdateOne) SetVault(v *Vault) *PasswordUpdateOne {
	return puo.SetVaultID(v.ID)
}

// Mutation returns the PasswordMutation object of the builder.
func (puo *PasswordUpdateOne) Mutation() *PasswordMutation {
	return puo.mutation
}

// ClearAdditionalFields clears all "additionalFields" edges to the AdditionalField entity.
func (puo *PasswordUpdateOne) ClearAdditionalFields() *PasswordUpdateOne {
	puo.mutation.ClearAdditionalFields()
	return puo
}

// RemoveAdditionalFieldIDs removes the "additionalFields" edge to AdditionalField entities by IDs.
func (puo *PasswordUpdateOne) RemoveAdditionalFieldIDs(ids ...uuid.UUID) *PasswordUpdateOne {
	puo.mutation.RemoveAdditionalFieldIDs(ids...)
	return puo
}

// RemoveAdditionalFields removes "additionalFields" edges to AdditionalField entities.
func (puo *PasswordUpdateOne) RemoveAdditionalFields(a ...*AdditionalField) *PasswordUpdateOne {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return puo.RemoveAdditionalFieldIDs(ids...)
}

// ClearUrls clears all "urls" edges to the Url entity.
func (puo *PasswordUpdateOne) ClearUrls() *PasswordUpdateOne {
	puo.mutation.ClearUrls()
	return puo
}

// RemoveURLIDs removes the "urls" edge to Url entities by IDs.
func (puo *PasswordUpdateOne) RemoveURLIDs(ids ...uuid.UUID) *PasswordUpdateOne {
	puo.mutation.RemoveURLIDs(ids...)
	return puo
}

// RemoveUrls removes "urls" edges to Url entities.
func (puo *PasswordUpdateOne) RemoveUrls(u ...*Url) *PasswordUpdateOne {
	ids := make([]uuid.UUID, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return puo.RemoveURLIDs(ids...)
}

// ClearVault clears the "vault" edge to the Vault entity.
func (puo *PasswordUpdateOne) ClearVault() *PasswordUpdateOne {
	puo.mutation.ClearVault()
	return puo
}

// Where appends a list predicates to the PasswordUpdate builder.
func (puo *PasswordUpdateOne) Where(ps ...predicate.Password) *PasswordUpdateOne {
	puo.mutation.Where(ps...)
	return puo
}

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

// Save executes the query and returns the updated Password entity.
func (puo *PasswordUpdateOne) Save(ctx context.Context) (*Password, error) {
	return withHooks[*Password, PasswordMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (puo *PasswordUpdateOne) check() error {
	if v, ok := puo.mutation.Name(); ok {
		if err := password.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Password.name": %w`, err)}
		}
	}
	if v, ok := puo.mutation.NameIv(); ok {
		if err := password.NameIvValidator(v); err != nil {
			return &ValidationError{Name: "nameIv", err: fmt.Errorf(`ent: validator failed for field "Password.nameIv": %w`, err)}
		}
	}
	if v, ok := puo.mutation.Username(); ok {
		if err := password.UsernameValidator(v); err != nil {
			return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Password.username": %w`, err)}
		}
	}
	if v, ok := puo.mutation.UsernameIv(); ok {
		if err := password.UsernameIvValidator(v); err != nil {
			return &ValidationError{Name: "usernameIv", err: fmt.Errorf(`ent: validator failed for field "Password.usernameIv": %w`, err)}
		}
	}
	if v, ok := puo.mutation.Password(); ok {
		if err := password.PasswordValidator(v); err != nil {
			return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Password.password": %w`, err)}
		}
	}
	if v, ok := puo.mutation.PasswordIv(); ok {
		if err := password.PasswordIvValidator(v); err != nil {
			return &ValidationError{Name: "passwordIv", err: fmt.Errorf(`ent: validator failed for field "Password.passwordIv": %w`, err)}
		}
	}
	if v, ok := puo.mutation.Colour(); ok {
		if err := password.ColourValidator(v); err != nil {
			return &ValidationError{Name: "colour", err: fmt.Errorf(`ent: validator failed for field "Password.colour": %w`, err)}
		}
	}
	if v, ok := puo.mutation.ColourIv(); ok {
		if err := password.ColourIvValidator(v); err != nil {
			return &ValidationError{Name: "colourIv", err: fmt.Errorf(`ent: validator failed for field "Password.colourIv": %w`, err)}
		}
	}
	return nil
}

func (puo *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err error) {
	if err := puo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeUUID))
	id, ok := puo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Password.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := puo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, password.FieldID)
		for _, f := range fields {
			if !password.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != password.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := puo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := puo.mutation.Name(); ok {
		_spec.SetField(password.FieldName, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.NameIv(); ok {
		_spec.SetField(password.FieldNameIv, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.Username(); ok {
		_spec.SetField(password.FieldUsername, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.UsernameIv(); ok {
		_spec.SetField(password.FieldUsernameIv, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.Password(); ok {
		_spec.SetField(password.FieldPassword, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.PasswordIv(); ok {
		_spec.SetField(password.FieldPasswordIv, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.Colour(); ok {
		_spec.SetField(password.FieldColour, field.TypeBytes, value)
	}
	if value, ok := puo.mutation.ColourIv(); ok {
		_spec.SetField(password.FieldColourIv, field.TypeBytes, value)
	}
	if puo.mutation.AdditionalFieldsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := puo.mutation.RemovedAdditionalFieldsIDs(); len(nodes) > 0 && !puo.mutation.AdditionalFieldsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.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 := puo.mutation.AdditionalFieldsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.AdditionalFieldsTable,
			Columns: []string{password.AdditionalFieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(additionalfield.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if puo.mutation.UrlsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := puo.mutation.RemovedUrlsIDs(); len(nodes) > 0 && !puo.mutation.UrlsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.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 := puo.mutation.UrlsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   password.UrlsTable,
			Columns: []string{password.UrlsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(url.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if puo.mutation.VaultCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   password.VaultTable,
			Columns: []string{password.VaultColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(vault.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := puo.mutation.VaultIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   password.VaultTable,
			Columns: []string{password.VaultColumn},
			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)
	}
	_node = &Password{config: puo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{password.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	puo.mutation.done = true
	return _node, nil
}
