package com.tzy.framework.express.dto;

import com.tzy.common.dto.Result;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Data
@NoArgsConstructor
public class ExpressResult extends Result {

    private Map data;

    public ExpressResult(boolean success, Integer code, String msg){
        this.setSuccess(success);
        this.setCode(code);
        this.setMsg(msg);
    }
    public static ExpressResult ok(){
        return new ExpressResult();
    }
    public static ExpressResult ok(String msg) {
        return new ExpressResult(true,200,msg);
    }
    public static ExpressResult error(String msg) {
        return new ExpressResult(false, -1, msg);
    }
    /**
     * 失败
     * @param code
     * @param msg
     * @return
     */
    public static ExpressResult error(Integer code,String msg){
        return new ExpressResult(false, code, msg);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public ExpressResult put(String key,Object value){
        if(null == this.data) this.data = new HashMap<>();
        this.data.put(key,value);
        return this;
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public ExpressResult putString(String key,String value){
        if(null == this.data) this.data = new HashMap<>();
        this.data.put(key,value);
        return this;
    }

    /**
     *
     * @param key
     * @return
     */
    public Object get(String key){
        if(null != this.data) return this.data.get(key);
        return null;
    }

    /**
     * get String
     * @param key
     * @return
     */
    public String getString(String key){
        if(null != this.data)  return (String) this.data.get(key);
        return null;
    }
}
