import { defHttp } from '@jdlinker/func';

export default {
  // 列表
  list: (data: any) => {
    const params = { ...data };
    return defHttp.post({ url: `/notifier/template/list`, data, params }, { isTransformResponse: false });
  },
  // 详情
  detail: (id: string): any => defHttp.get({ url: `/notifier/template/${id}` }, { isTransformResponse: false }),
  // 新增
  save: (data: any) => defHttp.post({ url: `/notifier/template`, data }, { isTransformResponse: false }),
  // 修改
  update: (data: any) => defHttp.put({ url: `/notifier/template`, data }, { isTransformResponse: false }),
  del: (id: any) => defHttp.delete({ url: `/notifier/template/${id}` }),
  getConfig: (data: any) =>
    defHttp.post<any[]>({
      url: `/notifier/config/_query/no-paging?paging=false`,
      data
    }),
  getTemplateDetail: (id: string) =>
    defHttp.get<any>({ url: `/notifier/template/${id}/detail` }, { isTransformResponse: false }),
  debug: (data: any, configId: string, templateId: string) =>
    defHttp.post({ url: `/notifier/${configId}/${templateId}/_send`, data }),
  getHistory: (data: any, id: string) =>
    defHttp.post({ url: `/notify/history/template/${id}/_query`, data }, { isTransformResponse: false }),
  // 钉钉/微信, 根据配置获取部门和用户
  getDept: (type: string, id: string) => defHttp.get<any>({ url: `/notifier/${type}/corp/${id}/departments` }),
  getUser: (type: string, id: string) => defHttp.get<any>({ url: `/notifier/${type}/corp/${id}/users` }),
  // 微信获取标签推送
  getTags: (id: string) => defHttp.get<any>({ url: `/notifier/wechat/corp/${id}/tags` }),
  // 语音/短信获取阿里云模板
  getAliTemplate: (id: any) => defHttp.get({ url: `/notifier/sms/aliyun/${id}/templates` }),
  // 短信获取签名
  getSigns: (id: any) => defHttp.get({ url: `/notifier/sms/aliyun/${id}/signs` }),

  getListByConfigId: (id: string, data: any): any => {
    const params = {
      configId: id
    };
    return defHttp.post({ url: `/notifier/template/list`, params }, { isTransformResponse: false });
  }
};
