import { request } from '@/http/axios'
import { SubmitApprovalRequestData, SubmitApprovalResponseData, SearchApiReturnApprovalQuery, ApiResponsePageData, ReturnApprovalEntity, HandleApprovalRequestData, SearchReturnApprovalAssetQuery, ReturnApprovalAssetDTO, HandleApprovalAssetRequestData, ApprovalGoodsCellEntity, ReturnApprovalDetailDTO } from './type'
import { OpenCabinetApiData, ShopOrderGoodsEntity } from '../shop/type'

export const getApprovalListApi = (params: SearchApiReturnApprovalQuery) => {
  return request<ApiResponsePageData<ReturnApprovalEntity>>({
    url: 'approval/list',
    method: 'get',
    params
  })
}

export const getApprovalAssetListApi = (params: SearchReturnApprovalAssetQuery) => {
  return request<ApiResponsePageData<ReturnApprovalAssetDTO>>({
    url: 'approval/list/asset',
    method: 'get',
    params
  })
}

export const checkApprovalCodeApi = (params: {
  corpid: string,
  approvalType: number,
  code: string
}) => {
  return request<ApiResponseMsgData<string>>(
    {
      url: 'approval/checkCode',
      method: 'post',
      params
    }
  )
}


export const submitApprovalApi = (data: SubmitApprovalRequestData) => {
  return request<SubmitApprovalResponseData>({
    url: 'approval/submit',
    method: 'post',
    data
  })
}

export const handleApprovalApi = (data: HandleApprovalRequestData) => {
  return request<ApiResponseMsgData<string>>({
    url: 'approval/handle',
    method: 'post',
    data
  })
}


export const handleApprovalAssetApi = (data: HandleApprovalRequestData) => {
  return request<ApiResponseMsgData<string>>({
    url: 'approval/handle/asset',
    method: 'post',
    data
  })
}

export const allocateApprovalGoods = (data: HandleApprovalAssetRequestData) => {
  return request<ApiResponseMsgData<string>>({
    url: 'approval/handle/allocateApprovalGoods',
    method: 'post',
    data
  })
}

export const getApprovalOrderGoodsApi = (approvalId: number) => {
  return request<ApiResponseMsgData<ShopOrderGoodsEntity[]>>({
    url: 'approval/getApprovalOrderGoods',
    method: 'get',
    params: { approvalId }
  })
}

export const getApprovalGoodsCellApi = (approvalId: number) => {
  return request<ApiResponseMsgData<ApprovalGoodsCellEntity[]>>(
    {
      url: 'approval/getApprovalGoodsCell',
      method: 'get',
      params: { approvalId }
    }
  )
}

export const getApprovalDetailAssetApi = (approvalId: number) => {
  return request<ApiResponseMsgData<ReturnApprovalDetailDTO>>(
    {
      url: 'approval/detail/asset',
      method: 'get',
      params: { approval_id: approvalId }
    }
  )
}

/** 打开储物柜接口 */
export function openCabinetApi(approvalGoodsCellId: number, data: OpenCabinetApiData) {
  return request<ApiResponseData<void>>({
    url: `approval/openCabinet/${approvalGoodsCellId}`,
    method: "post",
    data
  })
}