import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CrmGiftApplyForm, CrmGiftApplyQuery, CrmGiftApplyVO } from '@/api/oa/crm/crmGiftApply/types';

/**
 * 查询礼品申请列表
 * @param query
 * @returns {*}
 */

export const listCrmGiftApply = (query?: CrmGiftApplyQuery): AxiosPromise<CrmGiftApplyVO[]> => {
  return request({
    url: '/oa/crm/crmGiftApply/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询礼品申请详细
 * @param giftApplyId
 */
export const getCrmGiftApply = (giftApplyId: string | number): AxiosPromise<CrmGiftApplyVO> => {
  return request({
    url: '/oa/crm/crmGiftApply/' + giftApplyId,
    method: 'get'
  });
};

/**
 * 新增礼品申请
 * @param data
 */
export const addCrmGiftApply = (data: CrmGiftApplyForm) => {
  return request({
    url: '/oa/crm/crmGiftApply',
    method: 'post',
    data: data
  });
};

/**
 * 修改礼品申请
 * @param data
 */
export const updateCrmGiftApply = (data: CrmGiftApplyForm) => {
  return request({
    url: '/oa/crm/crmGiftApply',
    method: 'put',
    data: data
  });
};

/**
 * 删除礼品申请
 * @param giftApplyId
 */
export const delCrmGiftApply = (giftApplyId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/crm/crmGiftApply/' + giftApplyId,
    method: 'delete'
  });
};

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

/**
 * 提交礼品申请并发起审批流程
 * @param data
 */
export const giftApplySubmitAndFlowStart = (data: CrmGiftApplyForm): AxiosPromise<CrmGiftApplyVO> => {
  return request({
    url: '/oa/crm/crmGiftApply/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 批量发放礼品
 * @param data
 */
export const batchIssueGifts = (data: CrmGiftApplyForm) => {
  return request({
    url: '/oa/crm/crmGiftApply/batchIssue',
    method: 'post',
    data: data
  });
};
