package com.luojia_channel.common.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

// 统一返回前端的结果
@Data
@Schema(description = "统一返回前端的结果")
public class Result<T> {
    @Schema(description = "状态码")
    private int code;

    @Schema(description = "提示消息")
    private String msg;

    @Schema(description = "响应数据")
    private T data;
    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "success", data);
    }
    public static <T> Result<T> success() {
        return new Result<>(200, "success", null);
    }
    public static <T> Result<T> fail(String msg) {
        return new Result<>(500, msg, null);
    }
    public static <T> Result<T> fail(int code, String msg) {
        return new Result<>(code, msg, null);
    }
}
