-- P2-5: 消息举报 + 用户屏蔽
-- 1. message_reports: 举报记录（reporterId → messageId / reportedUserId）
-- 2. user_blocks: 用户屏蔽关系（blockerId → blockedId，唯一约束防重复）

CREATE TABLE `message_reports` (
  `id` varchar(128) NOT NULL,
  `reporter_id` varchar(128) NOT NULL,
  `message_id` varchar(128) NOT NULL,
  `reported_user_id` varchar(128) NOT NULL,
  `reason` varchar(50) NOT NULL,
  `description` text,
  `status` varchar(20) NOT NULL DEFAULT 'pending',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX `message_reports_reporter_idx` (`reporter_id`),
  INDEX `message_reports_message_idx` (`message_id`),
  INDEX `message_reports_reported_user_idx` (`reported_user_id`),
  INDEX `message_reports_status_idx` (`status`),
  CONSTRAINT `message_reports_reporter_id_users_id_fk` FOREIGN KEY (`reporter_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
  CONSTRAINT `message_reports_message_id_messages_id_fk` FOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON DELETE CASCADE,
  CONSTRAINT `message_reports_reported_user_id_users_id_fk` FOREIGN KEY (`reported_user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);

CREATE TABLE `user_blocks` (
  `id` varchar(128) NOT NULL,
  `blocker_id` varchar(128) NOT NULL,
  `blocked_id` varchar(128) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `user_blocks_blocker_blocked_uniq` (`blocker_id`, `blocked_id`),
  INDEX `user_blocks_blocker_idx` (`blocker_id`),
  CONSTRAINT `user_blocks_blocker_id_users_id_fk` FOREIGN KEY (`blocker_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
  CONSTRAINT `user_blocks_blocked_id_users_id_fk` FOREIGN KEY (`blocked_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);
