import { defHttp } from '/@/utils/http/axios';

enum Api {
    // 数据库操作
    GetBackupsDatabase = '/DbBackups-center/dbBackups/getBackupsDatabase',
    DelBackupsDatabase = '/DbBackups-center/dbBackups/DelBackupsDatabase',
    EditBackupsDatabase = '/DbBackups-center/dbBackups/editBackupsDatabase',
    // 数据备份
    GetBackupsDate = '/DbBackups-center/dbBackups/GetBackupsDate',
    BackupsDate = '/DbBackups-center/dbBackups/BackupsDate',
    DownloadDBFile = '/DbBackups-center/dbBackups/downloadDBFile',
    DelBackupsDate = '/DbBackups-center/dbBackups/DelBackupsDate',
    // 定时策略
    editScheduledTaskCL = '/DbBackups-center/dbBackups/editScheduledTaskCL',
    DelScheduledTaskCL = '/DbBackups-center/dbBackups/delScheduledTaskCL',
    GetScheduledTaskCL = '/DbBackups-center/dbBackups/getScheduledTaskCL',
    // 数据恢复
    RestoreDate = '/DbBackups-center/dbBackups/restoreDate'
}

/**
 * @description: 获取数据库信息列表
 * @param page string 页码
 * @param rows string 每页大小
 * @param fid string 备份id
 * @param keyStr string 关键字
 */
export const getBackupsDatabaseList = (params: any) => {
    let param = {
        page:1,
        rows:1000000,
        ...params
    }
    return new Promise<void>((resolve) => {
        defHttp.post({url: Api.GetBackupsDatabase, params: param }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 删除数据库信息
 * @param fid string 备份id
 */
export const delBackupsDatabase = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.DelBackupsDatabase, params: params }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 编辑数据库信息
 * @param dbip string 数据库ip
 * @param dbloginname string 数据库登录名
 * @param pwd string 数据库密码
 * @param dbname string 数据库名
 * @param fid string 数据库信息fid
 */
export const editBackupsDatabase = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.EditBackupsDatabase, params: params }).then((res) => {
            resolve(res)
        })
    })
};


/**
 * @description: 获取数据备份列表
 * @param page string 页码
 * @param rows string 每页大小
 * @param keyStr string 关键字
 * @param starttime string 备份开始时间
 * @param endtime string 备份结束时间
 */
export const getBackupsList = (params: any) => {
    let param = {
        page:1,
        rows:1000000,
        ...params
    }
    return new Promise<void>((resolve) => {
        defHttp.post({url: Api.GetBackupsDate, params: param }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 新增数据备份
 * @param dbBackups object 备份参数
 */
export const addDataBackup = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.BackupsDate, params: params }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 下载数据备份
 * @param fid string 备份数据fid
 */
export const downloadDBFile = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.DownloadDBFile, params: params }).then((res) => {
            resolve(res)
        })
    })
}
/**
 * @description: 删除数据备份
 * @param fid string 备份数据fid
 */
export const delDataBackup = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.DelBackupsDate, params: params }).then((res) => {
            resolve(res)
        })
    })
}



/**
 * @description: 新增定时策略
 * @param bfFid string 备份数据库Fid
 * @param bfzq number 备份周期（1：周；2：月）
 * @param sjsz number 时间设置（周：1——7，月：1——31）
 * @param zxsj string 执行时间（格式必须是10:15）
 * @param fid string 备份定时任务Fid
 * @param status number 是否启用（0禁用,1启用） 
 */
export const EditScheduledTaskCL = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.editScheduledTaskCL, params: params }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 获取定时策略
 * @param page string 页码
 * @param rows string 每页大小
 * @param fid string 备份定时任务Fid
 * @param keyStr string 关键字
 */
export const getScheduledTaskCL = (params: any) => {
    let param = {
        page:1,
        rows:1000000,
        ...params
    }
    return new Promise<void>((resolve) => {
        defHttp.post({url: Api.GetScheduledTaskCL, params: param }).then((res) => {
            resolve(res)
        })
    })
};
/**
 * @description: 删除定时策略
 * @param fid string 备份定时任务Fid
 */
export const delScheduledTaskCL = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.DelScheduledTaskCL, params: params }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 数据恢复
 * @param bfFid string 数据备份id
 * @param userid string 人员id
 */
export const dataRestore = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.RestoreDate, params: params }).then((res) => {
            resolve(res)
        })
    })
};