import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SmsServiceConfigVO, SmsServiceConfigForm, SmsServiceConfigQuery } from '@/api/msg/smsServiceConfig/types';

/**
 * 查询短信服务商配置列表
 * @param query
 * @returns {*}
 */

export const listSmsServiceConfig = (query?: SmsServiceConfigQuery): AxiosPromise<SmsServiceConfigVO[]> => {
  return request({
    url: '/msg/smsServiceConfig/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询所有短信服务商配置列表
 * @param query
 * @returns {*}
 */

export const getAllSmsManualChannelConfig = () => {
  return request({
    url: '/msg/smsServiceConfig/getAllSmsManualChannelConfig',
    method: 'post'
  });
};

/**
 * 查询短信服务商配置详细
 * @param providerId
 */
export const getSmsServiceConfig = (providerId: string | number): AxiosPromise<SmsServiceConfigVO> => {
  const data = {
    providerId
  };
  return request({
    url: '/msg/smsServiceConfig/getSmsServiceConfigDetail',
    method: 'post',
    data: data
  });
};


/**
 * 修改短信服务商配置
 * @param data
 */
export const updateSmsServiceConfig = (data: SmsServiceConfigForm) => {
  return request({
    url: '/msg/smsServiceConfig',
    method: 'put',
    data: data
  });
};

/**
 * 删除短信服务商配置
 * @param providerId
 */
export const delSmsServiceConfig = (providerId: string | number | Array<string | number>) => {
  return request({
    url: '/msg/smsServiceConfig/' + providerId,
    method: 'delete'
  });
};


/**
 * 申请服务信息修改
 * @param data
 */
export const addSmsServiceConfig = (from, list) => {
  const data = {
    configDefinitionBo: from,
    priceDefinitionBoList: list
  };
  return request({
    url: '/msg/smsServiceConfig/editSmsServiceConfigDetail',
    method: 'post',
    data: data
  });
};

/**
 * 查询申请列表
 */
export const listSmsServiceApplay = (query) => {
  return request({
    url: '/msg/smsServiceConfig/applayList',
    method: 'get',
    params: query
  });
};

/**
 * 查询申请详情
 */
export const getApplaySmsServiceConfig = (definitionId) => {
  const data = {
    definitionId
  };
  return request({
    url: '/msg/smsServiceConfig/getApplaySmsServiceConfig',
    method: 'post',
    data: data
  });
};

/**
 * 审批结果
 */
export const auditSmsServiceConfig = (definitionId, isPass) => {
  const data = {
    definitionId,
    isPass
  };
  return request({
    url: '/msg/smsServiceConfig/auditSmsServiceConfig',
    method: 'post',
    data: data
  });
};

/**
 * 当服务商由启用改为停用时，搜索所有使用该通道的短信模板
 * @param from
 */
export const getTemplateByChannel = (query) => {
  return request({
    url: '/msg/smsServiceConfig/getTemplateByChannel',
    method: 'get',
    params: query
  });
};

export const getTemplateConfigCasual = (query) => {
  return request({
    url: '/msg/smsServiceConfig/getTemplateConfigCasual',
    method: 'get',
    params: query
  });
};

/**
 * 更新服务商申请表状态，保存停用时短信模板数据
 * @param data
 */
export const updateSmsSendChannel = (data) => {
  return request({
    url: '/msg/smsServiceConfig/updateSmsSendChannel',
    method: 'post',
    data: data
  });
};
