package com.ebts.common.core.entity;


import com.ebts.common.constant.HttpStatus;

import java.io.Serializable;

/**
 * @description: some desc
 * @author: Binlin B Wang
 * @email: binlin.b.wang@cn.pwc.com
 * @date: 2022/5/31 10:00
 */
public class Result<T> implements Serializable {
    private int code;
    private boolean success;
    private String msg;
    private T data;

    public Result(int code, boolean success, String msg, T data) {
        this.code = code;
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> ok(int code, String msg, T data) {
        return new Result<>(code, true, msg, data);
    }

    public static <T> Result<T> ok(String msg, T data) {
        return Result.ok(HttpStatus.SUCCESS, msg, data);
    }

    public static <T> Result<T> ok(int code, T data) {
        return Result.ok(code, "操作成功", data);
    }

    public static <T> Result<T> ok(T data) {
        return Result.ok("操作成功", data);
    }

    public static <T> Result<T> ok() {
        return Result.ok("操作成功");
    }

    public static <T> Result<T> ok(String msg) {
        return Result.ok(msg, null);
    }

    public static <T> Result<T> error(String msg, T data) {
        return Result.error(HttpStatus.ERROR, msg, data);
    }

    public static <T> Result<T> error(int code, String msg) {
        return Result.error(code, msg, null);
    }

    public static <T> Result<T> error(int code, String msg, T data) {
        return new Result<>(code, false, msg, data);
    }

    public static <T> Result<T> error(String msg) {
        return Result.error(HttpStatus.ERROR, msg, null);
    }

    public static <T> Result<T> error() {
        return Result.error(HttpStatus.ERROR, "操作失败", null);
    }

    public static <T> Result<T> info(String msg) {
        return new Result<>(HttpStatus.NO_DATA, true, msg, null);
    }

    public static <T> Result<T> info() {
        return new Result<>(HttpStatus.NO_DATA, true, "查询为空", null);
    }


    public int getCode() {
        return code;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
