import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CrmMailingApplyForm, CrmMailingApplyQuery, CrmMailingApplyVO } from '@/api/oa/crm/crmMailingApply/types';

/**
 * 查询邮寄申请列表
 * @param query
 * @returns {*}
 */

export const listCrmMailingApply = (query?: CrmMailingApplyQuery): AxiosPromise<CrmMailingApplyVO[]> => {
  return request({
    url: '/oa/crm/crmMailingApply/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询邮寄申请详细
 * @param mailingApplyId
 */
export const getCrmMailingApply = (mailingApplyId: string | number): AxiosPromise<CrmMailingApplyVO> => {
  return request({
    url: '/oa/crm/crmMailingApply/' + mailingApplyId,
    method: 'get'
  });
};

/**
 * 新增邮寄申请
 * @param data
 */
export const addCrmMailingApply = (data: CrmMailingApplyForm) => {
  return request({
    url: '/oa/crm/crmMailingApply',
    method: 'post',
    data: data
  });
};

/**
 * 修改邮寄申请
 * @param data
 */
export const updateCrmMailingApply = (data: CrmMailingApplyForm) => {
  return request({
    url: '/oa/crm/crmMailingApply',
    method: 'put',
    data: data
  });
};

/**
 * 删除邮寄申请
 * @param mailingApplyId
 */
export const delCrmMailingApply = (mailingApplyId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/crm/crmMailingApply/' + mailingApplyId,
    method: 'delete'
  });
};

/**
 * 下拉框查询邮寄申请列表
 * @param query
 * @returns {*}
 */
export function getCrmMailingApplyList(query) {
  return request({
    url: '/oa/crm/crmMailingApply/getCrmMailingApplyList',
    method: 'get',
    params: query
  });
}

/**
 * 提交邮寄申请并发起审批流程
 * @param data
 */
export const mailingApplySubmitAndFlowStart = (data: CrmMailingApplyForm): AxiosPromise<CrmMailingApplyVO> => {
  return request({
    url: '/oa/crm/crmMailingApply/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 更新签收时间
 * @param data
 */
export const updateCrmMailingApplySignTime = (data: Pick<CrmMailingApplyForm, 'mailingApplyId' | 'signTime'>): AxiosPromise<CrmMailingApplyVO> => {
  return request({
    url: '/oa/crm/crmMailingApply/signTime',
    method: 'put',
    data: data
  });
};
