export type IvaIssue = { category: | 'missing_field' | 'invalid_value' | 'out_of_scope' | 'period_unavailable' | 'system_configuration'; field: string | null; label: string; received: unknown; expected: string; message: string; }; export type IvaDiagnostic = { label: string; rule_version: number; validity: { start: string; end: string | null }; source: { title?: string; diploma?: string; article?: string; url?: string; }; issues: IvaIssue[]; }; export const ivaIssueCategories = { missing_field: 'Campo em falta', invalid_value: 'Valor inválido', out_of_scope: 'Fora do âmbito', period_unavailable: 'Regra indisponível para o período', system_configuration: 'Configuração do sistema', }; export function ivaReceived(value: unknown): string { const labels: Record = { domestic: 'Operação interna', internal_general_net: 'Operação interna à taxa geral, sobre base líquida', import: 'Importação', export: 'Exportação', refund: 'Reembolso', unknown: 'Não sei', non_resident: 'Operação com não residente', other: 'Outra operação', }; return typeof value === 'string' && value !== '' ? (labels[value] ?? value) : 'Não recebido'; } export function ivaIssueText(issue: IvaIssue): string { return `${issue.label}: ${ivaIssueCategories[issue.category]}. Recebido: ${ivaReceived(issue.received)}. Esperado: ${issue.expected}. ${issue.message}`; }