package com.caliverse.admin.global.common.utils;

import com.caliverse.admin.domain.RabbitMq.message.LanguageType;
import com.caliverse.admin.domain.entity.Item;
import com.caliverse.admin.domain.entity.LANGUAGETYPE;
import com.caliverse.admin.domain.entity.Message;
import com.caliverse.admin.dynamodb.entity.MailItem;
import com.caliverse.admin.dynamodb.entity.SystemMessage;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class DynamodbUtil {
    public static String getSenderByLanguage(Message msg) {
        LANGUAGETYPE langType = LANGUAGETYPE.valueOf(msg.getLanguage());
        switch (langType) {
            case EN:
                return "CALIVERSE";
            case JA:
                return "カリバース";
            case KO:
                return "칼리버스";
            default:
                return null;
        }
    }

    public static Integer getLanguageType(String language) {
        LANGUAGETYPE langType = LANGUAGETYPE.valueOf(language);
        switch (langType) {
            case EN:
                return LanguageType.LanguageType_en.getNumber();
            case JA:
                return LanguageType.LanguageType_ja.getNumber();
            case KO:
                return LanguageType.LanguageType_ko.getNumber();
            default:
                return null;
        }
    }

    public static List<SystemMessage> createSystemMessages(List<Message> messages, Function<Message, String> textExtractor) {
        return messages.stream()
                .map(msg -> SystemMessage.builder()
                        .languageType(getLanguageType(msg.getLanguage()))
                        .text(textExtractor.apply(msg))
                        .build())
                .collect(Collectors.toList());
    }

    public static List<MailItem> createMailItems(List<Item> items) {
        return items.stream()
                .map(item -> MailItem.builder()
                        .itemId(CommonUtils.stringToInt(item.getItem()))
                        .count(item.getItemCnt())
                        .isRepeatProduct(false)
                        .productId(0)
                        .build())
                .collect(Collectors.toList());
    }
}
