import axiosInstance from "@/api/axios.ts";
import type {IErrorBaseSearch} from "@/interface/page/error/IErrorBaseSearch.ts";
import type {IAppBaseErrorInfo} from "@/model/table/IAppBaseErrorInfo.ts";
import {CookieUtils} from "@/utils/CookieUtils.ts";

export default class BaseErrorApi {

    // 下载示例文件
    static downLoadImportExample() {
        return axiosInstance.get('/app/baseError/downloadImportExample', {
            responseType: 'blob',
            timeout: 30000
        });
    };

    // 分页查询基础异常资料
    static queryBaseError(queryData: IErrorBaseSearch, pageIndex: number, pageSize: number) {
        return axiosInstance.post('/app/baseError/queryBaseErrorList', queryData, {
            params: {
                pageIndex: pageIndex,
                pageSize: pageSize
            }
        });
    };

    // 添加基础异常资料
    static addBaseError(addData: IAppBaseErrorInfo) {
        return axiosInstance.post('/app/baseError/addBaseError', addData);
    };

    // 返回导入的地址
    static getImportUrl() {
        return axiosInstance.defaults.baseURL + '/app/baseError/importBaseError'
    };

    // 获取导入的请求头
    static getHeaders() {
        const token = new CookieUtils().getItem('wcsToken');
        if (token) {
            return {Wcstoken: token};
        }
        return {};
    };

    // 删除特定类型的基础异常资料
    static deleteBaseError(equipmentType: number) {
        return axiosInstance.delete('/app/baseError/deleteBaseErrorByEquipmentType', {
            params: {
                equipmentType: equipmentType
            }
        });
    };

    // 删除特定id的基础异常资料
    static deleteBaseErrorById(id: number) {
        return axiosInstance.delete('/app/baseError/deleteBaseErrorById', {
            params: {
                id: id
            }
        });
    };

    // 修改基础异常资料
    static updateBaseError(updateData: IAppBaseErrorInfo) {
        return axiosInstance.post('/app/baseError/updateBaseError', updateData);
    };

    // 获取异常基础资料
    static getBaseError(equipmentType: number, errorCode: string) {
        return axiosInstance.get('/app/baseError/getBaseError', {
            params: {
                equipmentType: equipmentType,
                errorCode: errorCode
            }
        });
    }

}