import { addDataSource, dataSourceConnect, dataSourceConnectTest, delDataSource, getDataSourceById, getDataSourcePage, updateDataSource } from '@/api/schedule/dataSource'
import { message } from 'ant-design-vue'

export class DataSourceController {
  static async page (params: COMMON.API.QueryParams & {label: string, dataSourceType: SCHEDULE.SOURCE.DataSourceType}) {
    return await getDataSourcePage(params)
  }

  static async add (data: SCHEDULE.SOURCE.Detail) {
    await addDataSource(data)
    message.success('新增成功')
  }

  static async update (data: SCHEDULE.SOURCE.Detail) {
    await updateDataSource(data)
    message.success('修改成功')
  }

  static async del (id: string) {
    await delDataSource(id)
    message.success('删除成功')
  }

  static async byId (id: string) {
    return getDataSourceById(id)
  }

  static async connect (data: SCHEDULE.SOURCE.Detail) {
    await dataSourceConnect(data)
    message.success('连接成功')
  }

  static async connectTest (id: string) {
    await dataSourceConnectTest(id)
    message.success('测试连接成功')
  }
}
