import { z } from 'zod';
import { SSBClient } from '../apis/ssb.js';
const EconomicContextSchema = z.object({
industry: z.string().optional().describe("NACE-kode for spesifikk bransje"),
region: z.string().optional().describe("Region/fylke"),
include_innovation: z.boolean().default(false).describe("Inkluder innovasjonsstatistikk")
});
export async function getEconomicContext(args: unknown, ssb: SSBClient) {
const params = EconomicContextSchema.parse(args);
// Fetch comprehensive economic statistics from SSB with real data
const [highGrowthData, employmentData, economicIndicators, innovationStats] = await Promise.all([
params.industry ? ssb.getHighGrowthData(params.industry, params.region) : null,
params.industry ? ssb.getEmploymentData(params.industry, params.region) : null,
ssb.getEconomicIndicators(),
params.include_innovation ? ssb.getInnovationStats() : null
]);
const report = `
📊 ØKONOMISK KONTEKST
${params.industry ? `🏷️ Bransje: NACE ${params.industry}` : '🌍 Generell økonomi'}
${params.region ? `📍 Region: ${params.region}` : ''}
${highGrowthData ? `
🚀 HØYVEKSTFORETAK (SSB Tabell ${highGrowthData.tableId}):
${highGrowthData.description}
Periode: ${highGrowthData.period}
${highGrowthData.cached ? '💾 Data fra cache' : '🔄 Ferske data'}
${highGrowthData.trend ? `
📈 TREND:
Retning: ${highGrowthData.trend.direction === 'increasing' ? '📈 Økende' :
highGrowthData.trend.direction === 'decreasing' ? '📉 Synkende' : '➡️ Stabil'}
Endring: ${highGrowthData.trend.percentageChange > 0 ? '+' : ''}${highGrowthData.trend.percentageChange}%
Gjennomsnittlig vekst: ${highGrowthData.trend.averageGrowth}% per periode
Start: ${highGrowthData.trend.startValue.toLocaleString()} foretak
Nå: ${highGrowthData.trend.endValue.toLocaleString()} foretak
` : ''}
${highGrowthData.timeSeries && highGrowthData.timeSeries.length > 0 ? `
📊 TIDSERIE (siste ${Math.min(5, highGrowthData.timeSeries.length)} perioder):
${highGrowthData.timeSeries.slice(-5).map((ts: any) =>
` ${ts.period}: ${ts.value.toLocaleString()} foretak`
).join('\n')}
` : ''}
` : ''}
${employmentData ? `
👥 SYSSELSETTING (SSB Tabell ${employmentData.tableId}):
${employmentData.description}
Periode: ${employmentData.period}
Siste verdi: ${employmentData.latestValue?.toLocaleString() || 'N/A'}
Endring: ${employmentData.change || 'N/A'}
${employmentData.trend ? `
📈 TREND:
Retning: ${employmentData.trend.direction === 'increasing' ? '📈 Økende' :
employmentData.trend.direction === 'decreasing' ? '📉 Synkende' : '➡️ Stabil'}
Total endring: ${employmentData.trend.percentageChange > 0 ? '+' : ''}${employmentData.trend.percentageChange}%
Gjennomsnitt: ${employmentData.trend.averageGrowth}% per periode
` : ''}
` : ''}
${economicIndicators && economicIndicators.length > 0 ? `
📈 ØKONOMISKE INDIKATORER:
${economicIndicators.map((ind: any, idx: number) =>
`${idx + 1}. ${ind.label}
Periode: ${ind.period}
Table ID: ${ind.tableId}`
).join('\n\n')}
` : ''}
${innovationStats && innovationStats.length > 0 ? `
💡 INNOVASJONSSTATISTIKK:
${innovationStats.map((stat: any, idx: number) =>
`${idx + 1}. ${stat.label}
Periode: ${stat.period}
Table ID: ${stat.tableId}`
).join('\n\n')}
` : ''}
ℹ️ DATA KILDE:
Alle data hentet fra Statistisk sentralbyrå (SSB) via PxWeb API v2
API: https://data.ssb.no/api/pxwebapi/v2/
💡 BRUK:
- Bruk Table ID for å hente detaljert data fra SSB
- Kombiner med andre CompanyIQ-verktøy for dypere analyse
- Bruk 'market_landscape' for å se hvordan individuelle selskaper påvirker trenden
`;
return {
content: [{
type: "text" as const,
text: report
}]
};
}