// Code generated by ent, DO NOT EDIT.

package ent

import (
	"demo/ent/department"
	"demo/ent/instructor"
	"fmt"
	"strings"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

// Instructor is the model entity for the Instructor schema.
type Instructor struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the InstructorQuery when eager-loading is set.
	Edges                  InstructorEdges `json:"edges"`
	department_instructors *int
	selectValues           sql.SelectValues
}

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*Instructor) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case instructor.FieldID:
			values[i] = new(sql.NullInt64)
		case instructor.FieldName:
			values[i] = new(sql.NullString)
		case instructor.ForeignKeys[0]: // department_instructors
			values[i] = new(sql.NullInt64)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Instructor fields.
func (i *Instructor) 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 j := range columns {
		switch columns[j] {
		case instructor.FieldID:
			value, ok := values[j].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			i.ID = int(value.Int64)
		case instructor.FieldName:
			if value, ok := values[j].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[j])
			} else if value.Valid {
				i.Name = value.String
			}
		case instructor.ForeignKeys[0]:
			if value, ok := values[j].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for edge-field department_instructors", value)
			} else if value.Valid {
				i.department_instructors = new(int)
				*i.department_instructors = int(value.Int64)
			}
		default:
			i.selectValues.Set(columns[j], values[j])
		}
	}
	return nil
}

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

// QueryDepartment queries the "department" edge of the Instructor entity.
func (i *Instructor) QueryDepartment() *DepartmentQuery {
	return NewInstructorClient(i.config).QueryDepartment(i)
}

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

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

// String implements the fmt.Stringer.
func (i *Instructor) String() string {
	var builder strings.Builder
	builder.WriteString("Instructor(")
	builder.WriteString(fmt.Sprintf("id=%v, ", i.ID))
	builder.WriteString("name=")
	builder.WriteString(i.Name)
	builder.WriteByte(')')
	return builder.String()
}

// Instructors is a parsable slice of Instructor.
type Instructors []*Instructor
