import { apiRequestData } from "./http"; export type WecomApprovalArchiveScope = "self" | "team" | "all"; export type WecomApprovalArchiveType = "leave" | "missed_punch"; export type WecomApprovalArchiveStatus = "pending" | "approved" | "rejected" | "revoked" | "terminated" | "changed" | "unknown"; export type WecomApprovalArchiveFinding = "open" | "resolved" | "any"; export type WecomApprovalArchiveEmployee = { id: string; employeeNo: string | null; name: string; } | null; export type WecomApprovalArchiveItem = { id: string; spNoPrefix: string | null; templateIdPrefix: string | null; templateType: string; spName: string | null; normalizedStatus: string; applicant: WecomApprovalArchiveEmployee; appliedAt: string | null; submittedAt: string | null; completedAt: string | null; statusObservedAt: string | null; lastSource: string | null; lastCallbackAt: string | null; lastCompensationAt: string | null; readabilityStatus: string | null; singleTapApproveRisk: boolean; templateAdjustmentRequired: boolean; participantCount: number; actionCount: number; fieldCount: number; findingCount: number; openFindingCount: number; }; export type WecomApprovalArchiveDetail = WecomApprovalArchiveItem & { participants: Array<{ id: string; role: string; nodeIndex: number; employee: WecomApprovalArchiveEmployee; isCurrent: boolean; mappingStatus: string; }>; actions: Array<{ id: string; actionType: string; operator: WecomApprovalArchiveEmployee; actionTime: string | null; nodeIndex: number; source: string; }>; fields: Array<{ id: string; fieldKey: string; fieldIndex: number; fieldName: string | null; fieldType: string | null; sensitiveLevel: string; displayAllowed: boolean; }>; findings: Array<{ id: string; findingType: string; status: string; severity: string; source: string; detectedAt: string | null; resolvedAt: string | null; }>; }; export type WecomApprovalArchiveListQuery = { scope?: WecomApprovalArchiveScope; type?: "" | WecomApprovalArchiveType; status?: "" | WecomApprovalArchiveStatus; finding?: "" | WecomApprovalArchiveFinding; page?: number; pageSize?: number; }; export type WecomApprovalArchiveListResponse = { scope: WecomApprovalArchiveScope; requestedScope: WecomApprovalArchiveScope; canViewAll: boolean; page: number; pageSize: number; total: number; status: "OK" | "PARTIAL_ARCHIVE_NEEDS_DATA"; items: WecomApprovalArchiveItem[]; }; function buildQuery(query: WecomApprovalArchiveListQuery = {}) { const search = new URLSearchParams(); Object.entries(query).forEach(([key, value]) => { if (value === undefined || value === null || value === "") return; search.set(key, String(value)); }); const value = search.toString(); return value ? `?${value}` : ""; } export function fetchWecomApprovalArchive(query: WecomApprovalArchiveListQuery = {}) { return apiRequestData(`/api/wecom/approval-archive${buildQuery(query)}`); } export function fetchWecomApprovalArchiveDetail(id: string) { return apiRequestData<{ item: WecomApprovalArchiveDetail }>(`/api/wecom/approval-archive/${encodeURIComponent(id)}`); }