CREATE TABLE IF NOT EXISTS nn_email_log (
  id            INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  store_id      INT UNSIGNED DEFAULT NULL,
  order_id      INT UNSIGNED DEFAULT NULL,
  sent_to       VARCHAR(255) NOT NULL,
  subject       VARCHAR(255) NOT NULL,
  template      VARCHAR(50)  DEFAULT NULL,
  status        ENUM('queued','sent','failed','bounced') NOT NULL DEFAULT 'queued',
  error_message TEXT DEFAULT NULL,
  smtp_host     VARCHAR(100) DEFAULT NULL,
  relay_method  ENUM('wireguard','gmail','direct','unknown') NOT NULL DEFAULT 'unknown',
  created_at    DATETIME DEFAULT CURRENT_TIMESTAMP,
  KEY idx_order  (order_id),
  KEY idx_status (status, created_at),
  KEY idx_store  (store_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
