-- Premium breakdown the Access capture form had and this schema did not:
-- RECARGO, IVA and PRIMA TOTAL on the policy header, the same six figures per
-- payment on the installments, and the FORMA PAGO that decides whether a
-- surcharge applies at all.
--
-- IVA and TOTAL were never columns in Access — they were unbound calculated
-- controls on the form — so there is nothing to backfill for them here and
-- every migrated row stays null until somebody edits the policy. RECARGO and
-- the per-installment figures DO exist in the legacy data; they are currently
-- stranded inside `policies.coveragesJson` (the migration swept every column
-- it did not model into that blob) and are recovered by
-- `migration/backfill_policy_premium_breakdown.py`, not by this migration.

ALTER TABLE `policy_types`
  ADD COLUMN `taxRate` DECIMAL(6, 4) NULL;

ALTER TABLE `policies`
  ADD COLUMN `surcharge` DECIMAL(12, 2) NULL,
  ADD COLUMN `tax` DECIMAL(12, 2) NULL,
  ADD COLUMN `taxRate` DECIMAL(6, 4) NULL,
  ADD COLUMN `paymentFrequency` ENUM('ANNUAL', 'SEMIANNUAL', 'QUARTERLY', 'MONTHLY', 'SINGLE') NULL;

ALTER TABLE `policy_payment_installments`
  ADD COLUMN `netPremium` DECIMAL(12, 2) NULL,
  ADD COLUMN `surcharge` DECIMAL(12, 2) NULL,
  ADD COLUMN `policyFee` DECIMAL(12, 2) NULL,
  ADD COLUMN `tax` DECIMAL(12, 2) NULL,
  ADD COLUMN `taxRate` DECIMAL(6, 4) NULL,
  ADD COLUMN `total` DECIMAL(12, 2) NULL,
  ADD COLUMN `commission` DECIMAL(12, 2) NULL;

-- Seed the rate the books actually use. The legacy IMPUESTOS and
-- IMPUESTOS_AUTOS tables each held exactly one row, both 0.0800, covering the
-- home and auto lines respectively; applying it to every existing type
-- reproduces current behaviour rather than changing it. Types created later
-- start null and fall back to the API default.
UPDATE `policy_types` SET `taxRate` = 0.0800 WHERE `taxRate` IS NULL;
