-- Immutable audit log. Never UPDATE or DELETE rows from this table.

CREATE TABLE IF NOT EXISTS audit_logs (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  event_type VARCHAR(120) NOT NULL,
  actor_type ENUM('merchant_user','payer','system','admin') NOT NULL,
  actor_id BIGINT UNSIGNED NULL,
  actor_email VARCHAR(320) NULL,
  target_type VARCHAR(60) NULL,
  target_id BIGINT UNSIGNED NULL,
  context JSON NULL,
  ip_address VARCHAR(45) NULL,
  user_agent VARCHAR(512) NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_al_event (event_type),
  INDEX idx_al_actor (actor_type, actor_id),
  INDEX idx_al_target (target_type, target_id),
  INDEX idx_al_created (created_at)
)
