206 lines
7.5 KiB
TypeScript
206 lines
7.5 KiB
TypeScript
import { inputText } from './input-text.ts';
|
|
type Analysis = {
|
|
version?: number;
|
|
group?: string;
|
|
kind?: string;
|
|
state?: string;
|
|
need?:
|
|
| string
|
|
| {
|
|
state?: string;
|
|
problem?: string;
|
|
confirmation?: string;
|
|
limitations?: string;
|
|
missing?: string;
|
|
};
|
|
idea?: {
|
|
solution?: string;
|
|
activity?: string;
|
|
stage?: string;
|
|
coverage?: string;
|
|
resources?: string;
|
|
assumptions?: string;
|
|
conditions?: string;
|
|
pending?: string;
|
|
next_action?: string;
|
|
};
|
|
proposal?: string;
|
|
basis?: string;
|
|
limitations?: string;
|
|
next_action?: string;
|
|
stage?: string;
|
|
resources?: string;
|
|
assumptions?: string;
|
|
conditions?: string;
|
|
relations?: {
|
|
kind: string;
|
|
target_id: string;
|
|
label: string;
|
|
relationship: string;
|
|
basis: string;
|
|
}[];
|
|
evidence?: {
|
|
id?: string;
|
|
statement?: string;
|
|
interpretation?: string;
|
|
source?: string;
|
|
locator?: string;
|
|
period?: string;
|
|
scope?: string;
|
|
coverage?: string;
|
|
verified_on?: string;
|
|
access?: string;
|
|
}[];
|
|
};
|
|
type Source = {
|
|
key?: string;
|
|
title?: string;
|
|
version?: string | number;
|
|
analysis?: { proactive?: Analysis };
|
|
};
|
|
export function proactiveInvestmentRows(
|
|
draft: Record<string, unknown>,
|
|
): Array<[string, string, string, string]> {
|
|
const rows: Array<[string, string, string, string]> = [],
|
|
sources: Source[] = [],
|
|
seen = new Set<string>();
|
|
try {
|
|
const selected = draft.context_opportunity_snapshot
|
|
? JSON.parse(inputText(draft.context_opportunity_snapshot))
|
|
: null;
|
|
const context = draft.context_applicability_snapshot
|
|
? JSON.parse(inputText(draft.context_applicability_snapshot))
|
|
: null;
|
|
if (selected?.choice?.opportunity)
|
|
sources.push(selected.choice.opportunity);
|
|
else if (Array.isArray(context?.opportunity_choices))
|
|
sources.push(
|
|
...context.opportunity_choices.map(
|
|
(c: { opportunity: Source }) => c.opportunity,
|
|
),
|
|
);
|
|
else if (context?.selection?.opportunity)
|
|
sources.push(context.selection.opportunity);
|
|
for (const source of sources) {
|
|
const p = source?.analysis?.proactive;
|
|
if (!p || p.version !== 1 || !source.key || seen.has(source.key))
|
|
continue;
|
|
seen.add(source.key);
|
|
if (
|
|
draft.context_opportunity &&
|
|
draft.context_opportunity !== source.key
|
|
)
|
|
continue;
|
|
const origin = `${source.title ?? 'Ideia por identificar'}; ${source.key}; versão ${source.version ?? 'Por identificar'}`;
|
|
const kind = p.group ?? p.kind;
|
|
const privateNeed = typeof p.need === 'object' ? p.need : null;
|
|
rows.push([
|
|
'Localização',
|
|
'Origem da análise e ideia',
|
|
source.title ?? 'Por identificar',
|
|
origin,
|
|
]);
|
|
if (kind !== 'exists')
|
|
rows.push([
|
|
'Localização',
|
|
'Estado da necessidade',
|
|
(privateNeed?.state ?? p.state) === 'confirmed'
|
|
? 'Necessidade confirmada no âmbito documentado; não comprova viabilidade comercial'
|
|
: 'Hipótese analítica; informação económica por confirmar',
|
|
origin,
|
|
]);
|
|
if (kind !== 'exists')
|
|
rows.push([
|
|
'Localização',
|
|
'Necessidade identificada',
|
|
privateNeed?.problem ??
|
|
(typeof p.need === 'string'
|
|
? p.need
|
|
: 'Por determinar'),
|
|
origin,
|
|
]);
|
|
if (kind === 'ideas')
|
|
rows.push([
|
|
'Localização',
|
|
'Proposta de investimento',
|
|
p.proposal ?? p.idea?.solution ?? 'Por determinar',
|
|
origin,
|
|
]);
|
|
rows.push([
|
|
'Localização',
|
|
'Fundamento da ideia',
|
|
p.basis ?? privateNeed?.confirmation ?? 'Por completar',
|
|
origin,
|
|
]);
|
|
if (kind === 'ideas')
|
|
rows.push([
|
|
'Localização',
|
|
'Etapa e pressupostos',
|
|
[
|
|
p.stage ?? p.idea?.stage,
|
|
p.idea?.coverage,
|
|
p.resources ?? p.idea?.resources,
|
|
p.assumptions ?? p.idea?.assumptions,
|
|
p.conditions ?? p.idea?.conditions,
|
|
]
|
|
.filter(Boolean)
|
|
.join('; ') || 'Por determinar',
|
|
origin,
|
|
]);
|
|
rows.push([
|
|
'Localização',
|
|
'Limitações da ideia',
|
|
[
|
|
p.limitations,
|
|
kind !== 'exists' ? privateNeed?.limitations : null,
|
|
kind !== 'exists' ? privateNeed?.missing : null,
|
|
kind === 'ideas' ? p.idea?.pending : null,
|
|
]
|
|
.filter(Boolean)
|
|
.join('; ') || 'Por completar',
|
|
origin,
|
|
]);
|
|
rows.push([
|
|
'Localização',
|
|
'Próxima acção da ideia',
|
|
p.next_action ?? p.idea?.next_action ?? 'Por determinar',
|
|
origin,
|
|
]);
|
|
for (const r of p.relations ?? [])
|
|
rows.push([
|
|
'Localização',
|
|
'Relação documentada ou hipótese',
|
|
`${r.label}; ${r.relationship}; sem contrato, acesso ou participação presumidos`,
|
|
`${origin}; ${r.kind}:${r.target_id}; ${r.basis}`,
|
|
]);
|
|
for (const e of p.evidence ?? [])
|
|
rows.push([
|
|
'Localização',
|
|
'Evidência da ideia',
|
|
[
|
|
e.statement,
|
|
e.interpretation
|
|
? `Interpretação: ${e.interpretation}`
|
|
: null,
|
|
`Período: ${e.period || 'Por determinar'}`,
|
|
`Abrangência: ${e.scope || 'Por determinar'}`,
|
|
`Cobertura: ${e.coverage || 'Por determinar'}`,
|
|
`Verificação: ${e.verified_on || 'Por determinar'}`,
|
|
]
|
|
.filter(Boolean)
|
|
.join('; '),
|
|
`${origin}; fonte: ${e.source || 'Por identificar'}; localizador: ${e.locator || 'Por identificar'}`,
|
|
]);
|
|
rows.push([
|
|
'Localização',
|
|
'Limites da preparação proactiva',
|
|
'Não comprova contrato, encomenda, participação disponível, energia acessível, terra disponível, viabilidade ou benefício fiscal. Informação em falta não é zero.',
|
|
origin,
|
|
]);
|
|
}
|
|
} catch {
|
|
/* Preserve unreadable original context; do not reconstruct an economic conclusion. */
|
|
}
|
|
return rows;
|
|
}
|