package com.huimv.employment.common.web;

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

import java.io.Serializable;

/**
 * 统一 API 响应体，与技术方案 §6.1 约定一致。
 */
@Schema(description = "统一响应体")
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "业务状态码，200 表示成功", example = "200")
    private int code;

    @Schema(description = "提示信息", example = "success")
    private String msg;

    @Schema(description = "业务数据")
    private T data;

    public R() {
    }

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

    /** 成功响应，携带业务数据 */
    public static <T> R<T> ok(T data) {
        return new R<>(200, "success", data);
    }

    /** 成功响应，无业务数据 */
    public static <T> R<T> ok() {
        return ok(null);
    }

    /** 失败响应 */
    public static <T> R<T> fail(int code, String msg) {
        return new R<>(code, msg, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

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