// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"sync"
	"time"

	"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"

	"entgo.io/ent"
)

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeAccount = "Account"
	TypeBlock   = "Block"
	TypeWallet  = "Wallet"
)

// AccountMutation represents an operation that mutates the Account nodes in the graph.
type AccountMutation struct {
	config
	op               Op
	typ              string
	id               *uuid.UUID
	address          *string
	account_index    *int
	addaccount_index *int
	private_key      *string
	work             *bool
	created_at       *time.Time
	clearedFields    map[string]struct{}
	wallet           *uuid.UUID
	clearedwallet    bool
	blocks           map[uuid.UUID]struct{}
	removedblocks    map[uuid.UUID]struct{}
	clearedblocks    bool
	done             bool
	oldValue         func(context.Context) (*Account, error)
	predicates       []predicate.Account
}

var _ ent.Mutation = (*AccountMutation)(nil)

// accountOption allows management of the mutation configuration using functional options.
type accountOption func(*AccountMutation)

// newAccountMutation creates new mutation for the Account entity.
func newAccountMutation(c config, op Op, opts ...accountOption) *AccountMutation {
	m := &AccountMutation{
		config:        c,
		op:            op,
		typ:           TypeAccount,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAccountID sets the ID field of the mutation.
func withAccountID(id uuid.UUID) accountOption {
	return func(m *AccountMutation) {
		var (
			err   error
			once  sync.Once
			value *Account
		)
		m.oldValue = func(ctx context.Context) (*Account, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Account.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAccount sets the old Account of the mutation.
func withAccount(node *Account) accountOption {
	return func(m *AccountMutation) {
		m.oldValue = func(context.Context) (*Account, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m AccountMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m AccountMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Account entities.
func (m *AccountMutation) SetID(id uuid.UUID) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *AccountMutation) ID() (id uuid.UUID, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *AccountMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Account.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetWalletID sets the "wallet_id" field.
func (m *AccountMutation) SetWalletID(u uuid.UUID) {
	m.wallet = &u
}

// WalletID returns the value of the "wallet_id" field in the mutation.
func (m *AccountMutation) WalletID() (r uuid.UUID, exists bool) {
	v := m.wallet
	if v == nil {
		return
	}
	return *v, true
}

// OldWalletID returns the old "wallet_id" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldWalletID(ctx context.Context) (v uuid.UUID, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWalletID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWalletID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWalletID: %w", err)
	}
	return oldValue.WalletID, nil
}

// ResetWalletID resets all changes to the "wallet_id" field.
func (m *AccountMutation) ResetWalletID() {
	m.wallet = nil
}

// SetAddress sets the "address" field.
func (m *AccountMutation) SetAddress(s string) {
	m.address = &s
}

// Address returns the value of the "address" field in the mutation.
func (m *AccountMutation) Address() (r string, exists bool) {
	v := m.address
	if v == nil {
		return
	}
	return *v, true
}

// OldAddress returns the old "address" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldAddress(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAddress is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAddress requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAddress: %w", err)
	}
	return oldValue.Address, nil
}

// ResetAddress resets all changes to the "address" field.
func (m *AccountMutation) ResetAddress() {
	m.address = nil
}

// SetAccountIndex sets the "account_index" field.
func (m *AccountMutation) SetAccountIndex(i int) {
	m.account_index = &i
	m.addaccount_index = nil
}

// AccountIndex returns the value of the "account_index" field in the mutation.
func (m *AccountMutation) AccountIndex() (r int, exists bool) {
	v := m.account_index
	if v == nil {
		return
	}
	return *v, true
}

// OldAccountIndex returns the old "account_index" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldAccountIndex(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAccountIndex is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAccountIndex requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAccountIndex: %w", err)
	}
	return oldValue.AccountIndex, nil
}

// AddAccountIndex adds i to the "account_index" field.
func (m *AccountMutation) AddAccountIndex(i int) {
	if m.addaccount_index != nil {
		*m.addaccount_index += i
	} else {
		m.addaccount_index = &i
	}
}

// AddedAccountIndex returns the value that was added to the "account_index" field in this mutation.
func (m *AccountMutation) AddedAccountIndex() (r int, exists bool) {
	v := m.addaccount_index
	if v == nil {
		return
	}
	return *v, true
}

// ClearAccountIndex clears the value of the "account_index" field.
func (m *AccountMutation) ClearAccountIndex() {
	m.account_index = nil
	m.addaccount_index = nil
	m.clearedFields[account.FieldAccountIndex] = struct{}{}
}

// AccountIndexCleared returns if the "account_index" field was cleared in this mutation.
func (m *AccountMutation) AccountIndexCleared() bool {
	_, ok := m.clearedFields[account.FieldAccountIndex]
	return ok
}

// ResetAccountIndex resets all changes to the "account_index" field.
func (m *AccountMutation) ResetAccountIndex() {
	m.account_index = nil
	m.addaccount_index = nil
	delete(m.clearedFields, account.FieldAccountIndex)
}

// SetPrivateKey sets the "private_key" field.
func (m *AccountMutation) SetPrivateKey(s string) {
	m.private_key = &s
}

// PrivateKey returns the value of the "private_key" field in the mutation.
func (m *AccountMutation) PrivateKey() (r string, exists bool) {
	v := m.private_key
	if v == nil {
		return
	}
	return *v, true
}

// OldPrivateKey returns the old "private_key" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldPrivateKey(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPrivateKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPrivateKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPrivateKey: %w", err)
	}
	return oldValue.PrivateKey, nil
}

