package cn.axzo.msg.center.message.domain.dto;

import cn.axzo.msg.center.domain.entity.CardStyle;
import cn.axzo.msg.center.domain.entity.MessageTemplateButtonV3;
import cn.axzo.msg.center.domain.entity.MessageTemplateGroupV3;
import cn.axzo.msg.center.domain.entity.MessageTemplateV3;
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
import cn.axzo.msg.center.service.enums.PresetButtonType;
import cn.axzo.msg.center.service.enums.RouterCategoryEnum;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;

/**
 * @author yanglin
 */
@Setter
@Getter
public class TemplateModelV3 {

    @NotNull private MessageTemplateV3 template;
    @Nullable private CardStyle cardStyle;
    @NotNull private List<MessageTemplateGroupV3> groups;
    @NotNull private List<MessageTemplateButtonV3> buttons;

    public String getTemplateCode() {
        return template.getCode();
    }

    public MessageCategoryEnum getTemplateCategory() {
        return template.getMsgCategory();
    }

    public boolean hasPresetButtons() {
        return buttons.stream()
                .anyMatch(btn -> btn.getCategory() == RouterCategoryEnum.PRESET_BUTTON);
    }

    public Optional<MessageTemplateButtonV3> findPresetButton(PresetButtonType type) {
        return buttons.stream()
                .filter(btn -> btn.getPresetBtnType() == type)
                .findFirst();

    }
}