package com.sptg.common.core.beans;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * title: ResultBean
 * package: com.sptg.common.core.beans
 * description: 所有接口的返回值类型
 *                  
 *               
 */
@Getter
public class ResultBean<Entity> implements java.io.Serializable {

    /**
     * 状态代码
     */
    private String code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 返回值
     */
    @Setter
    private Entity data;

    /**
     * 返回值列表,有序
     */
    @Setter
    private List<Entity> list;

    /**
     * 全部返回值状态枚举的父类接口
     */
    public interface BaseResultEnum {

        /**
         * 错误代码
         * @return String
         */
        String getCode();

        /**
         * 错误消息
         * @return String
         */
        String getMsg();

    }

    /* ================================================== 构造函数 ================================================== */

    public ResultBean(){

    }

    public ResultBean(String code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(BaseResultEnum result){
        this(result.getCode(),result.getMsg());
    }

    public ResultBean(BaseResultEnum result, Entity data) {
        this(result);
        this.data = data;
    }

    public ResultBean(BaseResultEnum result, List<Entity> list) {
        this(result);
        this.list = list;
    }

    public static ResultBean ok(){
        return new ResultBean(ResultEnum.SUCCESS);
    }

    public static <T> ResultBean<T> ok(T data){
        return new ResultBean<>(ResultEnum.SUCCESS,data);
    }

}
