// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/common/keys"
	"github.com/lightsparkdev/spark/so/ent/l1tokencreate"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
	"github.com/lightsparkdev/spark/so/ent/tokencreate"
)

// TokenCreate is the model entity for the TokenCreate schema.
type TokenCreate struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreateTime holds the value of the "create_time" field.
	CreateTime time.Time `json:"create_time,omitempty"`
	// UpdateTime holds the value of the "update_time" field.
	UpdateTime time.Time `json:"update_time,omitempty"`
	// IssuerPublicKey holds the value of the "issuer_public_key" field.
	IssuerPublicKey keys.Public `json:"issuer_public_key,omitempty"`
	// TokenName holds the value of the "token_name" field.
	TokenName string `json:"token_name,omitempty"`
	// TokenTicker holds the value of the "token_ticker" field.
	TokenTicker string `json:"token_ticker,omitempty"`
	// Decimals holds the value of the "decimals" field.
	Decimals uint8 `json:"decimals,omitempty"`
	// MaxSupply holds the value of the "max_supply" field.
	MaxSupply []byte `json:"max_supply,omitempty"`
	// IsFreezable holds the value of the "is_freezable" field.
	IsFreezable bool `json:"is_freezable,omitempty"`
	// Network holds the value of the "network" field.
	Network schematype.Network `json:"network,omitempty"`
	// TokenIdentifier holds the value of the "token_identifier" field.
	TokenIdentifier []byte `json:"token_identifier,omitempty"`
	// IssuerSignature holds the value of the "issuer_signature" field.
	IssuerSignature []byte `json:"issuer_signature,omitempty"`
	// OperatorSpecificIssuerSignature holds the value of the "operator_specific_issuer_signature" field.
	OperatorSpecificIssuerSignature []byte `json:"operator_specific_issuer_signature,omitempty"`
	// CreationEntityPublicKey holds the value of the "creation_entity_public_key" field.
	CreationEntityPublicKey keys.Public `json:"creation_entity_public_key,omitempty"`
	// WalletProvidedTimestamp holds the value of the "wallet_provided_timestamp" field.
	//
	// Deprecated: Field "wallet_provided_timestamp" was marked as deprecated in the schema.
	WalletProvidedTimestamp uint64 `json:"wallet_provided_timestamp,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the TokenCreateQuery when eager-loading is set.
	Edges                        TokenCreateEdges `json:"edges"`
	token_create_l1_token_create *uuid.UUID
	selectValues                 sql.SelectValues
}

// TokenCreateEdges holds the relations/edges for other nodes in the graph.
type TokenCreateEdges struct {
	// TokenTransaction holds the value of the token_transaction edge.
	TokenTransaction []*TokenTransaction `json:"token_transaction,omitempty"`
	// L1TokenCreate holds the value of the l1_token_create edge.
	L1TokenCreate *L1TokenCreate `json:"l1_token_create,omitempty"`
	// TokenOutput holds the value of the token_output edge.
	TokenOutput []*TokenOutput `json:"token_output,omitempty"`
	// TokenFreeze holds the value of the token_freeze edge.
	TokenFreeze []*TokenFreeze `json:"token_freeze,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [4]bool
}

// TokenTransactionOrErr returns the TokenTransaction value or an error if the edge
// was not loaded in eager-loading.
func (e TokenCreateEdges) TokenTransactionOrErr() ([]*TokenTransaction, error) {
	if e.loadedTypes[0] {
		return e.TokenTransaction, nil
	}
	return nil, &NotLoadedError{edge: "token_transaction"}
}

// L1TokenCreateOrErr returns the L1TokenCreate value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TokenCreateEdges) L1TokenCreateOrErr() (*L1TokenCreate, error) {
	if e.L1TokenCreate != nil {
		return e.L1TokenCreate, nil
	} else if e.loadedTypes[1] {
		return nil, &NotFoundError{label: l1tokencreate.Label}
	}
	return nil, &NotLoadedError{edge: "l1_token_create"}
}

// TokenOutputOrErr returns the TokenOutput value or an error if the edge
// was not loaded in eager-loading.
func (e TokenCreateEdges) TokenOutputOrErr() ([]*TokenOutput, error) {
	if e.loadedTypes[2] {
		return e.TokenOutput, nil
	}
	return nil, &NotLoadedError{edge: "token_output"}
}

