Skip to content

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

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

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/attachment"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entity"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entityfield"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entitytype"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry"
	"github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag"
)

// EntityCreate is the builder for creating a Entity entity.
type EntityCreate struct {
	config
	mutation *EntityMutation
	hooks    []Hook
}

// SetCreatedAt sets the "created_at" field.
func (_c *EntityCreate) SetCreatedAt(v time.Time) *EntityCreate {
	_c.mutation.SetCreatedAt(v)
	return _c
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *EntityCreate) SetNillableCreatedAt(v *time.Time) *EntityCreate {
	if v != nil {
		_c.SetCreatedAt(*v)
	}
	return _c
}

// SetUpdatedAt sets the "updated_at" field.
func (_c *EntityCreate) SetUpdatedAt(v time.Time) *EntityCreate {
	_c.mutation.SetUpdatedAt(v)
	return _c
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *EntityCreate) SetNillableUpdatedAt(v *time.Time) *EntityCreate {
	if v != nil {
		_c.SetUpdatedAt(*v)
	}
	return _c
}

// SetName sets the "name" field.
func (_c *EntityCreate) SetName(v string) *EntityCreate {
	_c.mutation.SetName(v)
	return _c
}

// SetDescription sets the "description" field.
func (_c *EntityCreate) SetDescription(v string) *EntityCreate {
	_c.mutation.SetDescription(v)
	return _c
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_c *EntityCreate) SetNillableDescription(v *string) *EntityCreate {
	if v != nil {
		_c.SetDescription(*v)
	}
	return _c
}

// SetImportRef sets the "import_ref" field.
func (_c *EntityCreate) SetImportRef(v string) *EntityCreate {
	_c.mutation.SetImportRef(v)
	return _c
}

// SetNillableImportRef sets the "import_ref" field if the given value is not nil.
func (_c *EntityCreate) SetNillableImportRef(v *string) *EntityCreate {
	if v != nil {
		_c.SetImportRef(*v)
	}
	return _c
}

// SetNotes sets the "notes" field.
func (_c *EntityCreate) SetNotes(v string) *EntityCreate {
	_c.mutation.SetNotes(v)
	return _c
}

// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_c *EntityCreate) SetNillableNotes(v *string) *EntityCreate {
	if v != nil {
		_c.SetNotes(*v)
	}
	return _c
}

// SetQuantity sets the "quantity" field.
func (_c *EntityCreate) SetQuantity(v float64) *EntityCreate {
	_c.mutation.SetQuantity(v)
	return _c
}

// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_c *EntityCreate) SetNillableQuantity(v *float64) *EntityCreate {
	if v != nil {
		_c.SetQuantity(*v)
	}
	return _c
}

// SetInsured sets the "insured" field.
func (_c *EntityCreate) SetInsured(v bool) *EntityCreate {
	_c.mutation.SetInsured(v)
	return _c
}

// SetNillableInsured sets the "insured" field if the given value is not nil.
func (_c *EntityCreate) SetNillableInsured(v *bool) *EntityCreate {
	if v != nil {
		_c.SetInsured(*v)
	}
	return _c
}

// SetArchived sets the "archived" field.
func (_c *EntityCreate) SetArchived(v bool) *EntityCreate {
	_c.mutation.SetArchived(v)
	return _c
}

// SetNillableArchived sets the "archived" field if the given value is not nil.
func (_c *EntityCreate) SetNillableArchived(v *bool) *EntityCreate {
	if v != nil {
		_c.SetArchived(*v)
	}
	return _c
}

// SetAssetID sets the "asset_id" field.
func (_c *EntityCreate) SetAssetID(v int64) *EntityCreate {
	_c.mutation.SetAssetID(v)
	return _c
}

// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
func (_c *EntityCreate) SetNillableAssetID(v *int64) *EntityCreate {
	if v != nil {
		_c.SetAssetID(*v)
	}
	return _c
}

// SetSyncChildEntityLocations sets the "sync_child_entity_locations" field.
func (_c *EntityCreate) SetSyncChildEntityLocations(v bool) *EntityCreate {
	_c.mutation.SetSyncChildEntityLocations(v)
	return _c
}

// SetNillableSyncChildEntityLocations sets the "sync_child_entity_locations" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSyncChildEntityLocations(v *bool) *EntityCreate {
	if v != nil {
		_c.SetSyncChildEntityLocations(*v)
	}
	return _c
}

