-- Vendor Portal Tokens: Allow suppliers to respond to RFQs via a public link
CREATE TABLE IF NOT EXISTS vendor_portal_tokens (
  id INT AUTO_INCREMENT PRIMARY KEY,
  company_id INT NOT NULL,
  rfq_id INT NOT NULL,
  supplier_id INT NOT NULL,
  token VARCHAR(64) NOT NULL UNIQUE,
  is_active TINYINT(1) NOT NULL DEFAULT 1,
  expires_at DATETIME DEFAULT NULL,
  access_count INT NOT NULL DEFAULT 0,
  max_access INT NOT NULL DEFAULT 50,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uq_rfq_supplier (rfq_id, supplier_id),
  KEY idx_token (token),
  KEY idx_company (company_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Auto-generate tokens when RFQ is sent (trigger via API)
