import type { AssetCatalog } from "./asset-catalog.aggregate"; import type { AssetDefinitionSpec, AssetFieldType } from "./asset-definition"; import { AssetDefinitionValues } from "./value-objects/asset-definition-values"; const FIELDS: readonly [string, string, AssetFieldType, string][] = [ ["brand", "Marca", "text", ""], ["model", "Modelo", "text", ""], ["serial", "Número de serie", "text", ""], ["processor", "Procesador", "text", ""], ["memory", "Memoria RAM", "number", "GB"], ["storage", "Almacenamiento", "text", ""], ["os", "Sistema operativo", "text", ""], ["hostname", "Nombre de equipo", "text", ""], ["screen_size", "Pulgadas", "number", "pulgadas"], ["resolution", "Resolución", "text", ""], ["connections", "Conexiones", "text", ""], ["ip", "Dirección IP", "text", ""], ["mac", "Dirección MAC", "text", ""], ["ports", "Número de puertos", "number", ""], ["speed", "Velocidad de red", "text", ""], ["poe", "PoE", "boolean", ""], ["wifi", "Estándar Wi-Fi", "text", ""], ["capacity", "Capacidad útil", "text", ""], ["disks", "Discos", "text", ""], ["raid", "RAID", "text", ""], ["printing", "Tecnología de impresión", "text", ""], ["color", "Impresión en color", "boolean", ""], ["duplex", "Doble cara", "boolean", ""], ["imei", "IMEI", "text", ""], ["phone", "Número de teléfono", "text", ""], ["carrier", "Operador móvil", "text", ""], ["power", "Potencia", "number", "VA"], ["battery", "Autonomía", "number", "minutos"], ["purchased_on", "Fecha de compra", "date", ""], ["warranty_until", "Fin de garantía", "date", ""], ]; const COMMON = ["brand", "model", "serial", "purchased_on", "warranty_until"]; const TEMPLATES: readonly [string, string, readonly string[]][] = [ [ "laptop", "Portátil", [ "processor", "memory", "storage", "os", "hostname", "screen_size", "resolution", "connections", "ip", "mac", ], ], [ "desktop", "PC de sobremesa", ["processor", "memory", "storage", "os", "hostname", "connections", "ip", "mac"], ], ["monitor", "Monitor", ["screen_size", "resolution", "connections"]], ["printer", "Impresora", ["printing", "color", "duplex", "connections", "ip", "mac"]], ["router", "Router", ["ports", "speed", "wifi", "ip", "mac"]], ["firewall", "Firewall", ["ports", "speed", "ip", "mac"]], ["switch", "Switch", ["ports", "speed", "poe", "ip", "mac"]], ["access_point", "Punto de acceso Wi-Fi", ["wifi", "poe", "ip", "mac"]], ["nas", "NAS", ["processor", "memory", "disks", "capacity", "raid", "os", "ip", "mac"]], [ "server", "Servidor", ["processor", "memory", "storage", "disks", "raid", "os", "hostname", "ip", "mac"], ], ["smartphone", "Smartphone", ["os", "storage", "screen_size", "imei", "phone", "carrier"]], ["ups", "SAI", ["power", "battery", "connections"]], ]; export function seedAssetCatalog(catalog: AssetCatalog) { let current = catalog; const add = (key: string, input: AssetDefinitionSpec) => { const values = AssetDefinitionValues.create(input); if (!values.isSuccess) { throw new Error("Definición inicial de activos inválida."); } const result = current.seed(key, values.data); if (!result.isSuccess) { throw new Error("Catálogo inicial de activos inconsistente."); } current = result.data; }; for (const [key, name, type, unit] of FIELDS) { add(`field:${key}`, { kind: "field", name, description: "", type, unit, choices: [] }); } for (const [key, name, fields] of TEMPLATES) { const references = [...COMMON, ...fields].map((field) => { const id = current.definitions .find((item) => item.stockKey.getOrUndefined() === `field:${field}`) ?.id.toPrimitive(); if (!id) { throw new Error("Campo inicial de activos ausente."); } return { fieldId: id, required: false }; }); add(`template:${key}`, { kind: "template", name, description: "", fields: references }); } return current; }