import { get, post } from '@/utils/request';
import type {
  WecomApprovalVo,
  WecomApprovalDetail,
  ApprovalStats,
  WecomTemplate,
  ApprovalListParams,
  SubmitApprovalBo,
} from './types';

export type {
  WecomApprovalVo,
  WecomApprovalDetail,
  ApprovalStats,
  WecomTemplate,
  ApprovalListParams,
  SubmitApprovalBo,
};

/** 分页查询审批列表 */
export function getApprovalList(params: ApprovalListParams) {
  return get<{ rows: WecomApprovalVo[]; total: number }>('/wecom/approval/list', params).json();
}

/** 获取审批详情（返回原始JSON字符串） */
export function getApprovalDetail(spNo: string) {
  return get<string>(`/wecom/approval/${spNo}`).json();
}

/** 发起审批申请 */
export function submitApproval(data: SubmitApprovalBo) {
  return post<string>('/wecom/approval/submit', data).json();
}

/** 触发全量同步（管理员） */
export function syncApprovals(daysBack = 30) {
  return post('/wecom/approval/sync/full', {}, { params: { daysBack } }).json();
}

/** 同步当前用户审批数据（近1天） */
export function syncCurrentUserApprovals() {
  return post<string>('/wecom/approval/sync/current', {}).json();
}

/** 获取模板列表 */
export function getTemplateList() {
  return get<{ templateId: string; templateName: string; syncTime: string }[]>('/wecom/approval/templates').json();
}

/** 获取统计数据（全局） */
export function getApprovalStats() {
  return get<ApprovalStats>('/wecom/approval/stats').json();
}

/** 获取当前用户统计数据 */
export function getUserApprovalStats() {
  return get<ApprovalStats>('/wecom/approval/stats/user').json();
}

/** 导出审批数据 */
export function exportApprovals(status?: string) {
  return post('/wecom/approval/export', { status }).json();
}