// ClearPrivateKey clears the value of the "private_key" field.
func (m *AccountMutation) ClearPrivateKey() {
	m.private_key = nil
	m.clearedFields[account.FieldPrivateKey] = struct{}{}
}

// PrivateKeyCleared returns if the "private_key" field was cleared in this mutation.
func (m *AccountMutation) PrivateKeyCleared() bool {
	_, ok := m.clearedFields[account.FieldPrivateKey]
	return ok
}

// ResetPrivateKey resets all changes to the "private_key" field.
func (m *AccountMutation) ResetPrivateKey() {
	m.private_key = nil
	delete(m.clearedFields, account.FieldPrivateKey)
}

// SetWork sets the "work" field.
func (m *AccountMutation) SetWork(b bool) {
	m.work = &b
}

// Work returns the value of the "work" field in the mutation.
func (m *AccountMutation) Work() (r bool, exists bool) {
	v := m.work
	if v == nil {
		return
	}
	return *v, true
}

// OldWork returns the old "work" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldWork(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWork is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWork requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWork: %w", err)
	}
	return oldValue.Work, nil
}

// ResetWork resets all changes to the "work" field.
func (m *AccountMutation) ResetWork() {
	m.work = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *AccountMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AccountMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedAt returns the old "created_at" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
	}
	return oldValue.CreatedAt, nil
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *AccountMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearWallet clears the "wallet" edge to the Wallet entity.
func (m *AccountMutation) ClearWallet() {
	m.clearedwallet = true
}

// WalletCleared reports if the "wallet" edge to the Wallet entity was cleared.
func (m *AccountMutation) WalletCleared() bool {
	return m.clearedwallet
}

// WalletIDs returns the "wallet" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// WalletID instead. It exists only for internal usage by the builders.
func (m *AccountMutation) WalletIDs() (ids []uuid.UUID) {
	if id := m.wallet; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetWallet resets all changes to the "wallet" edge.
func (m *AccountMutation) ResetWallet() {
	m.wallet = nil
	m.clearedwallet = false
}

// AddBlockIDs adds the "blocks" edge to the Block entity by ids.
func (m *AccountMutation) AddBlockIDs(ids ...uuid.UUID) {
	if m.blocks == nil {
		m.blocks = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.blocks[ids[i]] = struct{}{}
	}
}

// ClearBlocks clears the "blocks" edge to the Block entity.
func (m *AccountMutation) ClearBlocks() {
	m.clearedblocks = true
}

// BlocksCleared reports if the "blocks" edge to the Block entity was cleared.
func (m *AccountMutation) BlocksCleared() bool {
	return m.clearedblocks
}

// RemoveBlockIDs removes the "blocks" edge to the Block entity by IDs.
func (m *AccountMutation) RemoveBlockIDs(ids ...uuid.UUID) {
	if m.removedblocks == nil {
		m.removedblocks = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.blocks, ids[i])
		m.removedblocks[ids[i]] = struct{}{}
	}
}