// TokenFreezeOrErr returns the TokenFreeze value or an error if the edge
// was not loaded in eager-loading.
func (e TokenCreateEdges) TokenFreezeOrErr() ([]*TokenFreeze, error) {
	if e.loadedTypes[3] {
		return e.TokenFreeze, nil
	}
	return nil, &NotLoadedError{edge: "token_freeze"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*TokenCreate) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case tokencreate.FieldMaxSupply, tokencreate.FieldTokenIdentifier, tokencreate.FieldIssuerSignature, tokencreate.FieldOperatorSpecificIssuerSignature:
			values[i] = new([]byte)
		case tokencreate.FieldIssuerPublicKey, tokencreate.FieldCreationEntityPublicKey:
			values[i] = new(keys.Public)
		case tokencreate.FieldIsFreezable:
			values[i] = new(sql.NullBool)
		case tokencreate.FieldDecimals, tokencreate.FieldWalletProvidedTimestamp:
			values[i] = new(sql.NullInt64)
		case tokencreate.FieldTokenName, tokencreate.FieldTokenTicker, tokencreate.FieldNetwork:
			values[i] = new(sql.NullString)
		case tokencreate.FieldCreateTime, tokencreate.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case tokencreate.FieldID:
			values[i] = new(uuid.UUID)
		case tokencreate.ForeignKeys[0]: // token_create_l1_token_create
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the TokenCreate fields.
func (tc *TokenCreate) assignValues(columns []string, values []any) 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 tokencreate.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				tc.ID = *value
			}
		case tokencreate.FieldCreateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field create_time", values[i])
			} else if value.Valid {
				tc.CreateTime = value.Time
			}
		case tokencreate.FieldUpdateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field update_time", values[i])
			} else if value.Valid {
				tc.UpdateTime = value.Time
			}
		case tokencreate.FieldIssuerPublicKey:
			if value, ok := values[i].(*keys.Public); !ok {
				return fmt.Errorf("unexpected type %T for field issuer_public_key", values[i])
			} else if value != nil {
				tc.IssuerPublicKey = *value
			}
		case tokencreate.FieldTokenName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token_name", values[i])
			} else if value.Valid {
				tc.TokenName = value.String
			}
		case tokencreate.FieldTokenTicker:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token_ticker", values[i])
			} else if value.Valid {
				tc.TokenTicker = value.String
			}
		case tokencreate.FieldDecimals:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field decimals", values[i])
			} else if value.Valid {
				tc.Decimals = uint8(value.Int64)
			}
		case tokencreate.FieldMaxSupply:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field max_supply", values[i])
			} else if value != nil {
				tc.MaxSupply = *value
			}
		case tokencreate.FieldIsFreezable:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field is_freezable", values[i])
			} else if value.Valid {
				tc.IsFreezable = value.Bool
			}
		case tokencreate.FieldNetwork:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field network", values[i])
			} else if value.Valid {
				tc.Network = schematype.Network(value.String)
			}
		case tokencreate.FieldTokenIdentifier:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field token_identifier", values[i])
			} else if value != nil {
				tc.TokenIdentifier = *value
			}
		case tokencreate.FieldIssuerSignature:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field issuer_signature", values[i])
			} else if value != nil {
				tc.IssuerSignature = *value
			}
		case tokencreate.FieldOperatorSpecificIssuerSignature:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field operator_specific_issuer_signature", values[i])
			} else if value != nil {
				tc.OperatorSpecificIssuerSignature = *value
			}
		case tokencreate.FieldCreationEntityPublicKey:
			if value, ok := values[i].(*keys.Public); !ok {
				return fmt.Errorf("unexpected type %T for field creation_entity_public_key", values[i])
			} else if value != nil {
				tc.CreationEntityPublicKey = *value
			}
		case tokencreate.FieldWalletProvidedTimestamp:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field wallet_provided_timestamp", values[i])
			} else if value.Valid {
				tc.WalletProvidedTimestamp = uint64(value.Int64)
			}
		case tokencreate.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field token_create_l1_token_create", values[i])
			} else if value.Valid {
				tc.token_create_l1_token_create = new(uuid.UUID)
				*tc.token_create_l1_token_create = *value.S.(*uuid.UUID)
			}
		default:
			tc.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the TokenCreate.
