import { requestClient } from '#/api/request';

const prefix = 'notice/';

/**
 * 查询通知列表（xk-api）
 */
export async function getNoticeListApi(data: any) {
  return requestClient.get<any>(`${prefix}list`, { params: data });
}

/**
 * 未读总数（铃铛角标）
 */
export async function getNoticeUnreadCountApi() {
  return requestClient.get<any>(`${prefix}unread-count`);
}

/**
 * 获取接受消息用户下拉列表
 */
export async function getUserOptionApi() {
  return requestClient.get<any>(`${prefix}user-option`);
}

/**
 * 查询通知详情（会标记已读）
 */
export async function getNoticeDetailApi(id: number) {
  const result = requestClient.get<any>(`${prefix}detail`, { params: { id } });
  localStorage.setItem(`readStatus`, Math.random().toString(36).slice(2));
  return result;
}

/**
 * 设置已读某条消息
 */
export async function readApi(id: number) {
  const result = requestClient.post<any>(`${prefix}read`, { id });
  localStorage.setItem(`readStatus`, Math.random().toString(36).slice(2));
  return result;
}

/**
 * 设置已读全部消息
 */
export async function readAllApi() {
  const result = requestClient.post<any>(`${prefix}read-all`);
  localStorage.setItem(`readStatus`, Math.random().toString(36).slice(2));
  return result;
}

/**
 * 群发消息
 */
export async function sendNoticeApi(data: any) {
  return requestClient.post<any>(`${prefix}send`, data);
}
