Files
Investidor-V2/resources/js/lib/investor-guidance-finance.ts
T
nala 1106509116
tests / ci (push) Canceled after 0s
vrsao 2
2026-10-08 14:02:01 +02:00

77 lines
2.7 KiB
TypeScript

import {
forecastBusinessPlan,
restoreBusinessPlanSnapshot,
compareBusinessScenarios,
} from './business-financial-plan.ts';
import { buildProjectDossierRows } from './project-dossier.ts';
import { restoreFinancialToolsSnapshot } from './financial-calculators.ts';
/** Reuses the dossier's existing report for loan, budget, funding and break-even. */
export function guidanceFinancialTools(draft: Record<string, unknown> | null) {
const snapshot =
typeof draft?.financial_tools_snapshot === 'string'
? draft.financial_tools_snapshot
: '';
const assumptions = restoreFinancialToolsSnapshot(snapshot);
if (!assumptions) return null;
const input = {
financial_tools_snapshot: snapshot,
currency: typeof draft?.currency === 'string' ? draft.currency : '',
};
return {
calculator: 'financial-calculators/project-dossier',
snapshotVersion: 1,
assumptions,
rows: buildProjectDossierRows(input).filter(
(row) => row[0] === 'Plano financeiro',
),
};
}
/** The assistant only presents outputs of the existing calculator. */
export function guidanceFinance(draft: Record<string, unknown> | null) {
const snapshot =
typeof draft?.business_plan_snapshot === 'string'
? draft.business_plan_snapshot
: '';
const plan = restoreBusinessPlanSnapshot(snapshot);
if (!plan)
return {
status: 'indeterminate' as const,
reason: 'Sem snapshot financeiro compatível.',
result: null,
scenarios: null,
};
try {
const result = forecastBusinessPlan(plan);
let scenarios: ReturnType<typeof compareBusinessScenarios> | null =
null;
try {
scenarios = compareBusinessScenarios(plan);
} catch {
/* Missing scenario inputs remain indeterminate. */
}
return {
status: 'calculated' as const,
reason: 'Estimativa determinística; pressupostos declarados, sem validação de procura ou financiamento.',
result,
scenarios,
snapshotVersion: (JSON.parse(snapshot) as { version: number })
.version,
assumptions: plan,
calculator: 'business-financial-plan',
tax: 'indeterminate' as const,
};
} catch (error) {
return {
status: 'indeterminate' as const,
reason:
error instanceof Error
? error.message
: 'Pressupostos incompatíveis.',
result: null,
scenarios: null,
};
}
}