CREATE TABLE IF NOT EXISTS `activity_log` (
    `id`           INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `user_id`      INT UNSIGNED NULL,
    `action`       VARCHAR(100) NOT NULL COMMENT 'e.g. login, booking_created, review_posted',
    `subject_type` VARCHAR(80) NULL COMMENT 'e.g. booking, therapist_profile',
    `subject_id`   INT UNSIGNED NULL,
    `data`         JSON NULL,
    `ip`           VARCHAR(45) NULL,
    `user_agent`   VARCHAR(255) NULL,
    `created_at`   DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `activity_log_user_id_index` (`user_id`),
    KEY `activity_log_action_index` (`action`),
    KEY `activity_log_created_at_index` (`created_at`),
    CONSTRAINT `fk_al_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
