Skip to content

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

8.5 KB
Raw Blame
// 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/attachment"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entity"
)

// Attachment is the model entity for the Attachment schema.
type Attachment 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"`
	// Type holds the value of the "type" field.
	Type attachment.Type `json:"type,omitempty"`
	// Primary holds the value of the "primary" field.
	Primary bool `json:"primary,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Path holds the value of the "path" field.
	Path string `json:"path,omitempty"`
	// MimeType holds the value of the "mime_type" field.
	MimeType string `json:"mime_type,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the AttachmentQuery when eager-loading is set.
	Edges                AttachmentEdges `json:"edges"`
	attachment_thumbnail *uuid.UUID
	entity_attachments   *uuid.UUID
	selectValues         sql.SelectValues
}

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

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

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

// scanValues returns the types for scanning values from sql.Rows.
func (*Attachment) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case attachment.FieldPrimary:
			values[i] = new(sql.NullBool)
		case attachment.FieldType, attachment.FieldTitle, attachment.FieldPath, attachment.FieldMimeType:
			values[i] = new(sql.NullString)
		case attachment.FieldCreatedAt, attachment.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		case attachment.FieldID:
			values[i] = new(uuid.UUID)
		case attachment.ForeignKeys[0]: // attachment_thumbnail
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		case attachment.ForeignKeys[1]: // entity_attachments
			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 Attachment fields.
func (_m *Attachment) 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 attachment.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 attachment.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 attachment.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 attachment.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 = attachment.Type(value.String)
			}
		case attachment.FieldPrimary:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field primary", values[i])
			} else if value.Valid {
				_m.Primary = value.Bool
			}
		case attachment.FieldTitle:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field title", values[i])
			} else if value.Valid {
				_m.Title = value.String
			}
		case attachment.FieldPath:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field path", values[i])
			} else if value.Valid {
				_m.Path = value.String
			}
		case attachment.FieldMimeType:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field mime_type", values[i])
			} else if value.Valid {
				_m.MimeType = value.String
			}
		case attachment.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field attachment_thumbnail", values[i])
			} else if value.Valid {
				_m.attachment_thumbnail = new(uuid.UUID)
				*_m.attachment_thumbnail = *value.S.(*uuid.UUID)
			}
		case attachment.ForeignKeys[1]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field entity_attachments", values[i])
			} else if value.Valid {
				_m.entity_attachments = new(uuid.UUID)
				*_m.entity_attachments = *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 Attachment.
// This includes values selected through modifiers, order, etc.
func (_m *Attachment) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// QueryEntity queries the "entity" edge of the Attachment entity.
func (_m *Attachment) QueryEntity() *EntityQuery {
	return NewAttachmentClient(_m.config).QueryEntity(_m)
}

// QueryThumbnail queries the "thumbnail" edge of the Attachment entity.
func (_m *Attachment) QueryThumbnail() *AttachmentQuery {
	return NewAttachmentClient(_m.config).QueryThumbnail(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *Attachment) String() string {
	var builder strings.Builder
	builder.WriteString("Attachment(")
	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("type=")
	builder.WriteString(fmt.Sprintf("%v", _m.Type))
	builder.WriteString(", ")
	builder.WriteString("primary=")
	builder.WriteString(fmt.Sprintf("%v", _m.Primary))
	builder.WriteString(", ")
	builder.WriteString("title=")
	builder.WriteString(_m.Title)
	builder.WriteString(", ")
	builder.WriteString("path=")
	builder.WriteString(_m.Path)
	builder.WriteString(", ")
	builder.WriteString("mime_type=")
	builder.WriteString(_m.MimeType)
	builder.WriteByte(')')
	return builder.String()
}

// Attachments is a parsable slice of Attachment.
type Attachments []*Attachment