package de.champonthis.buntspecht.controller.support;

import org.springframework.core.NestedRuntimeException;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;

import jakarta.annotation.Nullable;


public class EntityResponseStatusException extends NestedRuntimeException {

	private static final long serialVersionUID = 1L;

	private final HttpStatus status;

	@Nullable
	private final Object body;

	
	public EntityResponseStatusException(HttpStatus status) {
		this(null, status);
	}

	
	public EntityResponseStatusException(@Nullable Object body, HttpStatus status) {
		this(body, status, null);
	}

	
	public EntityResponseStatusException(@Nullable Object body, HttpStatus status, @Nullable Throwable cause) {
		super(null, cause);
		Assert.notNull(status, "HttpStatus is required");
		this.status = status;
		this.body = body;
	}

	
	public HttpStatus getStatus() {
		return this.status;
	}

	
	@Nullable
	public Object getBody() {
		return this.body;
	}

	/*
	 * @see org.springframework.core.NestedRuntimeException#getMessage()
	 */
	@Override
	public String getMessage() {
		return this.status + (this.body != null ? " \"" + this.body + "\"" : "");
	}

}
