import { request } from '@/sheep/request';
import { isEmpty } from 'lodash';
import { CRUD } from '@/sheep/request/crud';

export default {
  // 站内信分类
  notificationType: () =>
    request({
      url: 'admin/notification/notificationType',
    }),

  // 即时通讯配置
  chatInit: () =>
    request({
      url: 'chat/admin/index/init',
    }),

  // 站内信列表
  notifications: (params) =>
    request({
      url: 'admin/auth/admin/notifications',
      method: 'GET',
      params,
    }),

  read: (id) =>
    request({
      url: `admin/auth/admin/notification/${id}`,
      method: 'PUT',
    }),
  clear: () =>
    request({
      url: `admin/auth/admin/notifications`,
      method: 'DELETE',
    }),

  // 系统设置
  config: {
    // 客服配置
    basic: (data) =>
      request({
        url: 'chat/admin/config/basic',
        method: isEmpty(data) ? 'GET' : 'PUT',
        data,
        options: {
          showSuccessMessage: !isEmpty(data),
        },
      }),
    // 系统配置
    system: (data) =>
      request({
        url: 'chat/admin/config/system',
        method: isEmpty(data) ? 'GET' : 'PUT',
        data,
        options: {
          showSuccessMessage: !isEmpty(data),
        },
      }),
    // 应用配置
    application: (data) =>
      request({
        url: 'chat/admin/config/application',
        method: isEmpty(data) ? 'GET' : 'PUT',
        data,
        options: {
          showSuccessMessage: !isEmpty(data),
        },
      }),
  },

  admin: {
    // 常用语
    commonWord: {
      ...CRUD('chat/admin/commonWord'),
    },
    // 客服列表
    customerService: {
      ...CRUD('chat/admin/customerService'),
      select: (params) =>
        request({
          url: 'chat/admin/customerService/select',
          method: 'GET',
          params,
        }),
    },
    // 常见问题
    question: {
      ...CRUD('chat/admin/question'),
    },
    // 会话管理
    user: {
      ...CRUD('chat/admin/user'),
      detailList: (params) =>
        request({
          url: 'chat/admin/record',
          method: 'GET',
          params,
        }),
    },
  },
};
