// 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/schema/schematype"
	"github.com/lightsparkdev/spark/so/ent/tokencreate"
	"github.com/lightsparkdev/spark/so/ent/tokenfreeze"
)

// TokenFreeze is the model entity for the TokenFreeze schema.
type TokenFreeze 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"`
	// Status holds the value of the "status" field.
	Status schematype.TokenFreezeStatus `json:"status,omitempty"`
	// OwnerPublicKey holds the value of the "owner_public_key" field.
	OwnerPublicKey keys.Public `json:"owner_public_key,omitempty"`
	// TokenPublicKey holds the value of the "token_public_key" field.
	TokenPublicKey keys.Public `json:"token_public_key,omitempty"`
	// IssuerSignature holds the value of the "issuer_signature" field.
	IssuerSignature []byte `json:"issuer_signature,omitempty"`
	// WalletProvidedFreezeTimestamp holds the value of the "wallet_provided_freeze_timestamp" field.
	WalletProvidedFreezeTimestamp uint64 `json:"wallet_provided_freeze_timestamp,omitempty"`
	// WalletProvidedThawTimestamp holds the value of the "wallet_provided_thaw_timestamp" field.
	WalletProvidedThawTimestamp uint64 `json:"wallet_provided_thaw_timestamp,omitempty"`
	// TokenCreateID holds the value of the "token_create_id" field.
	TokenCreateID uuid.UUID `json:"token_create_id,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the TokenFreezeQuery when eager-loading is set.
	Edges        TokenFreezeEdges `json:"edges"`
	selectValues sql.SelectValues
}

// TokenFreezeEdges holds the relations/edges for other nodes in the graph.
type TokenFreezeEdges struct {
	// Token create contains the token metadata associated with this token freeze.
	TokenCreate *TokenCreate `json:"token_create,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [1]bool
}

// TokenCreateOrErr returns the TokenCreate value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TokenFreezeEdges) TokenCreateOrErr() (*TokenCreate, error) {
	if e.TokenCreate != nil {
		return e.TokenCreate, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: tokencreate.Label}
	}
	return nil, &NotLoadedError{edge: "token_create"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*TokenFreeze) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case tokenfreeze.FieldIssuerSignature:
			values[i] = new([]byte)
		case tokenfreeze.FieldOwnerPublicKey, tokenfreeze.FieldTokenPublicKey:
			values[i] = new(keys.Public)
		case tokenfreeze.FieldWalletProvidedFreezeTimestamp, tokenfreeze.FieldWalletProvidedThawTimestamp:
			values[i] = new(sql.NullInt64)
		case tokenfreeze.FieldStatus:
			values[i] = new(sql.NullString)
		case tokenfreeze.FieldCreateTime, tokenfreeze.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case tokenfreeze.FieldID, tokenfreeze.FieldTokenCreateID:
			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 TokenFreeze fields.
func (tf *TokenFreeze) 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 tokenfreeze.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				tf.ID = *value
			}
		case tokenfreeze.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 {
				tf.CreateTime = value.Time
			}
		case tokenfreeze.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 {
				tf.UpdateTime = value.Time
			}
		case tokenfreeze.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				tf.Status = schematype.TokenFreezeStatus(value.String)
			}
		case tokenfreeze.FieldOwnerPublicKey:
			if value, ok := values[i].(*keys.Public); !ok {
				return fmt.Errorf("unexpected type %T for field owner_public_key", values[i])
			} else if value != nil {
				tf.OwnerPublicKey = *value
			}
		case tokenfreeze.FieldTokenPublicKey:
			if value, ok := values[i].(*keys.Public); !ok {
				return fmt.Errorf("unexpected type %T for field token_public_key", values[i])
			} else if value != nil {
				tf.TokenPublicKey = *value
			}
		case tokenfreeze.FieldIssuerSignature:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field issuer_signature", values[i])
			} else if value != nil {
				tf.IssuerSignature = *value
			}
		case tokenfreeze.FieldWalletProvidedFreezeTimestamp:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field wallet_provided_freeze_timestamp", values[i])
			} else if value.Valid {
				tf.WalletProvidedFreezeTimestamp = uint64(value.Int64)
			}
		case tokenfreeze.FieldWalletProvidedThawTimestamp:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field wallet_provided_thaw_timestamp", values[i])
			} else if value.Valid {
				tf.WalletProvidedThawTimestamp = uint64(value.Int64)
			}
		case tokenfreeze.FieldTokenCreateID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field token_create_id", values[i])
			} else if value != nil {
				tf.TokenCreateID = *value
			}
		default:
			tf.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryTokenCreate queries the "token_create" edge of the TokenFreeze entity.
func (tf *TokenFreeze) QueryTokenCreate() *TokenCreateQuery {
	return NewTokenFreezeClient(tf.config).QueryTokenCreate(tf)
}

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

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

// String implements the fmt.Stringer.
func (tf *TokenFreeze) String() string {
	var builder strings.Builder
	builder.WriteString("TokenFreeze(")
	builder.WriteString(fmt.Sprintf("id=%v, ", tf.ID))
	builder.WriteString("create_time=")
	builder.WriteString(tf.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(tf.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", tf.Status))
	builder.WriteString(", ")
	builder.WriteString("owner_public_key=")
	builder.WriteString(fmt.Sprintf("%v", tf.OwnerPublicKey))
	builder.WriteString(", ")
	builder.WriteString("token_public_key=")
	builder.WriteString(fmt.Sprintf("%v", tf.TokenPublicKey))
	builder.WriteString(", ")
	builder.WriteString("issuer_signature=")
	builder.WriteString(fmt.Sprintf("%v", tf.IssuerSignature))
	builder.WriteString(", ")
	builder.WriteString("wallet_provided_freeze_timestamp=")
	builder.WriteString(fmt.Sprintf("%v", tf.WalletProvidedFreezeTimestamp))
	builder.WriteString(", ")
	builder.WriteString("wallet_provided_thaw_timestamp=")
	builder.WriteString(fmt.Sprintf("%v", tf.WalletProvidedThawTimestamp))
	builder.WriteString(", ")
	builder.WriteString("token_create_id=")
	builder.WriteString(fmt.Sprintf("%v", tf.TokenCreateID))
	builder.WriteByte(')')
	return builder.String()
}

// TokenFreezes is a parsable slice of TokenFreeze.
type TokenFreezes []*TokenFreeze
