package com.docus.server.collect.report;

import com.docus.server.collect.IWsResult;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component("wsReportResultImpl")
public class WsReportResultImpl implements IWsResult {

    private static final String SUCCESS_TEMPLATE = "<Response>" +
        "<Result>" +
        "<Code>0</Code>" +
        "<MsgId>%s</MsgId>" +
        "<Msg>成功！</Msg>" +
        "</Result>" +
        "</Response>";

    private static final String FAILED_TEMPLATE = "<Response>" +
        "<Result>" +
        "<Code>500</Code>" +
        "<MsgId>%s</MsgId>" +
        "<Msg>%s</Msg>" +
        "</Result>" +
        "</Response>";

    @Override
    public String ok(Map<String, Object> params) {
        return String.format(SUCCESS_TEMPLATE, params.get("msgId"));
    }

    @Override
    public String fail(Map<String, Object> params) {
        return String.format(FAILED_TEMPLATE, params.get("msgId"), params.get("msg"));
    }
}
