import { operationTreatments } from './iva-operations.ts'; export type IvaActivityOperation = | 'internal_general_net' | 'internal_reduced_17a_net'; export type IvaActivityTreatment = { operation: IvaActivityOperation; rate: 16 | 5; label: string; article: string; conditions: string[]; /** True when the plan has a documented activity; otherwise the general rate is only the default. */ fromActivity: boolean; }; const treatment = ( id: string, operation: IvaActivityOperation, fromActivity: boolean, ): IvaActivityTreatment => { const row = operationTreatments.find((item) => item.id === id)!; return { operation, rate: operation === 'internal_general_net' ? 16 : 5, label: row.label, article: row.article, conditions: [...row.conditions], fromActivity, }; }; /** * IVA follows the activity, not a choice of rate (owner decision 04/12/2026). * CAE-Rev.2 subclasses that are the operations of artigo 15(10) take the * reduced rate of artigo 17-A; every other activity takes the general rate. * The conditions of the law are shown for the investor to confirm. */ export function ivaTreatmentForCae(code?: string | null): IvaActivityTreatment { const cae = (code ?? '').trim(); if (/^86\d{3}$/.test(cae)) return treatment('private_health', 'internal_reduced_17a_net', true); if (cae === '85492') return treatment('private_training', 'internal_reduced_17a_net', true); if (/^85(1\d{2}|2[12]\d|300)$/.test(cae)) return treatment('private_education', 'internal_reduced_17a_net', true); return treatment('general', 'internal_general_net', cae !== ''); }