// 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/so/ent/signingnonce"
)

// SigningNonce is the model entity for the SigningNonce schema.
type SigningNonce 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"`
	// Nonce holds the value of the "nonce" field.
	Nonce []byte `json:"nonce,omitempty"`
	// NonceCommitment holds the value of the "nonce_commitment" field.
	NonceCommitment []byte `json:"nonce_commitment,omitempty"`
	// Message holds the value of the "message" field.
	//
	// Deprecated: Field "message" was marked as deprecated in the schema.
	Message []byte `json:"message,omitempty"`
	// RetryFingerprint holds the value of the "retry_fingerprint" field.
	RetryFingerprint []byte `json:"retry_fingerprint,omitempty"`
	selectValues     sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*SigningNonce) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case signingnonce.FieldNonce, signingnonce.FieldNonceCommitment, signingnonce.FieldMessage, signingnonce.FieldRetryFingerprint:
			values[i] = new([]byte)
		case signingnonce.FieldCreateTime, signingnonce.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case signingnonce.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 SigningNonce fields.
func (sn *SigningNonce) 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 signingnonce.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				sn.ID = *value
			}
		case signingnonce.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 {
				sn.CreateTime = value.Time
			}
		case signingnonce.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 {
				sn.UpdateTime = value.Time
			}
		case signingnonce.FieldNonce:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field nonce", values[i])
			} else if value != nil {
				sn.Nonce = *value
			}
		case signingnonce.FieldNonceCommitment:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field nonce_commitment", values[i])
			} else if value != nil {
				sn.NonceCommitment = *value
			}
		case signingnonce.FieldMessage:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field message", values[i])
			} else if value != nil {
				sn.Message = *value
			}
		case signingnonce.FieldRetryFingerprint:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field retry_fingerprint", values[i])
			} else if value != nil {
				sn.RetryFingerprint = *value
			}
		default:
			sn.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (sn *SigningNonce) String() string {
	var builder strings.Builder
	builder.WriteString("SigningNonce(")
	builder.WriteString(fmt.Sprintf("id=%v, ", sn.ID))
	builder.WriteString("create_time=")
	builder.WriteString(sn.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(sn.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("nonce=")
	builder.WriteString(fmt.Sprintf("%v", sn.Nonce))
	builder.WriteString(", ")
	builder.WriteString("nonce_commitment=")
	builder.WriteString(fmt.Sprintf("%v", sn.NonceCommitment))
	builder.WriteString(", ")
	builder.WriteString("message=")
	builder.WriteString(fmt.Sprintf("%v", sn.Message))
	builder.WriteString(", ")
	builder.WriteString("retry_fingerprint=")
	builder.WriteString(fmt.Sprintf("%v", sn.RetryFingerprint))
	builder.WriteByte(')')
	return builder.String()
}

// SigningNonces is a parsable slice of SigningNonce.
type SigningNonces []*SigningNonce
