package be.naaturel.boardmateapi.controllers;

import java.util.Optional;

public class ResponseBody<T> {

    private T data;
    private String message;
    private boolean success;

    /**
     * Create a default empty response body containing no data, no message and flagged as failure
     * @return Empty response of T
     * @param <T> The wrapped data type
     */
    public static <T> ResponseBody<T> createEmpty() {
        return new ResponseBody<>(null, null,false);
    }

    private ResponseBody(T data, String messageOpt, boolean success){
        this.data = data;
        this.message = null;
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public Optional<String> getMessage() {
        return Optional.ofNullable(message);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

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