Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

15.2 KB
Raw Blame
// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"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/entitytemplate"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
)

// EntityTemplate is the model entity for the EntityTemplate schema.
type EntityTemplate 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"`
	// Notes holds the value of the "notes" field.
	Notes string `json:"notes,omitempty"`
	// DefaultQuantity holds the value of the "default_quantity" field.
	DefaultQuantity float64 `json:"default_quantity,omitempty"`
	// DefaultInsured holds the value of the "default_insured" field.
	DefaultInsured bool `json:"default_insured,omitempty"`
	// Default name template for items (can use placeholders)
	DefaultName string `json:"default_name,omitempty"`
	// Default description for items created from this template
	DefaultDescription string `json:"default_description,omitempty"`
	// DefaultManufacturer holds the value of the "default_manufacturer" field.
	DefaultManufacturer string `json:"default_manufacturer,omitempty"`
	// Default model number for items created from this template
	DefaultModelNumber string `json:"default_model_number,omitempty"`
	// DefaultLifetimeWarranty holds the value of the "default_lifetime_warranty" field.
	DefaultLifetimeWarranty bool `json:"default_lifetime_warranty,omitempty"`
	// DefaultWarrantyDetails holds the value of the "default_warranty_details" field.
	DefaultWarrantyDetails string `json:"default_warranty_details,omitempty"`
	// Whether to include warranty fields in items created from this template
	IncludeWarrantyFields bool `json:"include_warranty_fields,omitempty"`
	// Whether to include purchase fields in items created from this template
	IncludePurchaseFields bool `json:"include_purchase_fields,omitempty"`
	// Whether to include sold fields in items created from this template
	IncludeSoldFields bool `json:"include_sold_fields,omitempty"`
	// Default tag IDs for items created from this template
	DefaultTagIds []uuid.UUID `json:"default_tag_ids,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the EntityTemplateQuery when eager-loading is set.
	Edges                    EntityTemplateEdges `json:"edges"`
	entity_template_location *uuid.UUID
	group_entity_templates   *uuid.UUID
	selectValues             sql.SelectValues
}

// EntityTemplateEdges holds the relations/edges for other nodes in the graph.
type EntityTemplateEdges struct {
	// Group holds the value of the group edge.
	Group *Group `json:"group,omitempty"`
	// Fields holds the value of the fields edge.
	Fields []*TemplateField `json:"fields,omitempty"`
	// Location holds the value of the location edge.
	Location *Entity `json:"location,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [3]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 EntityTemplateEdges) 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"}
}

// FieldsOrErr returns the Fields value or an error if the edge
// was not loaded in eager-loading.
func (e EntityTemplateEdges) FieldsOrErr() ([]*TemplateField, error) {
	if e.loadedTypes[1] {
		return e.Fields, nil
	}
	return nil, &NotLoadedError{edge: "fields"}
}

// 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 EntityTemplateEdges) LocationOrErr() (*Entity, error) {
	if e.Location != nil {
		return e.Location, nil
	} else if e.loadedTypes[2] {
		return nil, &NotFoundError{label: entity.Label}
	}
	return nil, &NotLoadedError{edge: "location"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*EntityTemplate) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case entitytemplate.FieldDefaultTagIds:
			values[i] = new([]byte)
		case entitytemplate.FieldDefaultInsured, entitytemplate.FieldDefaultLifetimeWarranty, entitytemplate.FieldIncludeWarrantyFields, entitytemplate.FieldIncludePurchaseFields, entitytemplate.FieldIncludeSoldFields:
			values[i] = new(sql.NullBool)
		case entitytemplate.FieldDefaultQuantity:
			values[i] = new(sql.NullFloat64)
		case entitytemplate.FieldName, entitytemplate.FieldDescription, entitytemplate.FieldNotes, entitytemplate.FieldDefaultName, entitytemplate.FieldDefaultDescription, entitytemplate.FieldDefaultManufacturer, entitytemplate.FieldDefaultModelNumber, entitytemplate.FieldDefaultWarrantyDetails:
			values[i] = new(sql.NullString)
		case entitytemplate.FieldCreatedAt, entitytemplate.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		case entitytemplate.FieldID:
			values[i] = new(uuid.UUID)
		case entitytemplate.ForeignKeys[0]: // entity_template_location
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		case entitytemplate.ForeignKeys[1]: // group_entity_templates
			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 EntityTemplate fields.
