package com.caliverse.admin.domain.datacomponent;
import com.caliverse.admin.domain.entity.LANGUAGETYPE;
import com.caliverse.admin.domain.entity.metadata.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MetaDataHandler {

    @Autowired private MetaDataFileLoader metadataFileLoader;

    @Autowired
    public MetaDataHandler(MetaDataFileLoader metaDataFileLoader){
        this.metadataFileLoader = metaDataFileLoader;
    }

    public String getTextStringData(String text) {
        return metadataFileLoader.getName(text)
                .map(MetaTextStringData::getKor)
                .orElse("");
    }

    public String getTextStringData(String text, LANGUAGETYPE lang) {
        return metadataFileLoader.getName(text)
                .map(data -> lang.equals(LANGUAGETYPE.JA) ? data.getJa() : lang.equals(LANGUAGETYPE.EN) ? data.getEn() : data.getKor())
                .orElse("");
    }

    public String getMetaItemNameData(int itemId) {
        return metadataFileLoader.getMetaItem(itemId)
                .map(MetaItemData::getName)
                .orElse("");
    }

    public String getMetaItemLargeTypeData(int itemId) {
        return metadataFileLoader.getMetaItem(itemId)
                .map(MetaItemData::getLargeType)
                .orElse("");
    }

    public String getMetaClothSlotTypeData(int metaId) {
        return metadataFileLoader.getMetaClothType(metaId)
                .map(MetaClothTypeData::getEquipSlotType)
                .orElse("");
    }

    public String getMetaClothSmallTypeData(int metaId) {
        return metadataFileLoader.getMetaClothType(metaId)
                .map(MetaClothTypeData::getSmallType)
                .orElse("");
    }

    public List<MetaQuestData> getMetaQuestData(int questId) {
        return metadataFileLoader.getMetaQuests(questId);
    }

    public MetaBuildingData getMetaBuildingData(int buildingId) {
        return metadataFileLoader.getMetaBuildingItem(buildingId)
                .orElse(null);
    }

    public MetaLandData getMetaLandData(int landId) {
        return metadataFileLoader.getMetaLandItem(landId)
                .orElse(null);
    }

    public String getMetaWebLinkData(String key, LANGUAGETYPE lang) {
        return metadataFileLoader.getMetaWebLinkLocalize(key)
                .map(data -> lang.equals(LANGUAGETYPE.EN) ? data.getEn() : lang.equals(LANGUAGETYPE.JA) ? data.getJa() : data.getKo())
                .orElse("");
    }

    public String getMetaBuffName(int metaId){
        return metadataFileLoader.getMetaBuff(metaId)
                .map(MetaBuffData::getBuffName)
                .orElse("");
    }

    public String getMetaAttribData(String groupId){
        return metadataFileLoader.getMetaAttributeRandomGroup(groupId)
                .map(MetaAttributeRandomGroupData::getAttribute)
                .orElse("");
    }

    public String getMetaItemSetName(int metaId){
        return metadataFileLoader.getMetaItemSet(metaId)
                .map(MetaItemSetData::getName)
                .orElse("");
    }

    public Integer getMetaGachaGroupId(int metaId){
        return metadataFileLoader.getMetaGacha(metaId)
                .map(MetaGachaData::getGroupId)
                .orElse(0);
    }

    public String getMetaBrandName(int metaId){
        return metadataFileLoader.getMetaBrand(metaId)
                .map(MetaBrandData::getBrandName)
                .orElse("");
    }

    public String getMetaCurrencyName(int metaId){
        return metadataFileLoader.getMetaCurrency(metaId)
                .map(MetaCurrencyData::getName)
                .orElse("");
    }

    //전체 리스트

    public List<MetaBuildingData> getMetaBuildingListData() {
        return metadataFileLoader.getMetaBuildings();
    }

    public List<MetaLandData> getMetaLandListData() {
        return metadataFileLoader.getMetaLands();
    }

    public List<MetaBattleConfigData> getMetaBattleConfigsListData() {
        return metadataFileLoader.getMetaBattleConfigs();
    }

    public List<MetaBattleRewardData> getMetaBattleRewardsListData() {
        return metadataFileLoader.getMetaBattleRewards();
    }

    public List<MetaGameModeData> getMetaGameModeListData() {
        return metadataFileLoader.getMetaGameModes();
    }

    public List<MetaGameModeMatchData> getMetaGameModeMatchListData() {
        return metadataFileLoader.getMetaGameModeMatchs();
    }

    public List<MetaGameFFAConfigData> getMetaGameFFAConfigListData() {
        return metadataFileLoader.getMetaGameFFAConfigs();
    }

    public List<MetaSystemMailData> getMetaSystemMailListData() {
        return metadataFileLoader.getMetaSystemMail();
    }
    public List<MetaItemData> getMetaItemListData() {
        return metadataFileLoader.getMetaItems();
    }
    public List<MetaBrandData> getMetaBrandListData() {
        return metadataFileLoader.getMetaBrand();
    }

}

