-- Production payer payment method vault.
-- processor_token is the Stripe PaymentMethod ID — raw card data never stored here.

CREATE TABLE IF NOT EXISTS payer_payment_methods (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  payer_id BIGINT UNSIGNED NOT NULL,
  label VARCHAR(120) NOT NULL,
  network VARCHAR(60) NOT NULL,
  masked_account VARCHAR(40) NOT NULL,
  processor VARCHAR(40) NOT NULL DEFAULT 'stripe',
  processor_token VARCHAR(255) NOT NULL,
  billing_type ENUM('debit','credit','prepaid','other') NOT NULL DEFAULT 'other',
  expires_month TINYINT UNSIGNED NULL,
  expires_year SMALLINT UNSIGNED NULL,
  is_default BOOLEAN NOT NULL DEFAULT FALSE,
  is_active BOOLEAN NOT NULL DEFAULT TRUE,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (payer_id) REFERENCES payer_accounts(id) ON DELETE CASCADE,
  INDEX idx_ppm_payer (payer_id),
  UNIQUE KEY uq_ppm_token (processor, processor_token)
)
