import type { PageParam, PageResult } from '#/packages/effects/request/src';

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

export namespace HrmAttendanceExceptionApi {
  /** 考勤异常申请 */
  export interface AttendanceException {
    id?: number;
    userId?: number;
    userName?: string;
    deptName?: string;
    date?: string;
    exceptionType?: number;
    exceptionTypeName?: string;
    reason?: string;
    fileUrl?: string;
    status?: number;
    processInstanceId?: string;
    remark?: string;
    createTime?: string;
  }

  /** 审批流程 */
  export interface ApproveProcess {
    key: string;
    name: string;
  }
}

/** 查询考勤异常申请分页列表 */
export function getAttendanceExceptionPage(params: PageParam) {
  return requestClient.get<PageResult<HrmAttendanceExceptionApi.AttendanceException>>(
    '/hrm/attendance/exception/page',
    { params },
  );
}

/** 查询考勤异常申请详情 */
export function getAttendanceException(id: number) {
  return requestClient.get<HrmAttendanceExceptionApi.AttendanceException>(
    `/hrm/attendance/exception/get?id=${id}`,
  );
}

/** 新增考勤异常申请 */
export function createAttendanceException(
  data: HrmAttendanceExceptionApi.AttendanceException,
) {
  return requestClient.post('/hrm/attendance/exception/create', data);
}

/** 提交考勤异常申请 */
export function submitAttendanceException(id: number, processDefinitionKey: string) {
  return requestClient.post('/hrm/attendance/exception/submit', null, {
    params: { id, processDefinitionKey },
  });
}

/** 获取考勤异常审批流程列表 */
export function getAttendanceExceptionApproveProcessList() {
  return requestClient.get<HrmAttendanceExceptionApi.ApproveProcess[]>(
    '/hrm/attendance/exception/approve-process-list',
  );
}