package cn.axzo.msg.center.nimpush.payload.intent;

import cn.axzo.msg.center.common.utils.BizAssertions;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author yanglin
 */
public class UriIntent implements Intent<String> {

    private static final String INTENT_PREFIX =
            "intent://cn.axzo.codelabpush/deeplink?#Intent;scheme=pushschema;launchFlags=0x4000000;";

    private final LinkedHashMap<String, IntentValue> values = new LinkedHashMap<>();

    @Override
    public void setValue(String key, IntentValue value) {
        BizAssertions.assertNotBlank(key, "key is required");
        BizAssertions.assertNotNull(value, "value is required");
        values.put(key, value);
    }

    @Override
    public String build() {
        StringBuilder buf = new StringBuilder(INTENT_PREFIX);
        for (Map.Entry<String, IntentValue> entry : values.entrySet()) {
            entry.getValue().consume(stringValue ->
                    buf.append("S.")
                            .append(entry.getKey())
                            .append("=")
                            .append(stringValue)
                            .append(";"));
        }
        buf.append("end");
        return buf.toString();
    }

}