package com.zksy.common.core.domain;

import com.zksy.common.constant.HttpStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 操作消息提醒2
 *
 * @author xianggx
 */
@Data
public class AjaxResult2<T> {

    @ApiModelProperty(value = "状态码", required = true)
    private int code;

    @ApiModelProperty(value = "返回内容", required = true)
    private String msg;

    @ApiModelProperty(value = "返回数据对象", required = false)
    private T data;

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 错误消息
     */
    public static <T> AjaxResult2<T> error(String msg) {
        AjaxResult2<T> apiResult = new AjaxResult2();
        apiResult.setCode(HttpStatus.ERROR);
        apiResult.setMsg(msg);
        return apiResult;
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static <T> AjaxResult2<T> success(T data) {
        AjaxResult2<T> apiResult = new AjaxResult2();
        apiResult.setCode(HttpStatus.SUCCESS);
        apiResult.setMsg("操作成功");
        apiResult.setData(data);
        return apiResult;
    }
}
