// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/emplacement"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/lienobjetemplacement"
	"gitea.maison43.duckdns.org/gilles/matosbox/internal/data/ent/objet"
	"github.com/google/uuid"
)

// LienObjetEmplacement is the model entity for the LienObjetEmplacement schema.
type LienObjetEmplacement struct {
	config `json:"-"`
	// ID of the ent.
	// Identifiant unique du lien
	ID uuid.UUID `json:"id,omitempty"`
	// Identifiant de l'objet
	ObjetID uuid.UUID `json:"objet_id,omitempty"`
	// Identifiant de l'emplacement
	EmplacementID uuid.UUID `json:"emplacement_id,omitempty"`
	// Type de relation
	Type lienobjetemplacement.Type `json:"type,omitempty"`
	// Date de creation
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Date de derniere mise a jour
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the LienObjetEmplacementQuery when eager-loading is set.
	Edges        LienObjetEmplacementEdges `json:"edges"`
	selectValues sql.SelectValues
}

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

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*LienObjetEmplacement) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case lienobjetemplacement.FieldType:
			values[i] = new(sql.NullString)
		case lienobjetemplacement.FieldCreatedAt, lienobjetemplacement.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		case lienobjetemplacement.FieldID, lienobjetemplacement.FieldObjetID, lienobjetemplacement.FieldEmplacementID:
			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 LienObjetEmplacement fields.
func (_m *LienObjetEmplacement) 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 lienobjetemplacement.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				_m.ID = *value
			}
		case lienobjetemplacement.FieldObjetID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field objet_id", values[i])
			} else if value != nil {
				_m.ObjetID = *value
			}
		case lienobjetemplacement.FieldEmplacementID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field emplacement_id", values[i])
			} else if value != nil {
				_m.EmplacementID = *value
			}
		case lienobjetemplacement.FieldType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				_m.Type = lienobjetemplacement.Type(value.String)
			}
		case lienobjetemplacement.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				_m.CreatedAt = value.Time
			}
		case lienobjetemplacement.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				_m.UpdatedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryObjet queries the "objet" edge of the LienObjetEmplacement entity.
func (_m *LienObjetEmplacement) QueryObjet() *ObjetQuery {
	return NewLienObjetEmplacementClient(_m.config).QueryObjet(_m)
}

// QueryEmplacement queries the "emplacement" edge of the LienObjetEmplacement entity.
func (_m *LienObjetEmplacement) QueryEmplacement() *EmplacementQuery {
	return NewLienObjetEmplacementClient(_m.config).QueryEmplacement(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *LienObjetEmplacement) String() string {
	var builder strings.Builder
	builder.WriteString("LienObjetEmplacement(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("objet_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.ObjetID))
	builder.WriteString(", ")
	builder.WriteString("emplacement_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.EmplacementID))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", _m.Type))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// LienObjetEmplacements is a parsable slice of LienObjetEmplacement.
type LienObjetEmplacements []*LienObjetEmplacement
