import { DomainConflictError } from '../../../common/errors/domain-conflict.error';
type IncidentInput = Record<string, any>;
function object(input: unknown, code: string): asserts input is IncidentInput {
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new DomainConflictError(code);
}
function text(value: unknown, max: number, code: string): asserts value is string {
if (typeof value !== 'string' || value.trim().length === 0 || value.length > max) throw new DomainConflictError(code);
}
function optionalText(value: unknown, max: number, code: string): void {
if (value !== undefined && value !== null) text(value, max, code);
}
function scope(input: unknown, code: string): asserts input is IncidentInput {
object(input, code);
text(input.organizationId, 200, code);
text(input.locationId, 200, code);
}
function optionalDateTime(value: unknown, code: string): void {
if (value === undefined || value === null) return;
if (typeof value !== 'string' || value.length > 100 || Number.isNaN(Date.parse(value))) throw new DomainConflictError(code);
}
export function assertIncidentCreateInput(input: unknown): asserts input is IncidentInput {
const code = 'incidents.input_invalid';
scope(input, code);
text(input.incidentType, 100, code);
text(input.severity, 100, code);
text(input.title, 500, code);
optionalText(input.description, 10000, code);
optionalDateTime(input.occurredAt, code);
optionalText(input.employeeId, 200, code);
optionalText(input.reportedByEmployeeId, 200, code);
optionalText(input.relatedEntityType, 100, code);
optionalText(input.relatedEntityId, 200, code);
}
export function assertIncidentAssignInput(input: unknown): asserts input is IncidentInput {
const code = 'incidents.input_invalid';
scope(input, code);
text(input.incidentId, 200, code);
text(input.employeeId, 200, code);
}
export function assertIncidentResolveInput(input: unknown): asserts input is IncidentInput {
const code = 'incidents.input_invalid';
scope(input, code);
text(input.incidentId, 200, code);
text(input.resolution, 10000, code);
}
