package com.yzt.airconditionersystem.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;
import java.util.List;

/**
 * @author TzZach
 * @since 2022-04-13 21:44
 */
public class Result extends HashMap<String, Object> {

    public static final Integer SUCCESS_CODE = 0;
    public static final Integer ERROR_CODE = 1;

    public static final String SUCCESS_MSG = "成功";
    public static final String ERROR_MSG = "失败";

    private static final String CODE = "code";
    private static final String MSG = "msg";
    private static final String DATA = "data";

    private String code;
    private String msg;
    private Object data;


    public Result(Integer code, String msg, Object data) {
        put(CODE, code);
        put(MSG, msg);
        if(data != null) {
            put(DATA, data);
        }
    }

    public static Result success() {
        return new Result(SUCCESS_CODE, SUCCESS_MSG, null);
    }

    public static Result success(Object data) {
        return new Result(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static Result success(Integer code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result success(Integer code, String msg, Object data) {
        return new Result(code, msg, data);
    }


    public static Result error() {
        return new Result(ERROR_CODE, ERROR_MSG, null);
    }

    public static Result error(Object data) {
        return new Result(ERROR_CODE, ERROR_MSG, data);
    }

    public static Result error(Integer code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error(Integer code, String msg, Object data) {
        return new Result(code, msg, data);
    }



}