// SetSerialNumber sets the "serial_number" field.
func (_c *EntityCreate) SetSerialNumber(v string) *EntityCreate {
	_c.mutation.SetSerialNumber(v)
	return _c
}

// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSerialNumber(v *string) *EntityCreate {
	if v != nil {
		_c.SetSerialNumber(*v)
	}
	return _c
}

// SetModelNumber sets the "model_number" field.
func (_c *EntityCreate) SetModelNumber(v string) *EntityCreate {
	_c.mutation.SetModelNumber(v)
	return _c
}

// SetNillableModelNumber sets the "model_number" field if the given value is not nil.
func (_c *EntityCreate) SetNillableModelNumber(v *string) *EntityCreate {
	if v != nil {
		_c.SetModelNumber(*v)
	}
	return _c
}

// SetManufacturer sets the "manufacturer" field.
func (_c *EntityCreate) SetManufacturer(v string) *EntityCreate {
	_c.mutation.SetManufacturer(v)
	return _c
}

// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil.
func (_c *EntityCreate) SetNillableManufacturer(v *string) *EntityCreate {
	if v != nil {
		_c.SetManufacturer(*v)
	}
	return _c
}

// SetLifetimeWarranty sets the "lifetime_warranty" field.
func (_c *EntityCreate) SetLifetimeWarranty(v bool) *EntityCreate {
	_c.mutation.SetLifetimeWarranty(v)
	return _c
}

// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil.
func (_c *EntityCreate) SetNillableLifetimeWarranty(v *bool) *EntityCreate {
	if v != nil {
		_c.SetLifetimeWarranty(*v)
	}
	return _c
}

// SetWarrantyExpires sets the "warranty_expires" field.
func (_c *EntityCreate) SetWarrantyExpires(v time.Time) *EntityCreate {
	_c.mutation.SetWarrantyExpires(v)
	return _c
}

// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil.
func (_c *EntityCreate) SetNillableWarrantyExpires(v *time.Time) *EntityCreate {
	if v != nil {
		_c.SetWarrantyExpires(*v)
	}
	return _c
}

// SetWarrantyDetails sets the "warranty_details" field.
func (_c *EntityCreate) SetWarrantyDetails(v string) *EntityCreate {
	_c.mutation.SetWarrantyDetails(v)
	return _c
}

// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil.
func (_c *EntityCreate) SetNillableWarrantyDetails(v *string) *EntityCreate {
	if v != nil {
		_c.SetWarrantyDetails(*v)
	}
	return _c
}

// SetPurchaseDate sets the "purchase_date" field.
func (_c *EntityCreate) SetPurchaseDate(v time.Time) *EntityCreate {
	_c.mutation.SetPurchaseDate(v)
	return _c
}

// SetNillablePurchaseDate sets the "purchase_date" field if the given value is not nil.
func (_c *EntityCreate) SetNillablePurchaseDate(v *time.Time) *EntityCreate {
	if v != nil {
		_c.SetPurchaseDate(*v)
	}
	return _c
}

// SetPurchaseFrom sets the "purchase_from" field.
func (_c *EntityCreate) SetPurchaseFrom(v string) *EntityCreate {
	_c.mutation.SetPurchaseFrom(v)
	return _c
}

// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil.
func (_c *EntityCreate) SetNillablePurchaseFrom(v *string) *EntityCreate {
	if v != nil {
		_c.SetPurchaseFrom(*v)
	}
	return _c
}

// SetPurchasePrice sets the "purchase_price" field.
func (_c *EntityCreate) SetPurchasePrice(v float64) *EntityCreate {
	_c.mutation.SetPurchasePrice(v)
	return _c
}

// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil.
func (_c *EntityCreate) SetNillablePurchasePrice(v *float64) *EntityCreate {
	if v != nil {
		_c.SetPurchasePrice(*v)
	}
	return _c
}

// SetSoldDate sets the "sold_date" field.
func (_c *EntityCreate) SetSoldDate(v time.Time) *EntityCreate {
	_c.mutation.SetSoldDate(v)
	return _c
}

// SetNillableSoldDate sets the "sold_date" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSoldDate(v *time.Time) *EntityCreate {
	if v != nil {
		_c.SetSoldDate(*v)
	}
	return _c
}

// SetSoldTo sets the "sold_to" field.
func (_c *EntityCreate) SetSoldTo(v string) *EntityCreate {
	_c.mutation.SetSoldTo(v)
	return _c
}

