-- Migration: Add flexible rounding settings to billingInfo
-- This supports different currency requirements:
--   - EUR: roundingPrecision=2 (cents) or roundingPrecision=1 (10 cents)
--   - MYR: roundingPrecision=0 (whole ringgit)
--   - KRW: roundingPrecision=-1 (tens of won) or roundingPrecision=-2 (hundreds)
--
-- roundingMode options:
--   - 'down': Always round down (floor) - customer-friendly, legally required in some jurisdictions
--   - 'nearest': Round to nearest (standard mathematical rounding)
--   - 'up': Always round up (ceil) - rarely used but available
--
-- roundingDisplay options:
--   - 'line': Show rounding as a separate line item on the receipt
--   - 'service-charge': Fold rounding into service charge (no rounding line shown)

ALTER TABLE `billingInfo`
  ADD COLUMN `roundingPrecision` TINYINT(2) NOT NULL DEFAULT 0 
    COMMENT 'Decimal places to round final total. 2=cents, 1=10cents, 0=whole, -1=tens, -2=hundreds'
    AFTER `taxName`,
  ADD COLUMN `roundingMode` ENUM('down', 'nearest', 'up') NOT NULL DEFAULT 'nearest'
    COMMENT 'How to round: down=floor(customer-friendly), nearest=standard, up=ceil'
    AFTER `roundingPrecision`,
  ADD COLUMN `roundingDisplay` ENUM('line', 'service-charge') NOT NULL DEFAULT 'line'
    COMMENT 'line=show on receipt, service-charge=fold into service charge'
    AFTER `roundingMode`;

-- Also expand the rounding column in receipts to handle larger adjustments
-- (e.g., rounding to nearest 100 KRW on a 50,000 KRW bill could be ±50)
ALTER TABLE `receipts`
  MODIFY COLUMN `rounding` DECIMAL(8,2) NOT NULL DEFAULT 0.00
    COMMENT 'Rounding adjustment applied to reach final total';

-- Update archive table to match
ALTER TABLE `_archive_receipts`
  MODIFY COLUMN `rounding` DECIMAL(8,2) NOT NULL DEFAULT 0.00
    COMMENT 'Rounding adjustment applied to reach final total';
