// 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/tokenmint"
)

// TokenMint is the model entity for the TokenMint schema.
type TokenMint 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"`
	// WalletProvidedTimestamp holds the value of the "wallet_provided_timestamp" field.
	WalletProvidedTimestamp uint64 `json:"wallet_provided_timestamp,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"`
	// TokenIdentifier holds the value of the "token_identifier" field.
	TokenIdentifier []byte `json:"token_identifier,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the TokenMintQuery when eager-loading is set.
	Edges        TokenMintEdges `json:"edges"`
	selectValues sql.SelectValues
}

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*TokenMint) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case tokenmint.FieldIssuerSignature, tokenmint.FieldOperatorSpecificIssuerSignature, tokenmint.FieldTokenIdentifier:
			values[i] = new([]byte)
		case tokenmint.FieldIssuerPublicKey:
			values[i] = new(keys.Public)
		case tokenmint.FieldWalletProvidedTimestamp:
			values[i] = new(sql.NullInt64)
		case tokenmint.FieldCreateTime, tokenmint.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case tokenmint.FieldID:
			values[i] = 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 TokenMint fields.
func (tm *TokenMint) 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 tokenmint.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				tm.ID = *value
			}
		case tokenmint.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 {
				tm.CreateTime = value.Time
			}
		case tokenmint.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 {
				tm.UpdateTime = value.Time
			}
		case tokenmint.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 {
				tm.IssuerPublicKey = *value
			}
		case tokenmint.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 {
				tm.WalletProvidedTimestamp = uint64(value.Int64)
			}
		case tokenmint.FieldIssuerSignature:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field issuer_signature", values[i])
			} else if value != nil {
				tm.IssuerSignature = *value
			}
		case tokenmint.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 {
				tm.OperatorSpecificIssuerSignature = *value
			}
		case tokenmint.FieldTokenIdentifier:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field token_identifier", values[i])
			} else if value != nil {
				tm.TokenIdentifier = *value
			}
		default:
			tm.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryTokenTransaction queries the "token_transaction" edge of the TokenMint entity.
func (tm *TokenMint) QueryTokenTransaction() *TokenTransactionQuery {
	return NewTokenMintClient(tm.config).QueryTokenTransaction(tm)
}

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

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

// String implements the fmt.Stringer.
func (tm *TokenMint) String() string {
	var builder strings.Builder
	builder.WriteString("TokenMint(")
	builder.WriteString(fmt.Sprintf("id=%v, ", tm.ID))
	builder.WriteString("create_time=")
	builder.WriteString(tm.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(tm.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("issuer_public_key=")
	builder.WriteString(fmt.Sprintf("%v", tm.IssuerPublicKey))
	builder.WriteString(", ")
	builder.WriteString("wallet_provided_timestamp=")
	builder.WriteString(fmt.Sprintf("%v", tm.WalletProvidedTimestamp))
	builder.WriteString(", ")
	builder.WriteString("issuer_signature=")
	builder.WriteString(fmt.Sprintf("%v", tm.IssuerSignature))
	builder.WriteString(", ")
	builder.WriteString("operator_specific_issuer_signature=")
	builder.WriteString(fmt.Sprintf("%v", tm.OperatorSpecificIssuerSignature))
	builder.WriteString(", ")
	builder.WriteString("token_identifier=")
	builder.WriteString(fmt.Sprintf("%v", tm.TokenIdentifier))
	builder.WriteByte(')')
	return builder.String()
}

// TokenMints is a parsable slice of TokenMint.
type TokenMints []*TokenMint
