/**
 * Migration 023: Tax rates configuration.
 * Stores configurable tax rates per category.
 */
exports.up = async (pgm) => {
  pgm.sql(`
    CREATE TABLE IF NOT EXISTS tax_rates (
      id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
      name VARCHAR(40) NOT NULL,
      rate_percent NUMERIC(5,2) NOT NULL,
      country VARCHAR(2) NOT NULL DEFAULT 'ES',
      applies_to VARCHAR(20) NOT NULL DEFAULT 'general',
      active BOOLEAN NOT NULL DEFAULT true,
      created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
    );

    INSERT INTO tax_rates (name, rate_percent, country, applies_to, active) VALUES
      ('IVA General', 21.0, 'ES', 'general', true),
      ('IVA Reducido', 10.0, 'ES', 'reduced', true),
      ('IVA Superreducido', 4.0, 'ES', 'super-reduced', true)
    ON CONFLICT DO NOTHING;
  `);
};

exports.down = async (pgm) => {
  pgm.sql('DROP TABLE IF EXISTS tax_rates');
};
