-- #migration 2026_07_28_139
-- Factures générées à la confirmation d'un paiement (candidature ou parcours).
-- Numéro séquentiel formaté après insertion (invoice_number = U{année}-{id sur 6 chiffres}).
CREATE TABLE IF NOT EXISTS invoices (
  id                INT AUTO_INCREMENT PRIMARY KEY,
  invoice_number    VARCHAR(20)  NULL UNIQUE,
  user_id           VARCHAR(40)  NULL,
  email             VARCHAR(190) NOT NULL,
  label             VARCHAR(255) NOT NULL,
  amount_cents      INT UNSIGNED NOT NULL,
  product_type      VARCHAR(40)  NOT NULL,
  product_id        VARCHAR(40)  NULL,
  payment_intent_id VARCHAR(80)  NULL,
  created_at        TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_user (user_id),
  INDEX idx_pi (payment_intent_id)
);
