package com.handong.smartservice.component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;

public class CtResponse extends HashMap<String, Object> {

    public CtResponse() {
        put("errCode", ErrorCode.NO_ERROR);
    }

    public CtResponse(String key, Object obj) {
        put("errCode", ErrorCode.NO_ERROR);
        put(key, obj);
    }

    public CtResponse(int errCode) {
        put("errCode", errCode);
    }

    public int errCode() {
        return (int)get("errCode");
    }

    public void setErrCode(int errCode) {
        put("errCode", errCode);
    }

    public String toJson() {
        String json = "{}";
        ObjectMapper mapper = new ObjectMapper();
        try {
            //json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data);
            json = mapper.writeValueAsString(this);
        }
        catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return json;
    }
}
