-- Migration: Add rounding interval to prepaid cards

ALTER TABLE tticket_prepaid_cards
ADD COLUMN IF NOT EXISTS rounding_minutes INTEGER DEFAULT 0;

DO $$
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM pg_constraint WHERE conname = 'chk_tticket_prepaid_rounding_minutes'
    ) THEN
        ALTER TABLE tticket_prepaid_cards
        ADD CONSTRAINT chk_tticket_prepaid_rounding_minutes
        CHECK (rounding_minutes IN (0, 15, 30, 60));
    END IF;
END $$;

COMMENT ON COLUMN tticket_prepaid_cards.rounding_minutes IS 'Round up prepaid usage to this interval in minutes (0 = no rounding)';
