package cn.estsh.i3plus.ext.mes.pcn.apiservice.util;

import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;

/**
 * @Description : 抛出异常的工具类，用于简化抛出异常的代码
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/5/8 17:16
 * @Modify:
 **/
public class MesPcnException {

    /**
     * 抛出业务系统异常
     * @param errorDetail 异常信息
     * @param errorSolution 异常的解决方案
     * @throws ImppBusiException
     */
    public static void throwFlowException(String errorDetail, String errorSolution)
            throws ImppBusiException {

        throw ImppExceptionBuilder.newInstance()
                .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
                .setErrorDetail(errorDetail)
                .setErrorSolution(errorSolution)
                .build();
    }

    /**
     * 抛出业务系统异常
     * @param errorDetail 异常信息
     * @throws ImppBusiException
     */
    public static void throwFlowException(String errorDetail)
            throws ImppBusiException {

        throwFlowException(errorDetail, "");
    }

    /**
     * WMS 抛出业务异常
     * @param errorCode 错误代码
     * @param errorDetail 错误详情
     * @param errorSoluction 解决办法
     */
    public static void throwBusiExceptionByCode(String errorCode,String errorDetail,String errorSoluction,Object...args){
        throw ImppExceptionBuilder.newInstance()
                .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                .setErrorCode(errorCode)
                .setErrorDetail(errorDetail,args)
                .setErrorSolution(errorSoluction)
                .build();
    }
    /**
     * 抛异常
     *
     * @param
     */
    public static void throwMesBusiException(String errorDetailString, Object... args) {
        throw ImppExceptionBuilder.newInstance()
                .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION_DATA_ERROR.getCode())
                .setErrorDetail(errorDetailString,args)
                .build();
    }

    /**
     * 抛出业务异常
     * @param errorDetail 错误详情
     */
    public static void throwBusiException(String errorDetail, Object...args){
        throw ImppExceptionBuilder.newInstance()
                .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                .setErrorDetail(errorDetail, args)
                .build();
    }

}
