import { Board } from './board.model'; export const cabinetTypes = ['mcc', 'g650', 'g250', 'g350', 'g430', 'g450', 'g700'] as const; export type CabinetType = typeof cabinetTypes[number]; export class Cabinet { hardwareVintage: number; serialNumber: string; region: number; firmware: string; recoveryRule: string; type: CabinetType; ipV6Address: string; controller: string; name: string; number: number; ipAddress: string; registered: 'y' | 'n'; boards: Board[] = []; slots: Board[] | null[] = []; public static fromRaw(raw: RawCabinet, boards: Board[]): Cabinet { const cabinet = new Cabinet(); // TODO: an object mapper lib would be nice.. cabinet.hardwareVintage = Number(raw.Hardware_Vintage); cabinet.serialNumber = raw.Serial_Number; cabinet.region = Number(raw.Region); cabinet.firmware = raw.Firmware_Version; cabinet.recoveryRule = raw.Recovery_Rule; cabinet.type = raw.Type as CabinetType; cabinet.ipV6Address = raw.IPv6_Address; cabinet.ipAddress = raw.IP_Address; cabinet.controller = raw.Controller; cabinet.name = raw.Name; cabinet.number = Number(raw.Number); cabinet.registered = raw.Registered as 'y' | 'n'; cabinet.boards = boards.filter((board) => board.cabinet === cabinet.number); cabinet.initSlots(); return cabinet; } initSlots() { let arraySize = 0; switch (this.type) { case 'mcc': arraySize = 20; break; case 'g700': arraySize = 4; break; case 'g650': arraySize = 14; break; case 'g450': arraySize = 9; break; case 'g430': arraySize = 3; break; case 'g350': arraySize = 7; break; case 'g250': arraySize = 2; break; } this.slots = Array(arraySize).fill(null); this.boards.forEach((board) => { // Decrement needed in order to match zero-based index of arrays. this.slots[board.slot - 1] = board; }); } } export class RawCabinet { Hardware_Vintage: string; Serial_Number: string; Region: string; Firmware_Version: string; Recovery_Rule: string; Type: string; IPv6_Address: string; Controller: string; Name: string; Number: string; IP_Address: string; Registered: string; }