import { areMocksEnabled } from "@/mocks/env"; export type MockDepartment = { id: string; code: string; name: string; }; const seedDepartments: MockDepartment[] = [ { id: "dept-1", code: "OPS", name: "Operations" }, { id: "dept-2", code: "FIN", name: "Finance" }, { id: "dept-3", code: "ENG", name: "Engineering" }, { id: "dept-4", code: "ADM", name: "Administration" }, ]; let departmentStore: MockDepartment[] = seedDepartments.map((department) => ({ ...department })); export function getMockDepartments(): MockDepartment[] { if (!areMocksEnabled()) { return []; } return departmentStore.map((department) => ({ ...department })); } export function getMockDepartment(id: string): MockDepartment | undefined { return getMockDepartments().find((department) => department.id === id); } export function upsertMockDepartment(department: MockDepartment): MockDepartment { const index = departmentStore.findIndex((row) => row.id === department.id); const next = { ...department }; if (index === -1) { departmentStore = [...departmentStore, next]; } else { departmentStore = [ ...departmentStore.slice(0, index), next, ...departmentStore.slice(index + 1), ]; } return { ...next }; } export function resetMockDepartments(): void { departmentStore = seedDepartments.map((department) => ({ ...department })); }