package cd.casic.ci.repository.exception;

import cd.casic.ci.repository.enums.RepositoryExceptionEnum;
import cd.casic.framework.commons.exception.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 后台管理代码仓异常 Exception
 */
@Data
@EqualsAndHashCode(callSuper = true)
public final class RepositoryException extends RuntimeException {

    private Integer code;

    private String message;

    public RepositoryException() {
    }

    public RepositoryException(String message) {
        this.message = message;
    }

    public RepositoryException(String message, Throwable cause) {
        super(cause);
        this.message = message;
    }

    public RepositoryException(RepositoryExceptionEnum repositoryExceptionEnum) {
        this.message = repositoryExceptionEnum.getMessage();
        this.code = repositoryExceptionEnum.getCode();
    }

    public RepositoryException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    public RepositoryException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public RepositoryException setMessage(String message) {
        this.message = message;
        return this;
    }

    @Override
    public String getMessage() {
        return message;
    }

}