package com.zcloud.entity;

import java.util.HashMap;

public class Response extends HashMap<Object,Object> {

    private Response(){
        super();
    }

    public static Response getResponse(){
        Response response = new Response();
        return response;
    }

    public static Response getResponse(String result){
        Response response = new Response();
        response.put("result", result);
        if ("usererror".equals(result)) {
            response.put("msg", "用户名或密码有误");
        } else if ("error".equals(result)) {
            response.put("msg", "缺少参数");
        } else if ("userUSEerror".equals(result)) {
            response.put("msg", "您的企业已到使用期限，请联系管理员");
        }
        return response;
    }
    /**
     * description:组装返回参数
     * @author sparrow
     *
     * @date 2022-06-01
     */
    public void assemble(String result) {
        this.put("result", result);
    }

    /**
     * description:<p/>
     * usererror = 用户名或密码有误
     * error = 缺少参数
     * userUSEerror = 您的企业已到使用期限，请联系管理员
     * user_role_error = 该用户没有登陆系统权限
     *
     * @param errorMessage
     * @return
     */
    public Response error(String errorMessage){
       assemble("error");
       this.put("msg",errorMessage);
       return this;
    }

    public Response errorMessage(String errorMessage){
        assemble("success");
        this.put("code","9999");
        this.put("errorMessage",errorMessage);
        return this;
    }

    public Response errorMessage(String errorMessage,String Code){
        assemble("success");
        this.put("code",Code);
        this.put("errorMessage",errorMessage);
        return this;
    }

    public Response succeedMessage(String message){
        this.OK();
        this.put("succeedMessage",message);
        return this;
    }

    public Response error(){
        assemble("error");
        return this;
    }
    /**description:生成成功返回对象
     * 自带result参数
     *
     * @return Response
     */
    public Response OK(String succeed){
        assemble("success");
        this.put("msg",succeed);
        return this;
    }

    /**description:生成成功返回对象
     * 自带result参数
     *
     * @return Response
     */
    public Response OK(){
        assemble("success");
        this.put("code","0");
        return this;
    }

    public void NotNullPut(){

    }

}
