/**
 * vat_rates — system-i18n.
 *
 * Stores the historical VAT rate for each country. The composite PK
 * (country_code, effective_from) ensures exactly one rate per country per
 * date-boundary. Consumers call getVatRate(db, countryCode, date) which does
 * a lte(effective_from, date) + DESC + LIMIT 1 to find the rate in effect on
 * any given date.
 *
 * `rate` is NUMERIC(5,4) — never a floating-point column. 0.0800 = 8.00%.
 */
import { pgTable, text, date, numeric, primaryKey } from 'drizzle-orm/pg-core'

export const vatRates = pgTable(
  'vat_rates',
  {
    countryCode: text('country_code').notNull(),
    effectiveFrom: date('effective_from').notNull(),
    rate: numeric('rate', { precision: 5, scale: 4 }).notNull(),
  },
  (t) => ({
    pk: primaryKey({ columns: [t.countryCode, t.effectiveFrom] }),
  }),
)

export type VatRate = typeof vatRates.$inferSelect
export type NewVatRate = typeof vatRates.$inferInsert
