-- ============================================
-- 公告系统表
-- ============================================

-- 公告表
CREATE TABLE IF NOT EXISTS announcements (
  id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(255) NOT NULL COMMENT '公告标题',
  content TEXT NOT NULL COMMENT '公告内容（支持富文本/Markdown）',
  category VARCHAR(32) NOT NULL DEFAULT 'notice' COMMENT '分类: notice(通知), tutorial(教程), rule(规则), faq(常见问题)',
  priority INT NOT NULL DEFAULT 0 COMMENT '优先级，数值越大越靠前',
  is_pinned TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否置顶',
  is_important TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否重要（重要的会有特殊标记）',
  view_count INT NOT NULL DEFAULT 0 COMMENT '查看次数',
  status VARCHAR(32) NOT NULL DEFAULT 'draft' COMMENT '状态: draft(草稿), published(已发布), archived(已归档)',
  published_at DATETIME NULL COMMENT '发布时间',
  created_by BIGINT UNSIGNED NULL COMMENT '创建者ID（管理员）',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_announcements_status (status, is_pinned, priority, published_at),
  KEY idx_announcements_category (category, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公告表';