// SetNillableSoldTo sets the "sold_to" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSoldTo(v *string) *EntityCreate {
	if v != nil {
		_c.SetSoldTo(*v)
	}
	return _c
}

// SetSoldPrice sets the "sold_price" field.
func (_c *EntityCreate) SetSoldPrice(v float64) *EntityCreate {
	_c.mutation.SetSoldPrice(v)
	return _c
}

// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSoldPrice(v *float64) *EntityCreate {
	if v != nil {
		_c.SetSoldPrice(*v)
	}
	return _c
}

// SetSoldNotes sets the "sold_notes" field.
func (_c *EntityCreate) SetSoldNotes(v string) *EntityCreate {
	_c.mutation.SetSoldNotes(v)
	return _c
}

// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil.
func (_c *EntityCreate) SetNillableSoldNotes(v *string) *EntityCreate {
	if v != nil {
		_c.SetSoldNotes(*v)
	}
	return _c
}

// SetID sets the "id" field.
func (_c *EntityCreate) SetID(v uuid.UUID) *EntityCreate {
	_c.mutation.SetID(v)
	return _c
}

// SetNillableID sets the "id" field if the given value is not nil.
func (_c *EntityCreate) SetNillableID(v *uuid.UUID) *EntityCreate {
	if v != nil {
		_c.SetID(*v)
	}
	return _c
}

// SetGroupID sets the "group" edge to the Group entity by ID.
func (_c *EntityCreate) SetGroupID(id uuid.UUID) *EntityCreate {
	_c.mutation.SetGroupID(id)
	return _c
}

// SetGroup sets the "group" edge to the Group entity.
func (_c *EntityCreate) SetGroup(v *Group) *EntityCreate {
	return _c.SetGroupID(v.ID)
}

// SetParentID sets the "parent" edge to the Entity entity by ID.
func (_c *EntityCreate) SetParentID(id uuid.UUID) *EntityCreate {
	_c.mutation.SetParentID(id)
	return _c
}

// SetNillableParentID sets the "parent" edge to the Entity entity by ID if the given value is not nil.
func (_c *EntityCreate) SetNillableParentID(id *uuid.UUID) *EntityCreate {
	if id != nil {
		_c = _c.SetParentID(*id)
	}
	return _c
}

// SetParent sets the "parent" edge to the Entity entity.
func (_c *EntityCreate) SetParent(v *Entity) *EntityCreate {
	return _c.SetParentID(v.ID)
}

// AddChildIDs adds the "children" edge to the Entity entity by IDs.
func (_c *EntityCreate) AddChildIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddChildIDs(ids...)
	return _c
}

// AddChildren adds the "children" edges to the Entity entity.
func (_c *EntityCreate) AddChildren(v ...*Entity) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddChildIDs(ids...)
}

// SetLocationID sets the "location" edge to the Entity entity by ID.
func (_c *EntityCreate) SetLocationID(id uuid.UUID) *EntityCreate {
	_c.mutation.SetLocationID(id)
	return _c
}

// SetNillableLocationID sets the "location" edge to the Entity entity by ID if the given value is not nil.
func (_c *EntityCreate) SetNillableLocationID(id *uuid.UUID) *EntityCreate {
	if id != nil {
		_c = _c.SetLocationID(*id)
	}
	return _c
}

// SetLocation sets the "location" edge to the Entity entity.
func (_c *EntityCreate) SetLocation(v *Entity) *EntityCreate {
	return _c.SetLocationID(v.ID)
}

// AddLocationEntityIDs adds the "location_entities" edge to the Entity entity by IDs.
func (_c *EntityCreate) AddLocationEntityIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddLocationEntityIDs(ids...)
	return _c
}

// AddLocationEntities adds the "location_entities" edges to the Entity entity.
func (_c *EntityCreate) AddLocationEntities(v ...*Entity) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddLocationEntityIDs(ids...)
}

// AddTagIDs adds the "tag" edge to the Tag entity by IDs.
func (_c *EntityCreate) AddTagIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddTagIDs(ids...)
	return _c
}

// AddTag adds the "tag" edges to the Tag entity.
func (_c *EntityCreate) AddTag(v ...*Tag) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddTagIDs(ids...)
}

