import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  BaseInfoVO,
  BaseInfoQuery,
  BaseInfoForm,
  ProdSalesApplicationBo,
  ProdChannelBo,
  ProdInstitutionBo,
  SalesStatusApplicationVO,
  QueryApplication,
  ProdSalesStatusApplicationBo,
  GetProductSalesInfoBo,
  GetProductSalesLogInfoBo
} from '@/api/product/apply/types';

export const getProductSalesLogInfo = (data: GetProductSalesLogInfoBo) => {
  return request({
    url: '/product/apply/getProductSalesLogInfo',
    method: 'post',
    data: data
  });
};

/**
 * 产品销售状态查询的搜索
 */

export const getProductSalesInfo = (data: GetProductSalesInfoBo) => {
  return request({
    url: '/product/apply/getProductSalesInfo',
    method: 'post',
    data: data
  });
};
/**
 * 查看详情 ---> 撤回申请
 */
export const cancelApplication = (data: ProdSalesStatusApplicationBo) => {
  return request({
    url: '/product/apply/cancelApplication',
    method: 'post',
    data: data
  });
};

/**
 * 查看详情--->保存
 * @param data
 */
export const updateApplicationInfo = (data, institutionList, channelList) => {
  const fromData = {
    ...data,
    channels: channelList,
    institutions: institutionList
  };
  return request({
    url: '/product/apply/updateApplicationInfo',
    method: 'post',
    data: fromData
  });
};

/**
 * 删除可销售渠道
 */
export const deleteChannelApplication = (applicationIds: Array<string | number> | string | number) => {
  return request({
    url: '/product/apply/deleteChannelApplication/' + applicationIds,
    method: 'post'
  });
};
/**
 * 删除可销售机构
 */
export const deleteInstitutionApplication = (applicationIds: Array<string | number> | string | number) => {
  return request({
    url: '/product/apply/deleteInstitutionApplication/' + applicationIds,
    method: 'post'
  });
};
/**
 * 产品销售状态申请记录 查看详情
 * @param code
 */
export const infoByApplicationId = (code: string | number) => {
  const data = {
    applicationId: code
  };
  return request({
    url: '/product/apply/infoByApplicationId',
    method: 'post',
    data: data
  });
};
/**
 * 修改申请状态，审核中--->申请中
 * @param code
 */
export const updateApplicationStatus = (code: string | number) => {
  const data= {
    applicationId: code
  };
  return request({
    url: '/product/apply/updateApplicationStatus',
    method: 'post',
    data: data
  });
};
/**
 * 产品销售状态申请记录查询
 * @param data
 */
export const queryByApplicant = (data) => {
  return request({
    url: '/product/apply/queryByApplicant',
    method: 'get',
    params: data
  });
};
/**
 * 产品销售权限配置申请保存
 */

export const productApply = (data, institutionList, channelList) => {
  const fromData = {
    ...data,
    channels: channelList,
    institutions: institutionList
  };
  return request({
    url: '/product/apply/productApply',
    method: 'post',
    data: fromData
  });
};
/**
 * 根据产品编号查询产品信息，销售渠道，销售机构
 * @param code
 */
export const searchText = (code: string): AxiosPromise<BaseInfoVO> => {
  return request({
    url: '/product/apply/searchText',
    method: 'post',
    data: {
      productCode: code
    }
  });
};
/**
 * 产品编号的模糊查询
 * @param code
 */
export const codeList = (code?: string): AxiosPromise<Array<string>> => {
  return request({
    url: '/product/apply/codeList?code=' + code,
    method: 'get'
  });
};

/**
 * 查询所有产品列表
 */
export const qeuryAllProduct = () => {
  return request({
    url: '/product/apply/qeuryAllProduct',
    method: 'post'
  });
};

/**
 * 按查询条件查询产品
 */
export const listProduct = (query) => {
  return request({
    url: '/product/apply/listProduct',
    method: 'get',
    params: query
  });
};
