package me.qwq.doghouse.exception;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 抛出该异常，返回带状态码的 R
 * @author Doghole
 * @see me.qwq.doghouse.pojo.dto.R
 * @see me.qwq.doghouse.component.DoghouseExceptionHandler
 *
 */
@Data
@Accessors(chain=true)
@EqualsAndHashCode(callSuper=false)
@AllArgsConstructor
public class RException extends RuntimeException {
    
    private static final long serialVersionUID = -4140809043470089887L;
    
    private HttpStatus httpStatus;
    
    private Boolean logRequest = false;

    public RException(HttpStatus status) {
        super((String)null);
        this.httpStatus = status;
    }
    
    public RException(HttpStatus status, String message) {
        super(message);
        this.httpStatus = status;
    }

    public static RException badRequest() {
        return new RException(HttpStatus.BAD_REQUEST);
    }
    
    public static RException badRequest(String message) {
        return new RException(HttpStatus.BAD_REQUEST, message);
    }
    
    public static RException unauthorized() {
        return new RException(HttpStatus.UNAUTHORIZED);
    }
    
    public static RException unauthorized(String message) {
        return new RException(HttpStatus.UNAUTHORIZED, message);
    }

    public static RException internalServerError() {
        return new RException(HttpStatus.INTERNAL_SERVER_ERROR);
    }

    public static RException internalServerError(String message) {
        return new RException(HttpStatus.INTERNAL_SERVER_ERROR, message);
    }

}
