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

// L1TokenCreate is the model entity for the L1TokenCreate schema.
type L1TokenCreate 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"`
	// TransactionID holds the value of the "transaction_id" field.
	TransactionID []byte `json:"transaction_id,omitempty"`
	selectValues  sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*L1TokenCreate) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case l1tokencreate.FieldMaxSupply, l1tokencreate.FieldTokenIdentifier, l1tokencreate.FieldTransactionID:
			values[i] = new([]byte)
		case l1tokencreate.FieldIssuerPublicKey:
			values[i] = new(keys.Public)
		case l1tokencreate.FieldIsFreezable:
			values[i] = new(sql.NullBool)
		case l1tokencreate.FieldDecimals:
			values[i] = new(sql.NullInt64)
		case l1tokencreate.FieldTokenName, l1tokencreate.FieldTokenTicker, l1tokencreate.FieldNetwork:
			values[i] = new(sql.NullString)
		case l1tokencreate.FieldCreateTime, l1tokencreate.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case l1tokencreate.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 L1TokenCreate fields.
func (lc *L1TokenCreate) 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 l1tokencreate.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				lc.ID = *value
			}
		case l1tokencreate.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 {
				lc.CreateTime = value.Time
			}
		case l1tokencreate.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 {
				lc.UpdateTime = value.Time
			}
		case l1tokencreate.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 {
				lc.IssuerPublicKey = *value
			}
		case l1tokencreate.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 {
				lc.TokenName = value.String
			}
		case l1tokencreate.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 {
				lc.TokenTicker = value.String
			}
		case l1tokencreate.FieldDecimals:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field decimals", values[i])
			} else if value.Valid {
				lc.Decimals = uint8(value.Int64)
			}
		case l1tokencreate.FieldMaxSupply:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field max_supply", values[i])
			} else if value != nil {
				lc.MaxSupply = *value
			}
		case l1tokencreate.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 {
				lc.IsFreezable = value.Bool
			}
		case l1tokencreate.FieldNetwork:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field network", values[i])
			} else if value.Valid {
				lc.Network = schematype.Network(value.String)
			}
		case l1tokencreate.FieldTokenIdentifier:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field token_identifier", values[i])
			} else if value != nil {
				lc.TokenIdentifier = *value
			}
		case l1tokencreate.FieldTransactionID:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field transaction_id", values[i])
			} else if value != nil {
				lc.TransactionID = *value
			}
		default:
			lc.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (lc *L1TokenCreate) String() string {
	var builder strings.Builder
	builder.WriteString("L1TokenCreate(")
	builder.WriteString(fmt.Sprintf("id=%v, ", lc.ID))
	builder.WriteString("create_time=")
	builder.WriteString(lc.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(lc.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("issuer_public_key=")
	builder.WriteString(fmt.Sprintf("%v", lc.IssuerPublicKey))
	builder.WriteString(", ")
	builder.WriteString("token_name=")
	builder.WriteString(lc.TokenName)
	builder.WriteString(", ")
	builder.WriteString("token_ticker=")
	builder.WriteString(lc.TokenTicker)
	builder.WriteString(", ")
	builder.WriteString("decimals=")
	builder.WriteString(fmt.Sprintf("%v", lc.Decimals))
	builder.WriteString(", ")
	builder.WriteString("max_supply=")
	builder.WriteString(fmt.Sprintf("%v", lc.MaxSupply))
	builder.WriteString(", ")
	builder.WriteString("is_freezable=")
	builder.WriteString(fmt.Sprintf("%v", lc.IsFreezable))
	builder.WriteString(", ")
	builder.WriteString("network=")
	builder.WriteString(fmt.Sprintf("%v", lc.Network))
	builder.WriteString(", ")
	builder.WriteString("token_identifier=")
	builder.WriteString(fmt.Sprintf("%v", lc.TokenIdentifier))
	builder.WriteString(", ")
	builder.WriteString("transaction_id=")
	builder.WriteString(fmt.Sprintf("%v", lc.TransactionID))
	builder.WriteByte(')')
	return builder.String()
}

// L1TokenCreates is a parsable slice of L1TokenCreate.
type L1TokenCreates []*L1TokenCreate
