// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent/dialect/sql"
	"github.com/appditto/pippin_nano_wallet/libs/database/ent/wallet"
	"github.com/google/uuid"
)

// Wallet is the model entity for the Wallet schema.
type Wallet struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// Seed holds the value of the "seed" field.
	Seed string `json:"seed,omitempty"`
	// Representative holds the value of the "representative" field.
	Representative *string `json:"representative,omitempty"`
	// Encrypted holds the value of the "encrypted" field.
	Encrypted bool `json:"encrypted,omitempty"`
	// Work holds the value of the "work" field.
	Work bool `json:"work,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the WalletQuery when eager-loading is set.
	Edges WalletEdges `json:"edges"`
}

// WalletEdges holds the relations/edges for other nodes in the graph.
type WalletEdges struct {
	// Accounts holds the value of the accounts edge.
	Accounts []*Account `json:"accounts,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// AccountsOrErr returns the Accounts value or an error if the edge
// was not loaded in eager-loading.
func (e WalletEdges) AccountsOrErr() ([]*Account, error) {
	if e.loadedTypes[0] {
		return e.Accounts, nil
	}
	return nil, &NotLoadedError{edge: "accounts"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Wallet) scanValues(columns []string) ([]interface{}, error) {
	values := make([]interface{}, len(columns))
	for i := range columns {
		switch columns[i] {
		case wallet.FieldEncrypted, wallet.FieldWork:
			values[i] = new(sql.NullBool)
		case wallet.FieldSeed, wallet.FieldRepresentative:
			values[i] = new(sql.NullString)
		case wallet.FieldCreatedAt:
			values[i] = new(sql.NullTime)
		case wallet.FieldID:
			values[i] = new(uuid.UUID)
		default:
			return nil, fmt.Errorf("unexpected column %q for type Wallet", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Wallet fields.
func (w *Wallet) assignValues(columns []string, values []interface{}) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case wallet.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				w.ID = *value
			}
		case wallet.FieldSeed:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field seed", values[i])
			} else if value.Valid {
				w.Seed = value.String
			}
		case wallet.FieldRepresentative:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field representative", values[i])
			} else if value.Valid {
				w.Representative = new(string)
				*w.Representative = value.String
			}
		case wallet.FieldEncrypted:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field encrypted", values[i])
			} else if value.Valid {
				w.Encrypted = value.Bool
			}
		case wallet.FieldWork:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field work", values[i])
			} else if value.Valid {
				w.Work = value.Bool
			}
		case wallet.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				w.CreatedAt = value.Time
			}
		}
	}
	return nil
}

// QueryAccounts queries the "accounts" edge of the Wallet entity.
func (w *Wallet) QueryAccounts() *AccountQuery {
	return (&WalletClient{config: w.config}).QueryAccounts(w)
}

// Update returns a builder for updating this Wallet.
// Note that you need to call Wallet.Unwrap() before calling this method if this Wallet
// was returned from a transaction, and the transaction was committed or rolled back.
func (w *Wallet) Update() *WalletUpdateOne {
	return (&WalletClient{config: w.config}).UpdateOne(w)
}

// Unwrap unwraps the Wallet entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (w *Wallet) Unwrap() *Wallet {
	_tx, ok := w.config.driver.(*txDriver)
	if !ok {
		panic("ent: Wallet is not a transactional entity")
	}
	w.config.driver = _tx.drv
	return w
}

// String implements the fmt.Stringer.
func (w *Wallet) String() string {
	var builder strings.Builder
	builder.WriteString("Wallet(")
	builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
	builder.WriteString("seed=")
	builder.WriteString(w.Seed)
	builder.WriteString(", ")
	if v := w.Representative; v != nil {
		builder.WriteString("representative=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("encrypted=")
	builder.WriteString(fmt.Sprintf("%v", w.Encrypted))
	builder.WriteString(", ")
	builder.WriteString("work=")
	builder.WriteString(fmt.Sprintf("%v", w.Work))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(w.CreatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// Wallets is a parsable slice of Wallet.
type Wallets []*Wallet

func (w Wallets) config(cfg config) {
	for _i := range w {
		w[_i].config = cfg
	}
}