// This includes values selected through modifiers, order, etc.
func (tc *TokenCreate) Value(name string) (ent.Value, error) {
	return tc.selectValues.Get(name)
}

// QueryTokenTransaction queries the "token_transaction" edge of the TokenCreate entity.
func (tc *TokenCreate) QueryTokenTransaction() *TokenTransactionQuery {
	return NewTokenCreateClient(tc.config).QueryTokenTransaction(tc)
}

// QueryL1TokenCreate queries the "l1_token_create" edge of the TokenCreate entity.
func (tc *TokenCreate) QueryL1TokenCreate() *L1TokenCreateQuery {
	return NewTokenCreateClient(tc.config).QueryL1TokenCreate(tc)
}

// QueryTokenOutput queries the "token_output" edge of the TokenCreate entity.
func (tc *TokenCreate) QueryTokenOutput() *TokenOutputQuery {
	return NewTokenCreateClient(tc.config).QueryTokenOutput(tc)
}

// QueryTokenFreeze queries the "token_freeze" edge of the TokenCreate entity.
func (tc *TokenCreate) QueryTokenFreeze() *TokenFreezeQuery {
	return NewTokenCreateClient(tc.config).QueryTokenFreeze(tc)
}

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

// Unwrap unwraps the TokenCreate 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 (tc *TokenCreate) Unwrap() *TokenCreate {
	_tx, ok := tc.config.driver.(*txDriver)
	if !ok {
		panic("ent: TokenCreate is not a transactional entity")
	}
	tc.config.driver = _tx.drv
	return tc
}

// String implements the fmt.Stringer.
func (tc *TokenCreate) String() string {
	var builder strings.Builder
	builder.WriteString("TokenCreate(")
	builder.WriteString(fmt.Sprintf("id=%v, ", tc.ID))
	builder.WriteString("create_time=")
	builder.WriteString(tc.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(tc.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("issuer_public_key=")
	builder.WriteString(fmt.Sprintf("%v", tc.IssuerPublicKey))
	builder.WriteString(", ")
	builder.WriteString("token_name=")
	builder.WriteString(tc.TokenName)
	builder.WriteString(", ")
	builder.WriteString("token_ticker=")
	builder.WriteString(tc.TokenTicker)
	builder.WriteString(", ")
	builder.WriteString("decimals=")
	builder.WriteString(fmt.Sprintf("%v", tc.Decimals))
	builder.WriteString(", ")
	builder.WriteString("max_supply=")
	builder.WriteString(fmt.Sprintf("%v", tc.MaxSupply))
	builder.WriteString(", ")
	builder.WriteString("is_freezable=")
	builder.WriteString(fmt.Sprintf("%v", tc.IsFreezable))
	builder.WriteString(", ")
	builder.WriteString("network=")
	builder.WriteString(fmt.Sprintf("%v", tc.Network))
	builder.WriteString(", ")
	builder.WriteString("token_identifier=")
	builder.WriteString(fmt.Sprintf("%v", tc.TokenIdentifier))
	builder.WriteString(", ")
	builder.WriteString("issuer_signature=")
	builder.WriteString(fmt.Sprintf("%v", tc.IssuerSignature))
	builder.WriteString(", ")
	builder.WriteString("operator_specific_issuer_signature=")
	builder.WriteString(fmt.Sprintf("%v", tc.OperatorSpecificIssuerSignature))
	builder.WriteString(", ")
	builder.WriteString("creation_entity_public_key=")
	builder.WriteString(fmt.Sprintf("%v", tc.CreationEntityPublicKey))
	builder.WriteString(", ")
	builder.WriteString("wallet_provided_timestamp=")
	builder.WriteString(fmt.Sprintf("%v", tc.WalletProvidedTimestamp))
	builder.WriteByte(')')
	return builder.String()
}

// TokenCreates is a parsable slice of TokenCreate.
type TokenCreates []*TokenCreate
