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

import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.nimpush.payload.intent.Intent;
import cn.axzo.msg.center.nimpush.payload.intent.IntentValue;
import org.apache.commons.lang3.StringUtils;

/**
 * @author yanglin
 */
abstract class AndroidPushPayloadBuilder<T extends Intent<?>>
        implements PushPayloadBuilder<T> {

    @Override
    public final T createIntent(PushContent content, PushPeer peer) {
        T intent = createIntent();
        BizAssertions.assertNotNull(intent, "intent can't be null");
        if (StringUtils.isNotBlank(content.getAndroidPushUrl()))
            Intent.setRouter(intent, IntentValue
                    .create(content.getAndroidPushUrl())
                    .urlEncode());
        return intent;
    }

    abstract T createIntent();

}