// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/appditto/pippin_nano_wallet/libs/database/ent/account"
	"github.com/appditto/pippin_nano_wallet/libs/database/ent/block"
	"github.com/appditto/pippin_nano_wallet/libs/database/ent/predicate"
	"github.com/appditto/pippin_nano_wallet/libs/database/ent/wallet"
	"github.com/google/uuid"
)

// AccountUpdate is the builder for updating Account entities.
type AccountUpdate struct {
	config
	hooks    []Hook
	mutation *AccountMutation
}

// Where appends a list predicates to the AccountUpdate builder.
func (au *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate {
	au.mutation.Where(ps...)
	return au
}

// SetWalletID sets the "wallet_id" field.
func (au *AccountUpdate) SetWalletID(u uuid.UUID) *AccountUpdate {
	au.mutation.SetWalletID(u)
	return au
}

// SetAddress sets the "address" field.
func (au *AccountUpdate) SetAddress(s string) *AccountUpdate {
	au.mutation.SetAddress(s)
	return au
}

// SetAccountIndex sets the "account_index" field.
func (au *AccountUpdate) SetAccountIndex(i int) *AccountUpdate {
	au.mutation.ResetAccountIndex()
	au.mutation.SetAccountIndex(i)
	return au
}

// SetNillableAccountIndex sets the "account_index" field if the given value is not nil.
func (au *AccountUpdate) SetNillableAccountIndex(i *int) *AccountUpdate {
	if i != nil {
		au.SetAccountIndex(*i)
	}
	return au
}

// AddAccountIndex adds i to the "account_index" field.
func (au *AccountUpdate) AddAccountIndex(i int) *AccountUpdate {
	au.mutation.AddAccountIndex(i)
	return au
}

// ClearAccountIndex clears the value of the "account_index" field.
func (au *AccountUpdate) ClearAccountIndex() *AccountUpdate {
	au.mutation.ClearAccountIndex()
	return au
}

// SetPrivateKey sets the "private_key" field.
func (au *AccountUpdate) SetPrivateKey(s string) *AccountUpdate {
	au.mutation.SetPrivateKey(s)
	return au
}

// SetNillablePrivateKey sets the "private_key" field if the given value is not nil.
func (au *AccountUpdate) SetNillablePrivateKey(s *string) *AccountUpdate {
	if s != nil {
		au.SetPrivateKey(*s)
	}
	return au
}

// ClearPrivateKey clears the value of the "private_key" field.
func (au *AccountUpdate) ClearPrivateKey() *AccountUpdate {
	au.mutation.ClearPrivateKey()
	return au
}

// SetWork sets the "work" field.
func (au *AccountUpdate) SetWork(b bool) *AccountUpdate {
	au.mutation.SetWork(b)
	return au
}

// SetNillableWork sets the "work" field if the given value is not nil.
func (au *AccountUpdate) SetNillableWork(b *bool) *AccountUpdate {
	if b != nil {
		au.SetWork(*b)
	}
	return au
}

// SetWallet sets the "wallet" edge to the Wallet entity.
func (au *AccountUpdate) SetWallet(w *Wallet) *AccountUpdate {
	return au.SetWalletID(w.ID)
}

// AddBlockIDs adds the "blocks" edge to the Block entity by IDs.
func (au *AccountUpdate) AddBlockIDs(ids ...uuid.UUID) *AccountUpdate {
	au.mutation.AddBlockIDs(ids...)
	return au
}

// AddBlocks adds the "blocks" edges to the Block entity.
func (au *AccountUpdate) AddBlocks(b ...*Block) *AccountUpdate {
	ids := make([]uuid.UUID, len(b))
	for i := range b {
		ids[i] = b[i].ID
	}
	return au.AddBlockIDs(ids...)
}

// Mutation returns the AccountMutation object of the builder.
func (au *AccountUpdate) Mutation() *AccountMutation {
	return au.mutation
}

// ClearWallet clears the "wallet" edge to the Wallet entity.
func (au *AccountUpdate) ClearWallet() *AccountUpdate {
	au.mutation.ClearWallet()
	return au
}

// ClearBlocks clears all "blocks" edges to the Block entity.
func (au *AccountUpdate) ClearBlocks() *AccountUpdate {
	au.mutation.ClearBlocks()
	return au
}

// RemoveBlockIDs removes the "blocks" edge to Block entities by IDs.
func (au *AccountUpdate) RemoveBlockIDs(ids ...uuid.UUID) *AccountUpdate {
	au.mutation.RemoveBlockIDs(ids...)
	return au
}

// RemoveBlocks removes "blocks" edges to Block entities.
func (au *AccountUpdate) RemoveBlocks(b ...*Block) *AccountUpdate {
	ids := make([]uuid.UUID, len(b))
	for i := range b {
		ids[i] = b[i].ID
	}
	return au.RemoveBlockIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (au *AccountUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(au.hooks) == 0 {
		if err = au.check(); err != nil {
			return 0, err
		}
		affected, err = au.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*AccountMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			if err = au.check(); err != nil {
				return 0, err
			}
			au.mutation = mutation
			affected, err = au.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(au.hooks) - 1; i >= 0; i-- {
			if au.hooks[i] == nil {
				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = au.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, au.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (au *AccountUpdate) check() error {
	if v, ok := au.mutation.Address(); ok {
		if err := account.AddressValidator(v); err != nil {
			return &ValidationError{Name: "address", err: fmt.Errorf(`ent: validator failed for field "Account.address": %w`, err)}
		}
	}
	if v, ok := au.mutation.PrivateKey(); ok {
		if err := account.PrivateKeyValidator(v); err != nil {
			return &ValidationError{Name: "private_key", err: fmt.Errorf(`ent: validator failed for field "Account.private_key": %w`, err)}
		}
	}
	if _, ok := au.mutation.WalletID(); au.mutation.WalletCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "Account.wallet"`)
	}
	return nil
}

func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   account.Table,
			Columns: account.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUUID,
				Column: account.FieldID,
			},
		},
	}
	if ps := au.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := au.mutation.Address(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: account.FieldAddress,
		})
	}
	if value, ok := au.mutation.AccountIndex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: account.FieldAccountIndex,
		})
	}
	if value, ok := au.mutation.AddedAccountIndex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: account.FieldAccountIndex,
		})
	}
	if au.mutation.AccountIndexCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Column: account.FieldAccountIndex,
		})
	}
	if value, ok := au.mutation.PrivateKey(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: account.FieldPrivateKey,
		})
	}
	if au.mutation.PrivateKeyCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Column: account.FieldPrivateKey,
		})
	}
	if value, ok := au.mutation.Work(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeBool,
			Value:  value,
			Column: account.FieldWork,
		})
	}
	if au.mutation.WalletCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   account.WalletTable,
			Columns: []string{account.WalletColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: wallet.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := au.mutation.WalletIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   account.WalletTable,
			Columns: []string{account.WalletColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: wallet.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if au.mutation.BlocksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := au.mutation.RemovedBlocksIDs(); len(nodes) > 0 && !au.mutation.BlocksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := au.mutation.BlocksIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		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, au.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	return n, nil
}

// AccountUpdateOne is the builder for updating a single Account entity.
type AccountUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *AccountMutation
}

// SetWalletID sets the "wallet_id" field.
func (auo *AccountUpdateOne) SetWalletID(u uuid.UUID) *AccountUpdateOne {
	auo.mutation.SetWalletID(u)
	return auo
}

// SetAddress sets the "address" field.
func (auo *AccountUpdateOne) SetAddress(s string) *AccountUpdateOne {
	auo.mutation.SetAddress(s)
	return auo
}

// SetAccountIndex sets the "account_index" field.
func (auo *AccountUpdateOne) SetAccountIndex(i int) *AccountUpdateOne {
	auo.mutation.ResetAccountIndex()
	auo.mutation.SetAccountIndex(i)
	return auo
}

// SetNillableAccountIndex sets the "account_index" field if the given value is not nil.
func (auo *AccountUpdateOne) SetNillableAccountIndex(i *int) *AccountUpdateOne {
	if i != nil {
		auo.SetAccountIndex(*i)
	}
	return auo
}

// AddAccountIndex adds i to the "account_index" field.
func (auo *AccountUpdateOne) AddAccountIndex(i int) *AccountUpdateOne {
	auo.mutation.AddAccountIndex(i)
	return auo
}

// ClearAccountIndex clears the value of the "account_index" field.
func (auo *AccountUpdateOne) ClearAccountIndex() *AccountUpdateOne {
	auo.mutation.ClearAccountIndex()
	return auo
}

// SetPrivateKey sets the "private_key" field.
func (auo *AccountUpdateOne) SetPrivateKey(s string) *AccountUpdateOne {
	auo.mutation.SetPrivateKey(s)
	return auo
}

// SetNillablePrivateKey sets the "private_key" field if the given value is not nil.
func (auo *AccountUpdateOne) SetNillablePrivateKey(s *string) *AccountUpdateOne {
	if s != nil {
		auo.SetPrivateKey(*s)
	}
	return auo
}

// ClearPrivateKey clears the value of the "private_key" field.
func (auo *AccountUpdateOne) ClearPrivateKey() *AccountUpdateOne {
	auo.mutation.ClearPrivateKey()
	return auo
}

// SetWork sets the "work" field.
func (auo *AccountUpdateOne) SetWork(b bool) *AccountUpdateOne {
	auo.mutation.SetWork(b)
	return auo
}

// SetNillableWork sets the "work" field if the given value is not nil.
func (auo *AccountUpdateOne) SetNillableWork(b *bool) *AccountUpdateOne {
	if b != nil {
		auo.SetWork(*b)
	}
	return auo
}

// SetWallet sets the "wallet" edge to the Wallet entity.
func (auo *AccountUpdateOne) SetWallet(w *Wallet) *AccountUpdateOne {
	return auo.SetWalletID(w.ID)
}

// AddBlockIDs adds the "blocks" edge to the Block entity by IDs.
func (auo *AccountUpdateOne) AddBlockIDs(ids ...uuid.UUID) *AccountUpdateOne {
	auo.mutation.AddBlockIDs(ids...)
	return auo
}

// AddBlocks adds the "blocks" edges to the Block entity.
func (auo *AccountUpdateOne) AddBlocks(b ...*Block) *AccountUpdateOne {
	ids := make([]uuid.UUID, len(b))
	for i := range b {
		ids[i] = b[i].ID
	}
	return auo.AddBlockIDs(ids...)
}

// Mutation returns the AccountMutation object of the builder.
func (auo *AccountUpdateOne) Mutation() *AccountMutation {
	return auo.mutation
}

// ClearWallet clears the "wallet" edge to the Wallet entity.
func (auo *AccountUpdateOne) ClearWallet() *AccountUpdateOne {
	auo.mutation.ClearWallet()
	return auo
}

// ClearBlocks clears all "blocks" edges to the Block entity.
func (auo *AccountUpdateOne) ClearBlocks() *AccountUpdateOne {
	auo.mutation.ClearBlocks()
	return auo
}

// RemoveBlockIDs removes the "blocks" edge to Block entities by IDs.
func (auo *AccountUpdateOne) RemoveBlockIDs(ids ...uuid.UUID) *AccountUpdateOne {
	auo.mutation.RemoveBlockIDs(ids...)
	return auo
}

// RemoveBlocks removes "blocks" edges to Block entities.
func (auo *AccountUpdateOne) RemoveBlocks(b ...*Block) *AccountUpdateOne {
	ids := make([]uuid.UUID, len(b))
	for i := range b {
		ids[i] = b[i].ID
	}
	return auo.RemoveBlockIDs(ids...)
}

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

// Save executes the query and returns the updated Account entity.
func (auo *AccountUpdateOne) Save(ctx context.Context) (*Account, error) {
	var (
		err  error
		node *Account
	)
	if len(auo.hooks) == 0 {
		if err = auo.check(); err != nil {
			return nil, err
		}
		node, err = auo.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*AccountMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			if err = auo.check(); err != nil {
				return nil, err
			}
			auo.mutation = mutation
			node, err = auo.sqlSave(ctx)
			mutation.done = true
			return node, err
		})
		for i := len(auo.hooks) - 1; i >= 0; i-- {
			if auo.hooks[i] == nil {
				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = auo.hooks[i](mut)
		}
		v, err := mut.Mutate(ctx, auo.mutation)
		if err != nil {
			return nil, err
		}
		nv, ok := v.(*Account)
		if !ok {
			return nil, fmt.Errorf("unexpected node type %T returned from AccountMutation", v)
		}
		node = nv
	}
	return node, err
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (auo *AccountUpdateOne) check() error {
	if v, ok := auo.mutation.Address(); ok {
		if err := account.AddressValidator(v); err != nil {
			return &ValidationError{Name: "address", err: fmt.Errorf(`ent: validator failed for field "Account.address": %w`, err)}
		}
	}
	if v, ok := auo.mutation.PrivateKey(); ok {
		if err := account.PrivateKeyValidator(v); err != nil {
			return &ValidationError{Name: "private_key", err: fmt.Errorf(`ent: validator failed for field "Account.private_key": %w`, err)}
		}
	}
	if _, ok := auo.mutation.WalletID(); auo.mutation.WalletCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "Account.wallet"`)
	}
	return nil
}

func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   account.Table,
			Columns: account.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUUID,
				Column: account.FieldID,
			},
		},
	}
	id, ok := auo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := auo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, account.FieldID)
		for _, f := range fields {
			if !account.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != account.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := auo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := auo.mutation.Address(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: account.FieldAddress,
		})
	}
	if value, ok := auo.mutation.AccountIndex(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: account.FieldAccountIndex,
		})
	}
	if value, ok := auo.mutation.AddedAccountIndex(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Value:  value,
			Column: account.FieldAccountIndex,
		})
	}
	if auo.mutation.AccountIndexCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeInt,
			Column: account.FieldAccountIndex,
		})
	}
	if value, ok := auo.mutation.PrivateKey(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: account.FieldPrivateKey,
		})
	}
	if auo.mutation.PrivateKeyCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Column: account.FieldPrivateKey,
		})
	}
	if value, ok := auo.mutation.Work(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeBool,
			Value:  value,
			Column: account.FieldWork,
		})
	}
	if auo.mutation.WalletCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   account.WalletTable,
			Columns: []string{account.WalletColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: wallet.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := auo.mutation.WalletIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   account.WalletTable,
			Columns: []string{account.WalletColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: wallet.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if auo.mutation.BlocksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := auo.mutation.RemovedBlocksIDs(); len(nodes) > 0 && !auo.mutation.BlocksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := auo.mutation.BlocksIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   account.BlocksTable,
			Columns: []string{account.BlocksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeUUID,
					Column: block.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Account{config: auo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{account.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	return _node, nil
}
