// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"registry-backend/ent/node"
	"registry-backend/ent/nodereview"
	"registry-backend/ent/user"
	"strings"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
)

// NodeReview is the model entity for the NodeReview schema.
type NodeReview struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// NodeID holds the value of the "node_id" field.
	NodeID string `json:"node_id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID string `json:"user_id,omitempty"`
	// Star holds the value of the "star" field.
	Star int `json:"star,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the NodeReviewQuery when eager-loading is set.
	Edges        NodeReviewEdges `json:"edges"`
	selectValues sql.SelectValues
}

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

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*NodeReview) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case nodereview.FieldStar:
			values[i] = new(sql.NullInt64)
		case nodereview.FieldNodeID, nodereview.FieldUserID:
			values[i] = new(sql.NullString)
		case nodereview.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 NodeReview fields.
func (nr *NodeReview) 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 nodereview.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				nr.ID = *value
			}
		case nodereview.FieldNodeID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field node_id", values[i])
			} else if value.Valid {
				nr.NodeID = value.String
			}
		case nodereview.FieldUserID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				nr.UserID = value.String
			}
		case nodereview.FieldStar:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field star", values[i])
			} else if value.Valid {
				nr.Star = int(value.Int64)
			}
		default:
			nr.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryUser queries the "user" edge of the NodeReview entity.
func (nr *NodeReview) QueryUser() *UserQuery {
	return NewNodeReviewClient(nr.config).QueryUser(nr)
}

// QueryNode queries the "node" edge of the NodeReview entity.
func (nr *NodeReview) QueryNode() *NodeQuery {
	return NewNodeReviewClient(nr.config).QueryNode(nr)
}

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

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

// String implements the fmt.Stringer.
func (nr *NodeReview) String() string {
	var builder strings.Builder
	builder.WriteString("NodeReview(")
	builder.WriteString(fmt.Sprintf("id=%v, ", nr.ID))
	builder.WriteString("node_id=")
	builder.WriteString(nr.NodeID)
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(nr.UserID)
	builder.WriteString(", ")
	builder.WriteString("star=")
	builder.WriteString(fmt.Sprintf("%v", nr.Star))
	builder.WriteByte(')')
	return builder.String()
}

// NodeReviews is a parsable slice of NodeReview.
type NodeReviews []*NodeReview