// RemovedBlocks returns the removed IDs of the "blocks" edge to the Block entity.
func (m *AccountMutation) RemovedBlocksIDs() (ids []uuid.UUID) {
	for id := range m.removedblocks {
		ids = append(ids, id)
	}
	return
}

// BlocksIDs returns the "blocks" edge IDs in the mutation.
func (m *AccountMutation) BlocksIDs() (ids []uuid.UUID) {
	for id := range m.blocks {
		ids = append(ids, id)
	}
	return
}

// ResetBlocks resets all changes to the "blocks" edge.
func (m *AccountMutation) ResetBlocks() {
	m.blocks = nil
	m.clearedblocks = false
	m.removedblocks = nil
}

// Where appends a list predicates to the AccountMutation builder.
func (m *AccountMutation) Where(ps ...predicate.Account) {
	m.predicates = append(m.predicates, ps...)
}

// Op returns the operation name.
func (m *AccountMutation) Op() Op {
	return m.op
}

// Type returns the node type of this mutation (Account).
func (m *AccountMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *AccountMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.wallet != nil {
		fields = append(fields, account.FieldWalletID)
	}
	if m.address != nil {
		fields = append(fields, account.FieldAddress)
	}
	if m.account_index != nil {
		fields = append(fields, account.FieldAccountIndex)
	}
	if m.private_key != nil {
		fields = append(fields, account.FieldPrivateKey)
	}
	if m.work != nil {
		fields = append(fields, account.FieldWork)
	}
	if m.created_at != nil {
		fields = append(fields, account.FieldCreatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *AccountMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case account.FieldWalletID:
		return m.WalletID()
	case account.FieldAddress:
		return m.Address()
	case account.FieldAccountIndex:
		return m.AccountIndex()
	case account.FieldPrivateKey:
		return m.PrivateKey()
	case account.FieldWork:
		return m.Work()
	case account.FieldCreatedAt:
		return m.CreatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *AccountMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case account.FieldWalletID:
		return m.OldWalletID(ctx)
	case account.FieldAddress:
		return m.OldAddress(ctx)
	case account.FieldAccountIndex:
		return m.OldAccountIndex(ctx)
	case account.FieldPrivateKey:
		return m.OldPrivateKey(ctx)
	case account.FieldWork:
		return m.OldWork(ctx)
	case account.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Account field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AccountMutation) SetField(name string, value ent.Value) error {
	switch name {
	case account.FieldWalletID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWalletID(v)
		return nil
	case account.FieldAddress:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAddress(v)
		return nil
	case account.FieldAccountIndex:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAccountIndex(v)
		return nil
	case account.FieldPrivateKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrivateKey(v)
		return nil
	case account.FieldWork:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWork(v)
		return nil
	case account.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Account field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AccountMutation) AddedFields() []string {
	var fields []string
	if m.addaccount_index != nil {
		fields = append(fields, account.FieldAccountIndex)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *AccountMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case account.FieldAccountIndex:
		return m.AddedAccountIndex()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AccountMutation) AddField(name string, value ent.Value) error {
	switch name {
	case account.FieldAccountIndex:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddAccountIndex(v)
		return nil
	}
	return fmt.Errorf("unknown Account numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AccountMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(account.FieldAccountIndex) {
		fields = append(fields, account.FieldAccountIndex)
	}
	if m.FieldCleared(account.FieldPrivateKey) {
		fields = append(fields, account.FieldPrivateKey)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AccountMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *AccountMutation) ClearField(name string) error {
	switch name {
	case account.FieldAccountIndex:
		m.ClearAccountIndex()
		return nil
	case account.FieldPrivateKey:
		m.ClearPrivateKey()
		return nil
	}
	return fmt.Errorf("unknown Account nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *AccountMutation) ResetField(name string) error {
	switch name {
	case account.FieldWalletID:
		m.ResetWalletID()
		return nil
	case account.FieldAddress:
		m.ResetAddress()
		return nil
	case account.FieldAccountIndex:
		m.ResetAccountIndex()
		return nil
	case account.FieldPrivateKey:
		m.ResetPrivateKey()
		return nil
	case account.FieldWork:
		m.ResetWork()
		return nil
	case account.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Account field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AccountMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.wallet != nil {
		edges = append(edges, account.EdgeWallet)
	}
	if m.blocks != nil {
		edges = append(edges, account.EdgeBlocks)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AccountMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case account.EdgeWallet:
		if id := m.wallet; id != nil {
			return []ent.Value{*id}
		}
	case account.EdgeBlocks:
		ids := make([]ent.Value, 0, len(m.blocks))
		for id := range m.blocks {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AccountMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	if m.removedblocks != nil {
		edges = append(edges, account.EdgeBlocks)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AccountMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case account.EdgeBlocks:
		ids := make([]ent.Value, 0, len(m.removedblocks))
		for id := range m.removedblocks {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AccountMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedwallet {
		edges = append(edges, account.EdgeWallet)
	}
	if m.clearedblocks {
		edges = append(edges, account.EdgeBlocks)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AccountMutation) EdgeCleared(name string) bool {
	switch name {
	case account.EdgeWallet:
		return m.clearedwallet
	case account.EdgeBlocks:
		return m.clearedblocks
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *AccountMutation) ClearEdge(name string) error {
	switch name {
	case account.EdgeWallet:
		m.ClearWallet()
		return nil
	}
	return fmt.Errorf("unknown Account unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *AccountMutation) ResetEdge(name string) error {
	switch name {
	case account.EdgeWallet:
		m.ResetWallet()
		return nil
	case account.EdgeBlocks:
		m.ResetBlocks()
		return nil
	}
	return fmt.Errorf("unknown Account edge %s", name)
}

// BlockMutation represents an operation that mutates the Block nodes in the graph.
type BlockMutation struct {
	config
	op             Op
	typ            string
	id             *uuid.UUID
	block_hash     *string
	block          *map[string]interface{}
	send_id        *string
	subtype        *string
	created_at     *time.Time
	clearedFields  map[string]struct{}
	account        *uuid.UUID
	clearedaccount bool
	done           bool
	oldValue       func(context.Context) (*Block, error)
	predicates     []predicate.Block
}

var _ ent.Mutation = (*BlockMutation)(nil)

// blockOption allows management of the mutation configuration using functional options.
type blockOption func(*BlockMutation)

// newBlockMutation creates new mutation for the Block entity.
func newBlockMutation(c config, op Op, opts ...blockOption) *BlockMutation {
	m := &BlockMutation{
		config:        c,
		op:            op,
		typ:           TypeBlock,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withBlockID sets the ID field of the mutation.
func withBlockID(id uuid.UUID) blockOption {
	return func(m *BlockMutation) {
		var (
			err   error
			once  sync.Once
			value *Block
		)
		m.oldValue = func(ctx context.Context) (*Block, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Block.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withBlock sets the old Block of the mutation.
func withBlock(node *Block) blockOption {
	return func(m *BlockMutation) {
		m.oldValue = func(context.Context) (*Block, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m BlockMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m BlockMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Block entities.
func (m *BlockMutation) SetID(id uuid.UUID) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *BlockMutation) ID() (id uuid.UUID, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *BlockMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Block.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetAccountID sets the "account_id" field.
func (m *BlockMutation) SetAccountID(u uuid.UUID) {
	m.account = &u
}

// AccountID returns the value of the "account_id" field in the mutation.
func (m *BlockMutation) AccountID() (r uuid.UUID, exists bool) {
	v := m.account
	if v == nil {
		return
	}
	return *v, true
}

// OldAccountID returns the old "account_id" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldAccountID(ctx context.Context) (v *uuid.UUID, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAccountID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAccountID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAccountID: %w", err)
	}
	return oldValue.AccountID, nil
}

// ClearAccountID clears the value of the "account_id" field.
func (m *BlockMutation) ClearAccountID() {
	m.account = nil
	m.clearedFields[block.FieldAccountID] = struct{}{}
}

// AccountIDCleared returns if the "account_id" field was cleared in this mutation.
func (m *BlockMutation) AccountIDCleared() bool {
	_, ok := m.clearedFields[block.FieldAccountID]
	return ok
}

// ResetAccountID resets all changes to the "account_id" field.
func (m *BlockMutation) ResetAccountID() {
	m.account = nil
	delete(m.clearedFields, block.FieldAccountID)
}

// SetBlockHash sets the "block_hash" field.
func (m *BlockMutation) SetBlockHash(s string) {
	m.block_hash = &s
}

// BlockHash returns the value of the "block_hash" field in the mutation.
func (m *BlockMutation) BlockHash() (r string, exists bool) {
	v := m.block_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldBlockHash returns the old "block_hash" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldBlockHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBlockHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBlockHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBlockHash: %w", err)
	}
	return oldValue.BlockHash, nil
}

// ResetBlockHash resets all changes to the "block_hash" field.
func (m *BlockMutation) ResetBlockHash() {
	m.block_hash = nil
}

// SetBlock sets the "block" field.
func (m *BlockMutation) SetBlock(value map[string]interface{}) {
	m.block = &value
}

// Block returns the value of the "block" field in the mutation.
func (m *BlockMutation) Block() (r map[string]interface{}, exists bool) {
	v := m.block
	if v == nil {
		return
	}
	return *v, true
}

// OldBlock returns the old "block" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldBlock(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBlock is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBlock requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBlock: %w", err)
	}
	return oldValue.Block, nil
}

// ResetBlock resets all changes to the "block" field.
func (m *BlockMutation) ResetBlock() {
	m.block = nil
}

// SetSendID sets the "send_id" field.
func (m *BlockMutation) SetSendID(s string) {
	m.send_id = &s
}

// SendID returns the value of the "send_id" field in the mutation.
func (m *BlockMutation) SendID() (r string, exists bool) {
	v := m.send_id
	if v == nil {
		return
	}
	return *v, true
}

// OldSendID returns the old "send_id" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldSendID(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSendID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSendID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSendID: %w", err)
	}
	return oldValue.SendID, nil
}

// ClearSendID clears the value of the "send_id" field.
func (m *BlockMutation) ClearSendID() {
	m.send_id = nil
	m.clearedFields[block.FieldSendID] = struct{}{}
}

// SendIDCleared returns if the "send_id" field was cleared in this mutation.
func (m *BlockMutation) SendIDCleared() bool {
	_, ok := m.clearedFields[block.FieldSendID]
	return ok
}

// ResetSendID resets all changes to the "send_id" field.
func (m *BlockMutation) ResetSendID() {
	m.send_id = nil
	delete(m.clearedFields, block.FieldSendID)
}

// SetSubtype sets the "subtype" field.
func (m *BlockMutation) SetSubtype(s string) {
	m.subtype = &s
}

// Subtype returns the value of the "subtype" field in the mutation.
func (m *BlockMutation) Subtype() (r string, exists bool) {
	v := m.subtype
	if v == nil {
		return
	}
	return *v, true
}

// OldSubtype returns the old "subtype" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldSubtype(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSubtype is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSubtype requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSubtype: %w", err)
	}
	return oldValue.Subtype, nil
}

// ResetSubtype resets all changes to the "subtype" field.
func (m *BlockMutation) ResetSubtype() {
	m.subtype = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *BlockMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *BlockMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedAt returns the old "created_at" field's value of the Block entity.
// If the Block object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *BlockMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
	}
	return oldValue.CreatedAt, nil
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *BlockMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearAccount clears the "account" edge to the Account entity.
func (m *BlockMutation) ClearAccount() {
	m.clearedaccount = true
}

// AccountCleared reports if the "account" edge to the Account entity was cleared.
func (m *BlockMutation) AccountCleared() bool {
	return m.AccountIDCleared() || m.clearedaccount
}

// AccountIDs returns the "account" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountID instead. It exists only for internal usage by the builders.
func (m *BlockMutation) AccountIDs() (ids []uuid.UUID) {
	if id := m.account; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAccount resets all changes to the "account" edge.
func (m *BlockMutation) ResetAccount() {
	m.account = nil
	m.clearedaccount = false
}

// Where appends a list predicates to the BlockMutation builder.
func (m *BlockMutation) Where(ps ...predicate.Block) {
	m.predicates = append(m.predicates, ps...)
}

// Op returns the operation name.
func (m *BlockMutation) Op() Op {
	return m.op
}

// Type returns the node type of this mutation (Block).
func (m *BlockMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *BlockMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.account != nil {
		fields = append(fields, block.FieldAccountID)
	}
	if m.block_hash != nil {
		fields = append(fields, block.FieldBlockHash)
	}
	if m.block != nil {
		fields = append(fields, block.FieldBlock)
	}
	if m.send_id != nil {
		fields = append(fields, block.FieldSendID)
	}
	if m.subtype != nil {
		fields = append(fields, block.FieldSubtype)
	}
	if m.created_at != nil {
		fields = append(fields, block.FieldCreatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *BlockMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case block.FieldAccountID:
		return m.AccountID()
	case block.FieldBlockHash:
		return m.BlockHash()
	case block.FieldBlock:
		return m.Block()
	case block.FieldSendID:
		return m.SendID()
	case block.FieldSubtype:
		return m.Subtype()
	case block.FieldCreatedAt:
		return m.CreatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *BlockMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case block.FieldAccountID:
		return m.OldAccountID(ctx)
	case block.FieldBlockHash:
		return m.OldBlockHash(ctx)
	case block.FieldBlock:
		return m.OldBlock(ctx)
	case block.FieldSendID:
		return m.OldSendID(ctx)
	case block.FieldSubtype:
		return m.OldSubtype(ctx)
	case block.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Block field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *BlockMutation) SetField(name string, value ent.Value) error {
	switch name {
	case block.FieldAccountID:
		v, ok := value.(uuid.UUID)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAccountID(v)
		return nil
	case block.FieldBlockHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBlockHash(v)
		return nil
	case block.FieldBlock:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBlock(v)
		return nil
	case block.FieldSendID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSendID(v)
		return nil
	case block.FieldSubtype:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubtype(v)
		return nil
	case block.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Block field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *BlockMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *BlockMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *BlockMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Block numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *BlockMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(block.FieldAccountID) {
		fields = append(fields, block.FieldAccountID)
	}
	if m.FieldCleared(block.FieldSendID) {
		fields = append(fields, block.FieldSendID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *BlockMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *BlockMutation) ClearField(name string) error {
	switch name {
	case block.FieldAccountID:
		m.ClearAccountID()
		return nil
	case block.FieldSendID:
		m.ClearSendID()
		return nil
	}
	return fmt.Errorf("unknown Block nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *BlockMutation) ResetField(name string) error {
	switch name {
	case block.FieldAccountID:
		m.ResetAccountID()
		return nil
	case block.FieldBlockHash:
		m.ResetBlockHash()
		return nil
	case block.FieldBlock:
		m.ResetBlock()
		return nil
	case block.FieldSendID:
		m.ResetSendID()
		return nil
	case block.FieldSubtype:
		m.ResetSubtype()
		return nil
	case block.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Block field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *BlockMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.account != nil {
		edges = append(edges, block.EdgeAccount)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *BlockMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case block.EdgeAccount:
		if id := m.account; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *BlockMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *BlockMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *BlockMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedaccount {
		edges = append(edges, block.EdgeAccount)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *BlockMutation) EdgeCleared(name string) bool {
	switch name {
	case block.EdgeAccount:
		return m.clearedaccount
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *BlockMutation) ClearEdge(name string) error {
	switch name {
	case block.EdgeAccount:
		m.ClearAccount()
		return nil
	}
	return fmt.Errorf("unknown Block unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *BlockMutation) ResetEdge(name string) error {
	switch name {
	case block.EdgeAccount:
		m.ResetAccount()
		return nil
	}
	return fmt.Errorf("unknown Block edge %s", name)
}

// WalletMutation represents an operation that mutates the Wallet nodes in the graph.
type WalletMutation struct {
	config
	op              Op
	typ             string
	id              *uuid.UUID
	seed            *string
	representative  *string
	encrypted       *bool
	work            *bool
	created_at      *time.Time
	clearedFields   map[string]struct{}
	accounts        map[uuid.UUID]struct{}
	removedaccounts map[uuid.UUID]struct{}
	clearedaccounts bool
	done            bool
	oldValue        func(context.Context) (*Wallet, error)
	predicates      []predicate.Wallet
}

var _ ent.Mutation = (*WalletMutation)(nil)

// walletOption allows management of the mutation configuration using functional options.
type walletOption func(*WalletMutation)

// newWalletMutation creates new mutation for the Wallet entity.
func newWalletMutation(c config, op Op, opts ...walletOption) *WalletMutation {
	m := &WalletMutation{
		config:        c,
		op:            op,
		typ:           TypeWallet,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withWalletID sets the ID field of the mutation.
func withWalletID(id uuid.UUID) walletOption {
	return func(m *WalletMutation) {
		var (
			err   error
			once  sync.Once
			value *Wallet
		)
		m.oldValue = func(ctx context.Context) (*Wallet, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Wallet.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withWallet sets the old Wallet of the mutation.
func withWallet(node *Wallet) walletOption {
	return func(m *WalletMutation) {
		m.oldValue = func(context.Context) (*Wallet, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m WalletMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m WalletMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Wallet entities.
func (m *WalletMutation) SetID(id uuid.UUID) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *WalletMutation) ID() (id uuid.UUID, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *WalletMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uuid.UUID{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Wallet.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetSeed sets the "seed" field.
func (m *WalletMutation) SetSeed(s string) {
	m.seed = &s
}

// Seed returns the value of the "seed" field in the mutation.
func (m *WalletMutation) Seed() (r string, exists bool) {
	v := m.seed
	if v == nil {
		return
	}
	return *v, true
}

// OldSeed returns the old "seed" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldSeed(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSeed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSeed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSeed: %w", err)
	}
	return oldValue.Seed, nil
}

// ResetSeed resets all changes to the "seed" field.
func (m *WalletMutation) ResetSeed() {
	m.seed = nil
}

// SetRepresentative sets the "representative" field.
func (m *WalletMutation) SetRepresentative(s string) {
	m.representative = &s
}

// Representative returns the value of the "representative" field in the mutation.
func (m *WalletMutation) Representative() (r string, exists bool) {
	v := m.representative
	if v == nil {
		return
	}
	return *v, true
}

// OldRepresentative returns the old "representative" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldRepresentative(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRepresentative is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRepresentative requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRepresentative: %w", err)
	}
	return oldValue.Representative, nil
}

// ClearRepresentative clears the value of the "representative" field.
func (m *WalletMutation) ClearRepresentative() {
	m.representative = nil
	m.clearedFields[wallet.FieldRepresentative] = struct{}{}
}

// RepresentativeCleared returns if the "representative" field was cleared in this mutation.
func (m *WalletMutation) RepresentativeCleared() bool {
	_, ok := m.clearedFields[wallet.FieldRepresentative]
	return ok
}

// ResetRepresentative resets all changes to the "representative" field.
func (m *WalletMutation) ResetRepresentative() {
	m.representative = nil
	delete(m.clearedFields, wallet.FieldRepresentative)
}

// SetEncrypted sets the "encrypted" field.
func (m *WalletMutation) SetEncrypted(b bool) {
	m.encrypted = &b
}

// Encrypted returns the value of the "encrypted" field in the mutation.
func (m *WalletMutation) Encrypted() (r bool, exists bool) {
	v := m.encrypted
	if v == nil {
		return
	}
	return *v, true
}

// OldEncrypted returns the old "encrypted" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldEncrypted(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEncrypted is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEncrypted requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEncrypted: %w", err)
	}
	return oldValue.Encrypted, nil
}

// ResetEncrypted resets all changes to the "encrypted" field.
func (m *WalletMutation) ResetEncrypted() {
	m.encrypted = nil
}

// SetWork sets the "work" field.
func (m *WalletMutation) SetWork(b bool) {
	m.work = &b
}

// Work returns the value of the "work" field in the mutation.
func (m *WalletMutation) Work() (r bool, exists bool) {
	v := m.work
	if v == nil {
		return
	}
	return *v, true
}

// OldWork returns the old "work" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldWork(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWork is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWork requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWork: %w", err)
	}
	return oldValue.Work, nil
}

// ResetWork resets all changes to the "work" field.
func (m *WalletMutation) ResetWork() {
	m.work = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *WalletMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *WalletMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedAt returns the old "created_at" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
	}
	return oldValue.CreatedAt, nil
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *WalletMutation) ResetCreatedAt() {
	m.created_at = nil
}

// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *WalletMutation) AddAccountIDs(ids ...uuid.UUID) {
	if m.accounts == nil {
		m.accounts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		m.accounts[ids[i]] = struct{}{}
	}
}

// ClearAccounts clears the "accounts" edge to the Account entity.
func (m *WalletMutation) ClearAccounts() {
	m.clearedaccounts = true
}

// AccountsCleared reports if the "accounts" edge to the Account entity was cleared.
func (m *WalletMutation) AccountsCleared() bool {
	return m.clearedaccounts
}

// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs.
func (m *WalletMutation) RemoveAccountIDs(ids ...uuid.UUID) {
	if m.removedaccounts == nil {
		m.removedaccounts = make(map[uuid.UUID]struct{})
	}
	for i := range ids {
		delete(m.accounts, ids[i])
		m.removedaccounts[ids[i]] = struct{}{}
	}
}

// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity.
func (m *WalletMutation) RemovedAccountsIDs() (ids []uuid.UUID) {
	for id := range m.removedaccounts {
		ids = append(ids, id)
	}
	return
}

// AccountsIDs returns the "accounts" edge IDs in the mutation.
func (m *WalletMutation) AccountsIDs() (ids []uuid.UUID) {
	for id := range m.accounts {
		ids = append(ids, id)
	}
	return
}

// ResetAccounts resets all changes to the "accounts" edge.
func (m *WalletMutation) ResetAccounts() {
	m.accounts = nil
	m.clearedaccounts = false
	m.removedaccounts = nil
}

// Where appends a list predicates to the WalletMutation builder.
func (m *WalletMutation) Where(ps ...predicate.Wallet) {
	m.predicates = append(m.predicates, ps...)
}

// Op returns the operation name.
func (m *WalletMutation) Op() Op {
	return m.op
}

// Type returns the node type of this mutation (Wallet).
func (m *WalletMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *WalletMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.seed != nil {
		fields = append(fields, wallet.FieldSeed)
	}
	if m.representative != nil {
		fields = append(fields, wallet.FieldRepresentative)
	}
	if m.encrypted != nil {
		fields = append(fields, wallet.FieldEncrypted)
	}
	if m.work != nil {
		fields = append(fields, wallet.FieldWork)
	}
	if m.created_at != nil {
		fields = append(fields, wallet.FieldCreatedAt)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *WalletMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case wallet.FieldSeed:
		return m.Seed()
	case wallet.FieldRepresentative:
		return m.Representative()
	case wallet.FieldEncrypted:
		return m.Encrypted()
	case wallet.FieldWork:
		return m.Work()
	case wallet.FieldCreatedAt:
		return m.CreatedAt()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case wallet.FieldSeed:
		return m.OldSeed(ctx)
	case wallet.FieldRepresentative:
		return m.OldRepresentative(ctx)
	case wallet.FieldEncrypted:
		return m.OldEncrypted(ctx)
	case wallet.FieldWork:
		return m.OldWork(ctx)
	case wallet.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Wallet field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletMutation) SetField(name string, value ent.Value) error {
	switch name {
	case wallet.FieldSeed:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSeed(v)
		return nil
	case wallet.FieldRepresentative:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRepresentative(v)
		return nil
	case wallet.FieldEncrypted:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEncrypted(v)
		return nil
	case wallet.FieldWork:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWork(v)
		return nil
	case wallet.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Wallet field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *WalletMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Wallet numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WalletMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(wallet.FieldRepresentative) {
		fields = append(fields, wallet.FieldRepresentative)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WalletMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *WalletMutation) ClearField(name string) error {
	switch name {
	case wallet.FieldRepresentative:
		m.ClearRepresentative()
		return nil
	}
	return fmt.Errorf("unknown Wallet nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *WalletMutation) ResetField(name string) error {
	switch name {
	case wallet.FieldSeed:
		m.ResetSeed()
		return nil
	case wallet.FieldRepresentative:
		m.ResetRepresentative()
		return nil
	case wallet.FieldEncrypted:
		m.ResetEncrypted()
		return nil
	case wallet.FieldWork:
		m.ResetWork()
		return nil
	case wallet.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown Wallet field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WalletMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.accounts != nil {
		edges = append(edges, wallet.EdgeAccounts)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WalletMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case wallet.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.accounts))
		for id := range m.accounts {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WalletMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedaccounts != nil {
		edges = append(edges, wallet.EdgeAccounts)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *WalletMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case wallet.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.removedaccounts))
		for id := range m.removedaccounts {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WalletMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedaccounts {
		edges = append(edges, wallet.EdgeAccounts)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WalletMutation) EdgeCleared(name string) bool {
	switch name {
	case wallet.EdgeAccounts:
		return m.clearedaccounts
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *WalletMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Wallet unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *WalletMutation) ResetEdge(name string) error {
	switch name {
	case wallet.EdgeAccounts:
		m.ResetAccounts()
		return nil
	}
	return fmt.Errorf("unknown Wallet edge %s", name)
}
