/**
 * VAT rates seed data — system-i18n.
 *
 * All 18 Israel VAT rate history rows. Rates are stored as NUMERIC(5,4)
 * strings matching the DB column precision (e.g. "0.0800" = 8.00%).
 *
 * Use `onConflictDoNothing()` on the composite PK so re-seeding is idempotent.
 *
 * Sources: Israeli Tax Authority historical records.
 * References: https://www.misim.gov.il/
 */
import type { Db } from '../client'
import { vatRates } from '../schema/vat-rates'

export const IL_VAT_RATES = [
  ['IL', '1976-07-01', '0.0800'],
  ['IL', '1977-11-01', '0.1200'],
  ['IL', '1982-08-01', '0.1500'],
  ['IL', '1985-06-01', '0.1700'],
  ['IL', '1985-10-01', '0.1500'],
  ['IL', '1990-03-01', '0.1600'],
  ['IL', '1991-01-01', '0.1800'],
  ['IL', '1993-01-01', '0.1700'],
  ['IL', '2002-06-15', '0.1800'],
  ['IL', '2004-03-01', '0.1700'],
  ['IL', '2005-09-01', '0.1650'],
  ['IL', '2006-07-01', '0.1550'],
  ['IL', '2009-07-01', '0.1650'],
  ['IL', '2010-01-01', '0.1600'],
  ['IL', '2012-09-01', '0.1700'],
  ['IL', '2013-06-02', '0.1800'],
  ['IL', '2015-10-01', '0.1700'],
  ['IL', '2025-01-01', '0.1800'],
] as const

/**
 * Seed Israel VAT rate history into the DB.
 * Idempotent: uses onConflictDoNothing on the composite PK.
 */
export async function seedVatRates(db: Db): Promise<void> {
  const rows = IL_VAT_RATES.map(([countryCode, effectiveFrom, rate]) => ({
    countryCode,
    effectiveFrom,
    rate,
  }))

  await db.insert(vatRates).values(rows).onConflictDoNothing()
  console.log(`Seeded ${rows.length} VAT rate rows (IL history).`)
}
