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

// EntityDkgKey is the model entity for the EntityDkgKey schema.
type EntityDkgKey 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"`
	// KeyType holds the value of the "key_type" field.
	KeyType string `json:"key_type,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the EntityDkgKeyQuery when eager-loading is set.
	Edges                           EntityDkgKeyEdges `json:"edges"`
	entity_dkg_key_signing_keyshare *uuid.UUID
	selectValues                    sql.SelectValues
}

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

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

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

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

// QuerySigningKeyshare queries the "signing_keyshare" edge of the EntityDkgKey entity.
func (edk *EntityDkgKey) QuerySigningKeyshare() *SigningKeyshareQuery {
	return NewEntityDkgKeyClient(edk.config).QuerySigningKeyshare(edk)
}

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

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

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

// EntityDkgKeys is a parsable slice of EntityDkgKey.
type EntityDkgKeys []*EntityDkgKey
