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

// PaymentIntent is the model entity for the PaymentIntent schema.
type PaymentIntent 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"`
	// The original payment intent string
	PaymentIntent string `json:"payment_intent,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the PaymentIntentQuery when eager-loading is set.
	Edges        PaymentIntentEdges `json:"edges"`
	selectValues sql.SelectValues
}

// PaymentIntentEdges holds the relations/edges for other nodes in the graph.
type PaymentIntentEdges struct {
	// Transfer holds the value of the transfer edge.
	Transfer []*Transfer `json:"transfer,omitempty"`
	// 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 [2]bool
}

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*PaymentIntent) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case paymentintent.FieldPaymentIntent:
			values[i] = new(sql.NullString)
		case paymentintent.FieldCreateTime, paymentintent.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case paymentintent.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 PaymentIntent fields.
func (pi *PaymentIntent) 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 paymentintent.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				pi.ID = *value
			}
		case paymentintent.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 {
				pi.CreateTime = value.Time
			}
		case paymentintent.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 {
				pi.UpdateTime = value.Time
			}
		case paymentintent.FieldPaymentIntent:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field payment_intent", values[i])
			} else if value.Valid {
				pi.PaymentIntent = value.String
			}
		default:
			pi.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryTransfer queries the "transfer" edge of the PaymentIntent entity.
func (pi *PaymentIntent) QueryTransfer() *TransferQuery {
	return NewPaymentIntentClient(pi.config).QueryTransfer(pi)
}

// QueryTokenTransaction queries the "token_transaction" edge of the PaymentIntent entity.
func (pi *PaymentIntent) QueryTokenTransaction() *TokenTransactionQuery {
	return NewPaymentIntentClient(pi.config).QueryTokenTransaction(pi)
}

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

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

// String implements the fmt.Stringer.
func (pi *PaymentIntent) String() string {
	var builder strings.Builder
	builder.WriteString("PaymentIntent(")
	builder.WriteString(fmt.Sprintf("id=%v, ", pi.ID))
	builder.WriteString("create_time=")
	builder.WriteString(pi.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(pi.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("payment_intent=")
	builder.WriteString(pi.PaymentIntent)
	builder.WriteByte(')')
	return builder.String()
}

// PaymentIntents is a parsable slice of PaymentIntent.
type PaymentIntents []*PaymentIntent
