package com.supervision.config.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
@ApiModel
public class GlobalResult<T> {

    private int code = 200;

    private String msg = "success";

    @ApiModelProperty
    private T data;


    public static <T> GlobalResult<T> ok() {
        return ok(null);
    }

    public static <T> GlobalResult<T> ok(T data) {
        GlobalResult<T> globalResult = new GlobalResult<>();
        globalResult.setData(data);
        return globalResult;
    }

    public static <T> GlobalResult<T> ok(T data, String message) {
        GlobalResult<T> globalResult = new GlobalResult<>();
        globalResult.setMsg(message);
        globalResult.setData(data);
        return globalResult;
    }

    public static <T> GlobalResult<T> error(String msg) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), null, msg);
    }


    public static <T> GlobalResult<T> error(int code, T data, String msg) {
        GlobalResult<T> globalResult = new GlobalResult<>();
        globalResult.setCode(code);
        globalResult.setData(data);
        globalResult.setMsg(msg);
        return globalResult;
    }
}
