package cn.axzo.msg.center.message.service.card;

import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
import cn.axzo.msg.center.service.pending.response.v3.model.ParsedModelV3;
import cn.axzo.msg.center.service.pending.response.v3.model.ParsedTemplateV3;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
 * @author yanglin
 */
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class CardTemplate {

    private final ParsedModelV3 parsedModel;

    public static CardTemplate wrap(ParsedModelV3 parsedModel) {
        return new CardTemplate(parsedModel);
    }

    public List<AppTypeEnum> ensureAppTypesPresent() {
        List<AppTypeEnum> appTypes = parsedModel.getTemplate().parsePushAppTypes();
        BizAssertions.assertNotEmpty(appTypes,
                "发送IM消息, 消息模版没有配置IM发送终端, templateCode={}", parsedModel.getTemplateCode());
        return appTypes;
    }

    public boolean isUpdatable() {
        return getTemplate().getMsgCategory() != MessageCategoryEnum.GENERAL_MESSAGE;
    }

    public ParsedTemplateV3 getTemplate() {
        return parsedModel.getTemplate();
    }

    public String getTemplateCode() {
        return parsedModel.getTemplateCode();
    }
}