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

import cn.axzo.msg.center.common.exception.ServiceException;
import cn.axzo.msg.center.domain.entity.CardStyle;
import cn.axzo.msg.center.domain.utils.StringListTypeHandler;
import cn.axzo.msg.center.service.card.request.CardStyleCreateRequest;
import cn.axzo.msg.center.service.card.request.CardStyleDeleteRequest;
import cn.axzo.msg.center.service.card.request.CardStyleUpdateRequest;
import cn.axzo.msg.center.service.domain.card.AppVersionConfig;
import cn.axzo.msg.center.service.domain.card.StateImageConfig;
import cn.axzo.msg.center.service.dto.MessageTemplateButtonV3DTO;
import cn.axzo.msg.center.service.dto.MessageTemplateCardJumpV3DTO;
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
import cn.axzo.msg.center.service.enums.MessageChannel;
import cn.axzo.msg.center.service.enums.PushTerminalEnum;
import cn.axzo.msg.center.service.enums.StatusEnum;
import cn.axzo.msg.center.service.pending.card.domain.CardElementConfig;
import cn.axzo.msg.center.service.template.request.MessageTemplateGroupV3CreateRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3CreateRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3DeleteRequest;
import cn.axzo.msg.center.service.template.request.MessageTemplateV3UpdateRequest;
import cn.axzo.msg.center.service.template.response.MessageTemplateV3DetailResponse;
import cn.axzo.msg.center.utils.MessageTemplateCategoryUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @description
 *
 * @author cold_blade
 * @date 2023/10/5
 * @version 1.0
 */
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CardStyleSaveOrUpdateParam implements Serializable {

    private static final long serialVersionUID = 6657624182580261353L;

    /**
     * 样式名称
     */
    private String name;

    /**
     * 样式code, 唯一
     */
    private String code;

    /**
     * 预览大图
     */
    private List<String> previewImages;

    /**
     * 卡片元素配置
     */
    private List<CardElementConfig> elementConfigs;


    public static CardStyleSaveOrUpdateParam from(CardStyleCreateRequest request) {

        return CardStyleSaveOrUpdateParam.builder()
                .name(request.getName())
                .code(request.getCode())
                .previewImages(request.getPreviewImages())
                .elementConfigs(request.getElementConfigs())
                .build();
    }

    public CardStyle toEntityWhenCreate(String code) {
        CardStyle cardStyle = new CardStyle();
        cardStyle.setName(this.getName());
        cardStyle.setCode(code);
        cardStyle.setPreviewImages(this.getPreviewImages());
        cardStyle.setElementConfigs(this.getElementConfigs());
        return cardStyle;
    }

    public static CardStyleSaveOrUpdateParam from(CardStyleUpdateRequest request) {
        return CardStyleSaveOrUpdateParam.builder()
                .name(request.getName())
                .code(request.getCode())
                .previewImages(request.getPreviewImages())
                .elementConfigs(request.getElementConfigs())
                .build();
    }

    public static CardStyleSaveOrUpdateParam from(CardStyleDeleteRequest request) {
        return CardStyleSaveOrUpdateParam.builder()
                .code(request.getCode())
                .build();
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
