import type { PageParam, PageResult } from '@vben/request';

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

export namespace VehicleApplicationApi {
  /** 用车申请状态 */
  export const Status = {
    DRAFT: 0,
    APPROVING: 15,
    APPROVED: 20,
    REJECTED: 35,
  } as const;

  /** 用车申请 */
  export interface Application {
    id?: number;
    no?: string;
    applicantId?: number;
    applicantName?: string;
    useStartTime?: string;
    useEndTime?: string;
    departure?: string;
    destination?: string;
    passengers?: number;
    reason?: string;
    vehicleNo?: string;
    status?: number;
    statusName?: string;
    processInstanceId?: string;
    approveTime?: string;
    remark?: string;
    createTime?: string;
  }

  /** 审批流程定义 */
  export interface ProcessDefinition {
    id: string;
    key: string;
    name: string;
  }
}

/** 查询用车申请分页 */
export function getVehicleApplicationPage(params: PageParam) {
  return requestClient.get<PageResult<VehicleApplicationApi.Application>>(
    '/vehicle/application/page',
    { params },
  );
}

/** 查询用车申请详情 */
export function getVehicleApplication(id: number) {
  return requestClient.get<VehicleApplicationApi.Application>(
    `/vehicle/application/get?id=${id}`,
  );
}

/** 新增用车申请 */
export function createVehicleApplication(
  data: VehicleApplicationApi.Application,
) {
  return requestClient.post('/vehicle/application/create', data);
}

/** 修改用车申请 */
export function updateVehicleApplication(
  data: VehicleApplicationApi.Application,
) {
  return requestClient.put('/vehicle/application/update', data);
}

/** 删除用车申请 */
export function deleteVehicleApplication(id: number) {
  return requestClient.delete('/vehicle/application/delete', {
    params: { id },
  });
}

/** 提交用车审批 */
export function submitVehicleApplication(
  id: number,
  processDefinitionKey: string,
) {
  return requestClient.post('/vehicle/application/submit', null, {
    params: { id, processDefinitionKey },
  });
}

/** 获取用车审批流程列表 */
export function getVehicleApproveProcessList() {
  return requestClient.get<VehicleApplicationApi.ProcessDefinition[]>(
    '/vehicle/application/approve-process-list',
  );
}