// SetEntityTypeID sets the "entity_type" edge to the EntityType entity by ID.
func (_c *EntityCreate) SetEntityTypeID(id uuid.UUID) *EntityCreate {
	_c.mutation.SetEntityTypeID(id)
	return _c
}

// SetEntityType sets the "entity_type" edge to the EntityType entity.
func (_c *EntityCreate) SetEntityType(v *EntityType) *EntityCreate {
	return _c.SetEntityTypeID(v.ID)
}

// AddFieldIDs adds the "fields" edge to the EntityField entity by IDs.
func (_c *EntityCreate) AddFieldIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddFieldIDs(ids...)
	return _c
}

// AddFields adds the "fields" edges to the EntityField entity.
func (_c *EntityCreate) AddFields(v ...*EntityField) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddFieldIDs(ids...)
}

// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
func (_c *EntityCreate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddMaintenanceEntryIDs(ids...)
	return _c
}

// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
func (_c *EntityCreate) AddMaintenanceEntries(v ...*MaintenanceEntry) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddMaintenanceEntryIDs(ids...)
}

// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
func (_c *EntityCreate) AddAttachmentIDs(ids ...uuid.UUID) *EntityCreate {
	_c.mutation.AddAttachmentIDs(ids...)
	return _c
}

// AddAttachments adds the "attachments" edges to the Attachment entity.
func (_c *EntityCreate) AddAttachments(v ...*Attachment) *EntityCreate {
	ids := make([]uuid.UUID, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddAttachmentIDs(ids...)
}

// Mutation returns the EntityMutation object of the builder.
func (_c *EntityCreate) Mutation() *EntityMutation {
	return _c.mutation
}

// Save creates the Entity in the database.
func (_c *EntityCreate) Save(ctx context.Context) (*Entity, error) {
	_c.defaults()
	return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (_c *EntityCreate) SaveX(ctx context.Context) *Entity {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (_c *EntityCreate) Exec(ctx context.Context) error {
	_, err := _c.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_c *EntityCreate) ExecX(ctx context.Context) {
	if err := _c.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (_c *EntityCreate) defaults() {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		v := entity.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		v := entity.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	if _, ok := _c.mutation.Quantity(); !ok {
		v := entity.DefaultQuantity
		_c.mutation.SetQuantity(v)
	}
	if _, ok := _c.mutation.Insured(); !ok {
		v := entity.DefaultInsured
		_c.mutation.SetInsured(v)
	}
	if _, ok := _c.mutation.Archived(); !ok {
		v := entity.DefaultArchived
		_c.mutation.SetArchived(v)
	}
	if _, ok := _c.mutation.AssetID(); !ok {
		v := entity.DefaultAssetID
		_c.mutation.SetAssetID(v)
	}
	if _, ok := _c.mutation.SyncChildEntityLocations(); !ok {
		v := entity.DefaultSyncChildEntityLocations
		_c.mutation.SetSyncChildEntityLocations(v)
	}
	if _, ok := _c.mutation.LifetimeWarranty(); !ok {
		v := entity.DefaultLifetimeWarranty
		_c.mutation.SetLifetimeWarranty(v)
	}
	if _, ok := _c.mutation.PurchasePrice(); !ok {
		v := entity.DefaultPurchasePrice
		_c.mutation.SetPurchasePrice(v)
	}
	if _, ok := _c.mutation.SoldPrice(); !ok {
		v := entity.DefaultSoldPrice
		_c.mutation.SetSoldPrice(v)
	}
	if _, ok := _c.mutation.ID(); !ok {
		v := entity.DefaultID()
		_c.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *EntityCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Entity.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Entity.updated_at"`)}
	}
	if _, ok := _c.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Entity.name"`)}
	}
	if v, ok := _c.mutation.Name(); ok {
		if err := entity.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Entity.name": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Description(); ok {
		if err := entity.DescriptionValidator(v); err != nil {
			return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Entity.description": %w`, err)}
		}
	}
	if v, ok := _c.mutation.ImportRef(); ok {
		if err := entity.ImportRefValidator(v); err != nil {
			return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Entity.import_ref": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Notes(); ok {
		if err := entity.NotesValidator(v); err != nil {
			return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Entity.notes": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Quantity(); !ok {
		return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Entity.quantity"`)}
	}
	if _, ok := _c.mutation.Insured(); !ok {
		return &ValidationError{Name: "insured", err: errors.New(`ent: missing required field "Entity.insured"`)}
	}
	if _, ok := _c.mutation.Archived(); !ok {
		return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Entity.archived"`)}
	}
	if _, ok := _c.mutation.AssetID(); !ok {
		return &ValidationError{Name: "asset_id", err: errors.New(`ent: missing required field "Entity.asset_id"`)}
	}
	if _, ok := _c.mutation.SyncChildEntityLocations(); !ok {
		return &ValidationError{Name: "sync_child_entity_locations", err: errors.New(`ent: missing required field "Entity.sync_child_entity_locations"`)}
	}
	if v, ok := _c.mutation.SerialNumber(); ok {
		if err := entity.SerialNumberValidator(v); err != nil {
			return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Entity.serial_number": %w`, err)}
		}
	}
	if v, ok := _c.mutation.ModelNumber(); ok {
		if err := entity.ModelNumberValidator(v); err != nil {
			return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Entity.model_number": %w`, err)}
		}
	}
	if v, ok := _c.mutation.Manufacturer(); ok {
		if err := entity.ManufacturerValidator(v); err != nil {
			return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Entity.manufacturer": %w`, err)}
		}
	}
	if _, ok := _c.mutation.LifetimeWarranty(); !ok {
		return &ValidationError{Name: "lifetime_warranty", err: errors.New(`ent: missing required field "Entity.lifetime_warranty"`)}
	}
	if v, ok := _c.mutation.WarrantyDetails(); ok {
		if err := entity.WarrantyDetailsValidator(v); err != nil {
			return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Entity.warranty_details": %w`, err)}
		}
	}
	if _, ok := _c.mutation.PurchasePrice(); !ok {
		return &ValidationError{Name: "purchase_price", err: errors.New(`ent: missing required field "Entity.purchase_price"`)}
	}
	if _, ok := _c.mutation.SoldPrice(); !ok {
		return &ValidationError{Name: "sold_price", err: errors.New(`ent: missing required field "Entity.sold_price"`)}
	}
	if v, ok := _c.mutation.SoldNotes(); ok {
		if err := entity.SoldNotesValidator(v); err != nil {
			return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Entity.sold_notes": %w`, err)}
		}
	}
	if len(_c.mutation.GroupIDs()) == 0 {
		return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Entity.group"`)}
	}
	if len(_c.mutation.EntityTypeIDs()) == 0 {
		return &ValidationError{Name: "entity_type", err: errors.New(`ent: missing required edge "Entity.entity_type"`)}
	}
	return nil
}

func (_c *EntityCreate) sqlSave(ctx context.Context) (*Entity, error) {
	if err := _c.check(); err != nil {
		return nil, err
	}
	_node, _spec := _c.createSpec()
	if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
			_node.ID = *id
		} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
			return nil, err
		}
	}
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *EntityCreate) createSpec() (*Entity, *sqlgraph.CreateSpec) {
	var (
		_node = &Entity{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(entity.Table, sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID))
	)
	if id, ok := _c.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(entity.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(entity.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.Name(); ok {
		_spec.SetField(entity.FieldName, field.TypeString, value)
		_node.Name = value
	}
	if value, ok := _c.mutation.Description(); ok {
		_spec.SetField(entity.FieldDescription, field.TypeString, value)
		_node.Description = value
	}
	if value, ok := _c.mutation.ImportRef(); ok {
		_spec.SetField(entity.FieldImportRef, field.TypeString, value)
		_node.ImportRef = value
	}
	if value, ok := _c.mutation.Notes(); ok {
		_spec.SetField(entity.FieldNotes, field.TypeString, value)
		_node.Notes = value
	}
	if value, ok := _c.mutation.Quantity(); ok {
		_spec.SetField(entity.FieldQuantity, field.TypeFloat64, value)
		_node.Quantity = value
	}
	if value, ok := _c.mutation.Insured(); ok {
		_spec.SetField(entity.FieldInsured, field.TypeBool, value)
		_node.Insured = value
	}
	if value, ok := _c.mutation.Archived(); ok {
		_spec.SetField(entity.FieldArchived, field.TypeBool, value)
		_node.Archived = value
	}
	if value, ok := _c.mutation.AssetID(); ok {
		_spec.SetField(entity.FieldAssetID, field.TypeInt64, value)
		_node.AssetID = value
	}
	if value, ok := _c.mutation.SyncChildEntityLocations(); ok {
		_spec.SetField(entity.FieldSyncChildEntityLocations, field.TypeBool, value)
		_node.SyncChildEntityLocations = value
	}
	if value, ok := _c.mutation.SerialNumber(); ok {
		_spec.SetField(entity.FieldSerialNumber, field.TypeString, value)
		_node.SerialNumber = value
	}
	if value, ok := _c.mutation.ModelNumber(); ok {
		_spec.SetField(entity.FieldModelNumber, field.TypeString, value)
		_node.ModelNumber = value
	}
	if value, ok := _c.mutation.Manufacturer(); ok {
		_spec.SetField(entity.FieldManufacturer, field.TypeString, value)
		_node.Manufacturer = value
	}
	if value, ok := _c.mutation.LifetimeWarranty(); ok {
		_spec.SetField(entity.FieldLifetimeWarranty, field.TypeBool, value)
		_node.LifetimeWarranty = value
	}
	if value, ok := _c.mutation.WarrantyExpires(); ok {
		_spec.SetField(entity.FieldWarrantyExpires, field.TypeTime, value)
		_node.WarrantyExpires = value
	}
	if value, ok := _c.mutation.WarrantyDetails(); ok {
		_spec.SetField(entity.FieldWarrantyDetails, field.TypeString, value)
		_node.WarrantyDetails = value
	}
	if value, ok := _c.mutation.PurchaseDate(); ok {
		_spec.SetField(entity.FieldPurchaseDate, field.TypeTime, value)
		_node.PurchaseDate = value
	}
	if value, ok := _c.mutation.PurchaseFrom(); ok {
		_spec.SetField(entity.FieldPurchaseFrom, field.TypeString, value)
		_node.PurchaseFrom = value
	}
	if value, ok := _c.mutation.PurchasePrice(); ok {
		_spec.SetField(entity.FieldPurchasePrice, field.TypeFloat64, value)
		_node.PurchasePrice = value
	}
	if value, ok := _c.mutation.SoldDate(); ok {
		_spec.SetField(entity.FieldSoldDate, field.TypeTime, value)
		_node.SoldDate = value
	}
	if value, ok := _c.mutation.SoldTo(); ok {
		_spec.SetField(entity.FieldSoldTo, field.TypeString, value)
		_node.SoldTo = value
	}
	if value, ok := _c.mutation.SoldPrice(); ok {
		_spec.SetField(entity.FieldSoldPrice, field.TypeFloat64, value)
		_node.SoldPrice = value
	}
	if value, ok := _c.mutation.SoldNotes(); ok {
		_spec.SetField(entity.FieldSoldNotes, field.TypeString, value)
		_node.SoldNotes = value
	}
	if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   entity.GroupTable,
			Columns: []string{entity.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.group_entities = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   entity.ParentTable,
			Columns: []string{entity.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.entity_children = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   entity.ChildrenTable,
			Columns: []string{entity.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.LocationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   entity.LocationTable,
			Columns: []string{entity.LocationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.entity_location_entities = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.LocationEntitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   entity.LocationEntitiesTable,
			Columns: []string{entity.LocationEntitiesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.TagIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   entity.TagTable,
			Columns: entity.TagPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.EntityTypeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   entity.EntityTypeTable,
			Columns: []string{entity.EntityTypeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entitytype.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.entity_type_entities = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.FieldsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   entity.FieldsTable,
			Columns: []string{entity.FieldsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entityfield.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   entity.MaintenanceEntriesTable,
			Columns: []string{entity.MaintenanceEntriesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := _c.mutation.AttachmentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   entity.AttachmentsTable,
			Columns: []string{entity.AttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// EntityCreateBulk is the builder for creating many Entity entities in bulk.
type EntityCreateBulk struct {
	config
	err      error
	builders []*EntityCreate
}

// Save creates the Entity entities in the database.
func (_c *EntityCreateBulk) Save(ctx context.Context) ([]*Entity, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*Entity, len(_c.builders))
	mutators := make([]Mutator, len(_c.builders))
	for i := range _c.builders {
		func(i int, root context.Context) {
			builder := _c.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*EntityMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (_c *EntityCreateBulk) SaveX(ctx context.Context) []*Entity {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (_c *EntityCreateBulk) Exec(ctx context.Context) error {
	_, err := _c.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_c *EntityCreateBulk) ExecX(ctx context.Context) {
	if err := _c.Exec(ctx); err != nil {
		panic(err)
	}
}