package com.crm.rely.backend.exception;

import com.crm.rely.backend.core.constant.Constants;
import lombok.Data;

/**
 * @author houn
 */
@Data

public class ServiceException extends Exception {

    private int code;

    public ServiceException(int code, String msg) {
        super(msg);
        this.code = code;
    }

    public ServiceException(String msg) {
        super(msg);
        code = Constants.FAILED_CODE;
    }

    public ServiceException(String msg, Object... args) {

        super(String.format(msg, args));
        code = Constants.FAILED_CODE;
    }

    public ServiceException(int code, String msg, Object... args) {

        this(code, String.format(msg, args));
    }

    public static ServiceException exception() {
        return new ServiceException(Constants.SYSTEM_ERROR);
    }

    public static ServiceException notFoundException() {
        return new ServiceException(Constants.INFO_NOT_FOUND);
    }

    public static ServiceException restrictRequest() {
        return new ServiceException("restrict_request");
    }

    public static ServiceException exception(String msg) {
        return new ServiceException(msg);
    }

    public static ServiceException exception(int code, String msg, Object... args) {
        return new ServiceException(code, msg, args);
    }

    public static ServiceException exception(String msg, Object... args) {
        return new ServiceException(msg, args);
    }
}
