import { get, post, del, put } from '/@/utils/request';

export default {
  list: (params: object) => get('/api/list', params),
  add: (data: object) => post('/api/add', data),
  edit: (data: object) => put('/api/edit', data),
  delete: (ids: number[]) => del('/api/delete', { ids }),
  get: (id: number) => get(`/api/get`, { id }),
  publish: (id: number) => put(`/api/publish`, { id }),
  deprecate: (id: number) => put(`/api/deprecate`, { id }),
  test: (data: object) => post(`/api/test`, data),
  group: {
    tree: () => get('/api_group/tree'),
    get: (id: number) => get(`/api_group/get`, { id }),
    delete: (ids: number[]) => del('/api_group/delete', { ids }),
    add: (data: object) => post('/api_group/add', data),
    edit: (data: object) => put('/api_group/edit', data),
  },
  dataSource: {
    list: (params: object) => get('/datasource/list', params),
    get: (id: number) => get(`/datasource/get`, { id }),
    add: (data: object) => post('/datasource/add', data),
    edit: (data: object) => put('/datasource/edit', data),
    delete: (ids: number[]) => del('/datasource/delete', { ids }),
    test: (data: object) => post('/datasource/test', data),
  },
  client: {
    list: (params: object) => get('/client/list', params),
    get: (id: number) => get(`/client/get`, { id }),
    add: (data: object) => post('/client/add', data),
    edit: (data: object) => put('/client/edit', data),
    delete: (ids: number[]) => del('/client/delete', { ids }),
    resetSecret: (id: number) => put('/client/reset-secret', { id }),
    getApis: (clientId: string) => get('/client/apis', { clientId }),
    save_apis: (clientId: string, apiKeys: string[]) => post('/client/save_apis', { clientId, apiKeys })
  },
  plugin: {
    list: (params: object) => get('/plugin/list', params),
    get: (id: number) => get(`/plugin/get`, { id }),
    add: (data: object) => post('/plugin/add', data),
    edit: (data: object) => put('/plugin/edit', data),
    delete: (ids: number[]) => del('/plugin/delete', { ids }),
    test: (data: object) => post('/plugin/test', data)
  }
}
