import { NextResponse } from 'next/server'
import pool from '@/lib/db'

export async function POST() {
  const results: string[] = []

  try {
    // Fix pitch_financials with WD numbers
    const fixes: [number, number, number, number, number][] = [
      [2026, 71447, 6, 3, 205788],
      [2027, 476354, 23, 3, 598188],
      [2028, 951641, 56, 5, 1176564],
      [2029, 1827761, 113, 7, 2312328],
      [2030, 3314258, 195, 9, 4080492],
    ]
    for (const [y, rev, cust, emp, arr] of fixes) {
      await pool.query(`UPDATE pitch_financials SET revenue_eur=$1, customers_count=$2, employees_count=$3, arr_eur=$4 WHERE year=$5`, [rev, cust, emp, arr, y])
    }
    results.push('pitch_financials updated')

    // Fix pitch_funding
    await pool.query(`UPDATE pitch_funding SET round_name='Pre-Seed (Wandeldarlehen)', amount_eur=200000, instrument='Wandeldarlehen', use_of_funds=$1`,
      [JSON.stringify([
        {category:'personal',label_de:'Personal & Gehälter',label_en:'Personnel & Salaries',percentage:45},
        {category:'cloud',label_de:'Cloud-Infrastruktur',label_en:'Cloud Infrastructure',percentage:15},
        {category:'sales',label_de:'Vertrieb & Marketing',label_en:'Sales & Marketing',percentage:15},
        {category:'ausstattung',label_de:'Arbeitsplatzausstattung',label_en:'Workplace Equipment',percentage:10},
        {category:'legal',label_de:'Zertifizierung & Recht',label_en:'Certification & Legal',percentage:10},
        {category:'reserve',label_de:'Reserve',label_en:'Reserve',percentage:5},
      ])])
    results.push('pitch_funding updated')
  } catch (err) {
    results.push(`ERROR: ${err instanceof Error ? err.message : String(err)}`)
  }

  return NextResponse.json({ ok: true, results })
}
