// ============================================================
// 公告模块 — 类型定义 + API 请求
// GET /api/v1/announcements
// ============================================================

import { get } from '@/shared/services/http';

// ============================================================
// AnnouncementUrlObj — 公告模块路由常量
// ============================================================

const AnnouncementUrlObj = {
   list: '/api/v1/announcements',
} as const;

// ---------- 类型 ----------

// ============================================================
// 公告类型常量
// ============================================================

export const AnnouncementTypeEnum = {
    System: "system",
    Feature: "feature",
    Activity: "activity",
    Maintenance: "maintenance",
} as const;

export type AnnouncementTypeValue = typeof AnnouncementTypeEnum[keyof typeof AnnouncementTypeEnum];

export const AnnouncementTypeLabelMap: Record<AnnouncementTypeValue, string> = {
    [AnnouncementTypeEnum.System]: "系统公告",
    [AnnouncementTypeEnum.Feature]: "功能更新",
    [AnnouncementTypeEnum.Activity]: "活动通知",
    [AnnouncementTypeEnum.Maintenance]: "维护公告",
};

export const AnnouncementTypeColorMap: Record<AnnouncementTypeValue, string> = {
    [AnnouncementTypeEnum.System]: "blue",
    [AnnouncementTypeEnum.Feature]: "purple",
    [AnnouncementTypeEnum.Activity]: "orange",
    [AnnouncementTypeEnum.Maintenance]: "red",
};

/** 公告类型（向后兼容：包含已知枚举 + string 宽类型） */
export type AnnouncementType = AnnouncementTypeValue | string;

/** 单条公告 */
export interface Announcement {
   id: number;
   title: string;
   content: string;
   type: AnnouncementType;
   is_active: boolean;
   pinned: boolean;
   expires_at: string;
   created_by: string;
   created_at: string;
   updated_at: string;
}

/** 公告列表响应 */
export type AnnouncementListResponse = Announcement[];

// ---------- API ----------

/**
 * 获取公告列表
 * GET /api/v1/announcements
 */
export function fetchAnnouncements(): Promise<AnnouncementListResponse> {
   return get<AnnouncementListResponse>(AnnouncementUrlObj.list);
}
