// 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/cooperativeexit"
	"github.com/lightsparkdev/spark/so/ent/transfer"
)

// CooperativeExit is the model entity for the CooperativeExit schema.
type CooperativeExit 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"`
	// ExitTxid holds the value of the "exit_txid" field.
	ExitTxid []byte `json:"exit_txid,omitempty"`
	// ConfirmationHeight holds the value of the "confirmation_height" field.
	ConfirmationHeight int64 `json:"confirmation_height,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the CooperativeExitQuery when eager-loading is set.
	Edges                     CooperativeExitEdges `json:"edges"`
	cooperative_exit_transfer *uuid.UUID
	selectValues              sql.SelectValues
}

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*CooperativeExit) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case cooperativeexit.FieldExitTxid:
			values[i] = new([]byte)
		case cooperativeexit.FieldConfirmationHeight:
			values[i] = new(sql.NullInt64)
		case cooperativeexit.FieldCreateTime, cooperativeexit.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case cooperativeexit.FieldID:
			values[i] = new(uuid.UUID)
		case cooperativeexit.ForeignKeys[0]: // cooperative_exit_transfer
			values[i] = &sql.NullScanner{S: 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 CooperativeExit fields.
func (ce *CooperativeExit) 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 cooperativeexit.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				ce.ID = *value
			}
		case cooperativeexit.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 {
				ce.CreateTime = value.Time
			}
		case cooperativeexit.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 {
				ce.UpdateTime = value.Time
			}
		case cooperativeexit.FieldExitTxid:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field exit_txid", values[i])
			} else if value != nil {
				ce.ExitTxid = *value
			}
		case cooperativeexit.FieldConfirmationHeight:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field confirmation_height", values[i])
			} else if value.Valid {
				ce.ConfirmationHeight = value.Int64
			}
		case cooperativeexit.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field cooperative_exit_transfer", values[i])
			} else if value.Valid {
				ce.cooperative_exit_transfer = new(uuid.UUID)
				*ce.cooperative_exit_transfer = *value.S.(*uuid.UUID)
			}
		default:
			ce.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryTransfer queries the "transfer" edge of the CooperativeExit entity.
func (ce *CooperativeExit) QueryTransfer() *TransferQuery {
	return NewCooperativeExitClient(ce.config).QueryTransfer(ce)
}

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

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

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

// CooperativeExits is a parsable slice of CooperativeExit.
type CooperativeExits []*CooperativeExit
