import type { UniqueID } from "@repo/rdx-ddd"; import type { Maybe } from "@repo/rdx-utils"; import type { CatalogResponseDTO } from "../../common"; import type { ResourceCatalog } from "../domain/resource-catalog.aggregate"; export function buildCatalogResponse( catalog: ResourceCatalog, scope: Maybe ): CatalogResponseDTO { return { items: catalog.visible(scope).map((item) => ({ id: item.id.toPrimitive(), companyId: item.companyId.getOrUndefined()?.toPrimitive() ?? null, builtin: item.stockKey.getOrUndefined() !== undefined, active: item.active, effectiveActive: catalog.active(item, scope), overridden: catalog.availability.some( (entry) => entry.companyId.equals(scope.getOrUndefined()) && entry.definitionId.equals(item.id) && entry.active.getOrUndefined() !== undefined ), values: item.values.data, bindings: item.bindings.map((binding) => ({ id: binding.id.toPrimitive(), fieldId: binding.fieldId.toPrimitive(), required: binding.required, })), })), }; }