import { EntityEnum } from '@sky-distribution/policy-service-interfaces/lib/rpc/Quote'; export interface HavingEntityType { baseData?: { jobType?: string; }; } export const getEntityType = (input: T): EntityEnum => { const jobType = (input?.baseData?.jobType?.toLowerCase() ?? 'submission') as unknown; const entity = EntityEnum[jobType as keyof typeof EntityEnum]; if (!entity) { throw new Error(`No entity type for jobType (${String(jobType)}).`); } return entity; }; export type PossiblyIdentifiable = { quoteID?: string; } & { jobID?: string; }; export const getEntityID = (possiblyIdentifiable: T): string => { const identifiers = ['quoteID', 'jobID'] as (keyof PossiblyIdentifiable)[]; const idValues = identifiers.map((idKey) => possiblyIdentifiable[idKey]) .filter(Boolean) as string[]; if (idValues.length < 1) { throw Error('Could not retrieve entity identifier'); } return idValues[0]; };