func (_m *EntityTemplate) 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 entitytemplate.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 entitytemplate.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 entitytemplate.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 entitytemplate.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 entitytemplate.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 entitytemplate.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 entitytemplate.FieldDefaultQuantity:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field default_quantity", values[i])
			} else if value.Valid {
				_m.DefaultQuantity = value.Float64
			}
		case entitytemplate.FieldDefaultInsured:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field default_insured", values[i])
			} else if value.Valid {
				_m.DefaultInsured = value.Bool
			}
		case entitytemplate.FieldDefaultName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field default_name", values[i])
			} else if value.Valid {
				_m.DefaultName = value.String
			}
		case entitytemplate.FieldDefaultDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field default_description", values[i])
			} else if value.Valid {
				_m.DefaultDescription = value.String
			}
		case entitytemplate.FieldDefaultManufacturer:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field default_manufacturer", values[i])
			} else if value.Valid {
				_m.DefaultManufacturer = value.String
			}
		case entitytemplate.FieldDefaultModelNumber:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field default_model_number", values[i])
			} else if value.Valid {
				_m.DefaultModelNumber = value.String
			}
		case entitytemplate.FieldDefaultLifetimeWarranty:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field default_lifetime_warranty", values[i])
			} else if value.Valid {
				_m.DefaultLifetimeWarranty = value.Bool
			}
		case entitytemplate.FieldDefaultWarrantyDetails:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field default_warranty_details", values[i])
			} else if value.Valid {
				_m.DefaultWarrantyDetails = value.String
			}
		case entitytemplate.FieldIncludeWarrantyFields:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field include_warranty_fields", values[i])
			} else if value.Valid {
				_m.IncludeWarrantyFields = value.Bool
			}
		case entitytemplate.FieldIncludePurchaseFields:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field include_purchase_fields", values[i])
			} else if value.Valid {
				_m.IncludePurchaseFields = value.Bool
			}
		case entitytemplate.FieldIncludeSoldFields:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field include_sold_fields", values[i])
			} else if value.Valid {
				_m.IncludeSoldFields = value.Bool
			}
		case entitytemplate.FieldDefaultTagIds:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field default_tag_ids", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.DefaultTagIds); err != nil {
					return fmt.Errorf("unmarshal field default_tag_ids: %w", err)
				}
			}
		case entitytemplate.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field entity_template_location", values[i])
			} else if value.Valid {
				_m.entity_template_location = new(uuid.UUID)
				*_m.entity_template_location = *value.S.(*uuid.UUID)
			}
		case entitytemplate.ForeignKeys[1]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field group_entity_templates", values[i])
			} else if value.Valid {
				_m.group_entity_templates = new(uuid.UUID)
				*_m.group_entity_templates = *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 EntityTemplate.
// This includes values selected through modifiers, order, etc.
func (_m *EntityTemplate) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// QueryGroup queries the "group" edge of the EntityTemplate entity.
func (_m *EntityTemplate) QueryGroup() *GroupQuery {
	return NewEntityTemplateClient(_m.config).QueryGroup(_m)
}

// QueryFields queries the "fields" edge of the EntityTemplate entity.
func (_m *EntityTemplate) QueryFields() *TemplateFieldQuery {
	return NewEntityTemplateClient(_m.config).QueryFields(_m)
}

// QueryLocation queries the "location" edge of the EntityTemplate entity.
func (_m *EntityTemplate) QueryLocation() *EntityQuery {
	return NewEntityTemplateClient(_m.config).QueryLocation(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *EntityTemplate) String() string {
	var builder strings.Builder
	builder.WriteString("EntityTemplate(")
	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("notes=")
	builder.WriteString(_m.Notes)
	builder.WriteString(", ")
	builder.WriteString("default_quantity=")
	builder.WriteString(fmt.Sprintf("%v", _m.DefaultQuantity))
	builder.WriteString(", ")
	builder.WriteString("default_insured=")
	builder.WriteString(fmt.Sprintf("%v", _m.DefaultInsured))
	builder.WriteString(", ")
	builder.WriteString("default_name=")
	builder.WriteString(_m.DefaultName)
	builder.WriteString(", ")
	builder.WriteString("default_description=")
	builder.WriteString(_m.DefaultDescription)
	builder.WriteString(", ")
	builder.WriteString("default_manufacturer=")
	builder.WriteString(_m.DefaultManufacturer)
	builder.WriteString(", ")
	builder.WriteString("default_model_number=")
	builder.WriteString(_m.DefaultModelNumber)
	builder.WriteString(", ")
	builder.WriteString("default_lifetime_warranty=")
	builder.WriteString(fmt.Sprintf("%v", _m.DefaultLifetimeWarranty))
	builder.WriteString(", ")
	builder.WriteString("default_warranty_details=")
	builder.WriteString(_m.DefaultWarrantyDetails)
	builder.WriteString(", ")
	builder.WriteString("include_warranty_fields=")
	builder.WriteString(fmt.Sprintf("%v", _m.IncludeWarrantyFields))
	builder.WriteString(", ")
	builder.WriteString("include_purchase_fields=")
	builder.WriteString(fmt.Sprintf("%v", _m.IncludePurchaseFields))
	builder.WriteString(", ")
	builder.WriteString("include_sold_fields=")
	builder.WriteString(fmt.Sprintf("%v", _m.IncludeSoldFields))
	builder.WriteString(", ")
	builder.WriteString("default_tag_ids=")
	builder.WriteString(fmt.Sprintf("%v", _m.DefaultTagIds))
	builder.WriteByte(')')
	return builder.String()
}

// EntityTemplates is a parsable slice of EntityTemplate.
type EntityTemplates []*EntityTemplate