package com.cpp.web.service.datafactory.impl;

import com.cpp.web.domain.datafactory.BaseParsing;
import com.cpp.web.domain.datafactory.enums.FileTypeEnum;
import com.cpp.web.service.datafactory.BaseParsingService;
import com.cpp.web.service.datafactory.ParsingInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@RequiredArgsConstructor
public class BaseParsingServiceImpl implements BaseParsingService {

//    private final Parsing parsingDqInfoService;
//    private final ParsingCdqInfoService parsingCdqInfoService;
//    private final ParsingNwpInfoService parsingNwpInfoService;
//

    private final Map<String, ParsingInterface> parsingInterfaceMap;


    @Override
    public List<BaseParsing> getParsingInfos() {

        List<BaseParsing> parsingInfos = new ArrayList<>();

//        parsingInfos.addAll(parsingDqInfoService.list());
//        parsingInfos.addAll(parsingCdqInfoService.list());
//        parsingInfos.addAll(parsingNwpInfoService.list());

        return parsingInfos;
    }

    @Override
    public List<Map<String,String>> getFileType() {
        FileTypeEnum[] values = FileTypeEnum.values();
        List<Map<String,String>> mapList = new ArrayList<>();
        for (FileTypeEnum value : values) {
            Map<String,String> map = new HashMap<>();
            map.put(value.name(),value.getMessage());
            mapList.add(map);
        }
        return mapList;
    }

    @Override
    public boolean save(BaseParsing baseParsing) {

        ParsingInterface parsingInterface = parsingInterfaceMap.get("parsing" + baseParsing.getFileType() + "ServiceImpl");

        return parsingInterface.save(baseParsing);
    }

    @Override
    public boolean deleteById(BaseParsing baseParsing) {
        ParsingInterface parsingInterface = parsingInterfaceMap.get("parsing" + baseParsing.getFileType() + "ServiceImpl");

        return parsingInterface.deleteById(baseParsing.getId());
    }


}
