Files
homebox/backend/internal/data/ent/entity.go
2025-09-05 22:44:40 -04:00

587 lines
22 KiB
Go

// 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/sysadminsmedia/homebox/backend/internal/data/ent/entity"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entitytype"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
)
// Entity is the model entity for the Entity schema.
type Entity struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// ImportRef holds the value of the "import_ref" field.
ImportRef string `json:"import_ref,omitempty"`
// Notes holds the value of the "notes" field.
Notes string `json:"notes,omitempty"`
// Quantity holds the value of the "quantity" field.
Quantity int `json:"quantity,omitempty"`
// Insured holds the value of the "insured" field.
Insured bool `json:"insured,omitempty"`
// Archived holds the value of the "archived" field.
Archived bool `json:"archived,omitempty"`
// AssetID holds the value of the "asset_id" field.
AssetID int `json:"asset_id,omitempty"`
// SyncChildEntitiesLocations holds the value of the "sync_child_entities_locations" field.
SyncChildEntitiesLocations bool `json:"sync_child_entities_locations,omitempty"`
// SerialNumber holds the value of the "serial_number" field.
SerialNumber string `json:"serial_number,omitempty"`
// ModelNumber holds the value of the "model_number" field.
ModelNumber string `json:"model_number,omitempty"`
// Manufacturer holds the value of the "manufacturer" field.
Manufacturer string `json:"manufacturer,omitempty"`
// LifetimeWarranty holds the value of the "lifetime_warranty" field.
LifetimeWarranty bool `json:"lifetime_warranty,omitempty"`
// WarrantyExpires holds the value of the "warranty_expires" field.
WarrantyExpires time.Time `json:"warranty_expires,omitempty"`
// WarrantyDetails holds the value of the "warranty_details" field.
WarrantyDetails string `json:"warranty_details,omitempty"`
// PurchaseTime holds the value of the "purchase_time" field.
PurchaseTime time.Time `json:"purchase_time,omitempty"`
// PurchaseFrom holds the value of the "purchase_from" field.
PurchaseFrom string `json:"purchase_from,omitempty"`
// PurchasePrice holds the value of the "purchase_price" field.
PurchasePrice float64 `json:"purchase_price,omitempty"`
// SoldTime holds the value of the "sold_time" field.
SoldTime time.Time `json:"sold_time,omitempty"`
// SoldTo holds the value of the "sold_to" field.
SoldTo string `json:"sold_to,omitempty"`
// SoldPrice holds the value of the "sold_price" field.
SoldPrice float64 `json:"sold_price,omitempty"`
// SoldNotes holds the value of the "sold_notes" field.
SoldNotes string `json:"sold_notes,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EntityQuery when eager-loading is set.
Edges EntityEdges `json:"edges"`
entity_parent *uuid.UUID
entity_location *uuid.UUID
entity_type_entities *uuid.UUID
group_entities *uuid.UUID
selectValues sql.SelectValues
}
// EntityEdges holds the relations/edges for other nodes in the graph.
type EntityEdges struct {
// Group holds the value of the group edge.
Group *Group `json:"group,omitempty"`
// Children holds the value of the children edge.
Children []*Entity `json:"children,omitempty"`
// Parent holds the value of the parent edge.
Parent *Entity `json:"parent,omitempty"`
// Entity holds the value of the entity edge.
Entity []*Entity `json:"entity,omitempty"`
// Location holds the value of the location edge.
Location *Entity `json:"location,omitempty"`
// Label holds the value of the label edge.
Label []*Label `json:"label,omitempty"`
// Type holds the value of the type edge.
Type *EntityType `json:"type,omitempty"`
// Fields holds the value of the fields edge.
Fields []*EntityField `json:"fields,omitempty"`
// MaintenanceEntries holds the value of the maintenance_entries edge.
MaintenanceEntries []*MaintenanceEntry `json:"maintenance_entries,omitempty"`
// Attachments holds the value of the attachments edge.
Attachments []*Attachment `json:"attachments,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [10]bool
}
// GroupOrErr returns the Group value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EntityEdges) GroupOrErr() (*Group, error) {
if e.Group != nil {
return e.Group, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: group.Label}
}
return nil, &NotLoadedError{edge: "group"}
}
// ChildrenOrErr returns the Children value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) ChildrenOrErr() ([]*Entity, error) {
if e.loadedTypes[1] {
return e.Children, nil
}
return nil, &NotLoadedError{edge: "children"}
}
// ParentOrErr returns the Parent value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EntityEdges) ParentOrErr() (*Entity, error) {
if e.Parent != nil {
return e.Parent, nil
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: entity.Label}
}
return nil, &NotLoadedError{edge: "parent"}
}
// EntityOrErr returns the Entity value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) EntityOrErr() ([]*Entity, error) {
if e.loadedTypes[3] {
return e.Entity, nil
}
return nil, &NotLoadedError{edge: "entity"}
}
// LocationOrErr returns the Location value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EntityEdges) LocationOrErr() (*Entity, error) {
if e.Location != nil {
return e.Location, nil
} else if e.loadedTypes[4] {
return nil, &NotFoundError{label: entity.Label}
}
return nil, &NotLoadedError{edge: "location"}
}
// LabelOrErr returns the Label value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) LabelOrErr() ([]*Label, error) {
if e.loadedTypes[5] {
return e.Label, nil
}
return nil, &NotLoadedError{edge: "label"}
}
// TypeOrErr returns the Type value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EntityEdges) TypeOrErr() (*EntityType, error) {
if e.Type != nil {
return e.Type, nil
} else if e.loadedTypes[6] {
return nil, &NotFoundError{label: entitytype.Label}
}
return nil, &NotLoadedError{edge: "type"}
}
// FieldsOrErr returns the Fields value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) FieldsOrErr() ([]*EntityField, error) {
if e.loadedTypes[7] {
return e.Fields, nil
}
return nil, &NotLoadedError{edge: "fields"}
}
// MaintenanceEntriesOrErr returns the MaintenanceEntries value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) MaintenanceEntriesOrErr() ([]*MaintenanceEntry, error) {
if e.loadedTypes[8] {
return e.MaintenanceEntries, nil
}
return nil, &NotLoadedError{edge: "maintenance_entries"}
}
// AttachmentsOrErr returns the Attachments value or an error if the edge
// was not loaded in eager-loading.
func (e EntityEdges) AttachmentsOrErr() ([]*Attachment, error) {
if e.loadedTypes[9] {
return e.Attachments, nil
}
return nil, &NotLoadedError{edge: "attachments"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Entity) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case entity.FieldInsured, entity.FieldArchived, entity.FieldSyncChildEntitiesLocations, entity.FieldLifetimeWarranty:
values[i] = new(sql.NullBool)
case entity.FieldPurchasePrice, entity.FieldSoldPrice:
values[i] = new(sql.NullFloat64)
case entity.FieldQuantity, entity.FieldAssetID:
values[i] = new(sql.NullInt64)
case entity.FieldName, entity.FieldDescription, entity.FieldImportRef, entity.FieldNotes, entity.FieldSerialNumber, entity.FieldModelNumber, entity.FieldManufacturer, entity.FieldWarrantyDetails, entity.FieldPurchaseFrom, entity.FieldSoldTo, entity.FieldSoldNotes:
values[i] = new(sql.NullString)
case entity.FieldCreatedAt, entity.FieldUpdatedAt, entity.FieldWarrantyExpires, entity.FieldPurchaseTime, entity.FieldSoldTime:
values[i] = new(sql.NullTime)
case entity.FieldID:
values[i] = new(uuid.UUID)
case entity.ForeignKeys[0]: // entity_parent
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
case entity.ForeignKeys[1]: // entity_location
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
case entity.ForeignKeys[2]: // entity_type_entities
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
case entity.ForeignKeys[3]: // group_entities
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 Entity fields.
func (_m *Entity) 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 entity.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 entity.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 entity.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
}
case entity.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case entity.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
_m.Description = value.String
}
case entity.FieldImportRef:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field import_ref", values[i])
} else if value.Valid {
_m.ImportRef = value.String
}
case entity.FieldNotes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field notes", values[i])
} else if value.Valid {
_m.Notes = value.String
}
case entity.FieldQuantity:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field quantity", values[i])
} else if value.Valid {
_m.Quantity = int(value.Int64)
}
case entity.FieldInsured:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field insured", values[i])
} else if value.Valid {
_m.Insured = value.Bool
}
case entity.FieldArchived:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field archived", values[i])
} else if value.Valid {
_m.Archived = value.Bool
}
case entity.FieldAssetID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field asset_id", values[i])
} else if value.Valid {
_m.AssetID = int(value.Int64)
}
case entity.FieldSyncChildEntitiesLocations:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field sync_child_entities_locations", values[i])
} else if value.Valid {
_m.SyncChildEntitiesLocations = value.Bool
}
case entity.FieldSerialNumber:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field serial_number", values[i])
} else if value.Valid {
_m.SerialNumber = value.String
}
case entity.FieldModelNumber:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field model_number", values[i])
} else if value.Valid {
_m.ModelNumber = value.String
}
case entity.FieldManufacturer:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field manufacturer", values[i])
} else if value.Valid {
_m.Manufacturer = value.String
}
case entity.FieldLifetimeWarranty:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field lifetime_warranty", values[i])
} else if value.Valid {
_m.LifetimeWarranty = value.Bool
}
case entity.FieldWarrantyExpires:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field warranty_expires", values[i])
} else if value.Valid {
_m.WarrantyExpires = value.Time
}
case entity.FieldWarrantyDetails:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field warranty_details", values[i])
} else if value.Valid {
_m.WarrantyDetails = value.String
}
case entity.FieldPurchaseTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field purchase_time", values[i])
} else if value.Valid {
_m.PurchaseTime = value.Time
}
case entity.FieldPurchaseFrom:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field purchase_from", values[i])
} else if value.Valid {
_m.PurchaseFrom = value.String
}
case entity.FieldPurchasePrice:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field purchase_price", values[i])
} else if value.Valid {
_m.PurchasePrice = value.Float64
}
case entity.FieldSoldTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field sold_time", values[i])
} else if value.Valid {
_m.SoldTime = value.Time
}
case entity.FieldSoldTo:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field sold_to", values[i])
} else if value.Valid {
_m.SoldTo = value.String
}
case entity.FieldSoldPrice:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field sold_price", values[i])
} else if value.Valid {
_m.SoldPrice = value.Float64
}
case entity.FieldSoldNotes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field sold_notes", values[i])
} else if value.Valid {
_m.SoldNotes = value.String
}
case entity.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field entity_parent", values[i])
} else if value.Valid {
_m.entity_parent = new(uuid.UUID)
*_m.entity_parent = *value.S.(*uuid.UUID)
}
case entity.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field entity_location", values[i])
} else if value.Valid {
_m.entity_location = new(uuid.UUID)
*_m.entity_location = *value.S.(*uuid.UUID)
}
case entity.ForeignKeys[2]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field entity_type_entities", values[i])
} else if value.Valid {
_m.entity_type_entities = new(uuid.UUID)
*_m.entity_type_entities = *value.S.(*uuid.UUID)
}
case entity.ForeignKeys[3]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field group_entities", values[i])
} else if value.Valid {
_m.group_entities = new(uuid.UUID)
*_m.group_entities = *value.S.(*uuid.UUID)
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Entity.
// This includes values selected through modifiers, order, etc.
func (_m *Entity) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryGroup queries the "group" edge of the Entity entity.
func (_m *Entity) QueryGroup() *GroupQuery {
return NewEntityClient(_m.config).QueryGroup(_m)
}
// QueryChildren queries the "children" edge of the Entity entity.
func (_m *Entity) QueryChildren() *EntityQuery {
return NewEntityClient(_m.config).QueryChildren(_m)
}
// QueryParent queries the "parent" edge of the Entity entity.
func (_m *Entity) QueryParent() *EntityQuery {
return NewEntityClient(_m.config).QueryParent(_m)
}
// QueryEntity queries the "entity" edge of the Entity entity.
func (_m *Entity) QueryEntity() *EntityQuery {
return NewEntityClient(_m.config).QueryEntity(_m)
}
// QueryLocation queries the "location" edge of the Entity entity.
func (_m *Entity) QueryLocation() *EntityQuery {
return NewEntityClient(_m.config).QueryLocation(_m)
}
// QueryLabel queries the "label" edge of the Entity entity.
func (_m *Entity) QueryLabel() *LabelQuery {
return NewEntityClient(_m.config).QueryLabel(_m)
}
// QueryType queries the "type" edge of the Entity entity.
func (_m *Entity) QueryType() *EntityTypeQuery {
return NewEntityClient(_m.config).QueryType(_m)
}
// QueryFields queries the "fields" edge of the Entity entity.
func (_m *Entity) QueryFields() *EntityFieldQuery {
return NewEntityClient(_m.config).QueryFields(_m)
}
// QueryMaintenanceEntries queries the "maintenance_entries" edge of the Entity entity.
func (_m *Entity) QueryMaintenanceEntries() *MaintenanceEntryQuery {
return NewEntityClient(_m.config).QueryMaintenanceEntries(_m)
}
// QueryAttachments queries the "attachments" edge of the Entity entity.
func (_m *Entity) QueryAttachments() *AttachmentQuery {
return NewEntityClient(_m.config).QueryAttachments(_m)
}
// Update returns a builder for updating this Entity.
// Note that you need to call Entity.Unwrap() before calling this method if this Entity
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Entity) Update() *EntityUpdateOne {
return NewEntityClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Entity 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 *Entity) Unwrap() *Entity {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Entity is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Entity) String() string {
var builder strings.Builder
builder.WriteString("Entity(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
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.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(_m.Description)
builder.WriteString(", ")
builder.WriteString("import_ref=")
builder.WriteString(_m.ImportRef)
builder.WriteString(", ")
builder.WriteString("notes=")
builder.WriteString(_m.Notes)
builder.WriteString(", ")
builder.WriteString("quantity=")
builder.WriteString(fmt.Sprintf("%v", _m.Quantity))
builder.WriteString(", ")
builder.WriteString("insured=")
builder.WriteString(fmt.Sprintf("%v", _m.Insured))
builder.WriteString(", ")
builder.WriteString("archived=")
builder.WriteString(fmt.Sprintf("%v", _m.Archived))
builder.WriteString(", ")
builder.WriteString("asset_id=")
builder.WriteString(fmt.Sprintf("%v", _m.AssetID))
builder.WriteString(", ")
builder.WriteString("sync_child_entities_locations=")
builder.WriteString(fmt.Sprintf("%v", _m.SyncChildEntitiesLocations))
builder.WriteString(", ")
builder.WriteString("serial_number=")
builder.WriteString(_m.SerialNumber)
builder.WriteString(", ")
builder.WriteString("model_number=")
builder.WriteString(_m.ModelNumber)
builder.WriteString(", ")
builder.WriteString("manufacturer=")
builder.WriteString(_m.Manufacturer)
builder.WriteString(", ")
builder.WriteString("lifetime_warranty=")
builder.WriteString(fmt.Sprintf("%v", _m.LifetimeWarranty))
builder.WriteString(", ")
builder.WriteString("warranty_expires=")
builder.WriteString(_m.WarrantyExpires.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("warranty_details=")
builder.WriteString(_m.WarrantyDetails)
builder.WriteString(", ")
builder.WriteString("purchase_time=")
builder.WriteString(_m.PurchaseTime.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("purchase_from=")
builder.WriteString(_m.PurchaseFrom)
builder.WriteString(", ")
builder.WriteString("purchase_price=")
builder.WriteString(fmt.Sprintf("%v", _m.PurchasePrice))
builder.WriteString(", ")
builder.WriteString("sold_time=")
builder.WriteString(_m.SoldTime.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("sold_to=")
builder.WriteString(_m.SoldTo)
builder.WriteString(", ")
builder.WriteString("sold_price=")
builder.WriteString(fmt.Sprintf("%v", _m.SoldPrice))
builder.WriteString(", ")
builder.WriteString("sold_notes=")
builder.WriteString(_m.SoldNotes)
builder.WriteByte(')')
return builder.String()
}
// Entities is a parsable slice of Entity.
type Entities []*Entity