package com.dbnt.kcscbackend.admin.config.service.impl;

import com.dbnt.kcscbackend.admin.config.service.AdminCommitteeCodeManagementService;
import com.dbnt.kcscbackend.admin.standardResearch.model.CreateStandardResearchVO;
import com.dbnt.kcscbackend.admin.standardResearch.model.UpdateStandardResearchVO;
import com.dbnt.kcscbackend.auth.entity.LoginVO;
import com.dbnt.kcscbackend.commonCode.repository.TnCmtOrgRepository;
import com.dbnt.kcscbackend.config.common.ResponseCode;
import com.dbnt.kcscbackend.config.common.ResultVO;
import lombok.RequiredArgsConstructor;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service("adminCommitteeCodeManagementService")
@RequiredArgsConstructor
public class AdminCommitteeCodeManagementServiceImpl extends EgovAbstractServiceImpl implements AdminCommitteeCodeManagementService {

    private final TnCmtOrgRepository tnCmtOrgRepository;

    @Override
    public ResultVO createCommitteeCodeManagement(ResultVO resultVO, HttpServletRequest request, LoginVO user, MultipartHttpServletRequest multiRequest, CreateStandardResearchVO createStandardResearchVO) throws Exception {
        return null;
    }

    @Override
    public ResultVO getCommitteeCodeManagement(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long upCmtSeq, String cmtType) throws Exception {

        System.out.println(
                "\n--------------------------------------------------------------\n" +
                        request.getRequestURI() + " IN:" +
                        "\n--------------------------------------------------------------\n" +
                        "user.getEmail():" + "\n" +
                        user.getEmail() + "\n" +
                        "\n--------------------------------------------------------------\n"
        );

        List<Map<String, Object>> list = tnCmtOrgRepository.findByUseYnAndUpCmtSeqAndCmtTypeOrderByCmtOrder("Y", upCmtSeq, cmtType).stream()
                .map(item -> {
                    Map<String, Object> returnMap = new HashMap<>();
                    returnMap.put("orgId",      item.getCmtSeq());
                    returnMap.put("orgNm",      item.getCmtNm());
                    returnMap.put("orgDesc",    item.getCmtDesc());
                    return returnMap;
                })
                .collect(Collectors.toList());

        Map<String, Object> dto = new HashMap<String, Object>();
        dto.put("list", list);
        resultVO.setResult(dto);
        resultVO.setResultCode(ResponseCode.SUCCESS.getCode());
        resultVO.setResultMessage(ResponseCode.SUCCESS.getMessage());

        return resultVO;
    }

    @Override
    public ResultVO setCommitteeCodeManagement(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdateStandardResearchVO updateStandardResearchVO, Long popupId) throws Exception {
        return null;
    }

    @Override
    public ResultVO deleteCommitteeCodeManagement(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception {
        return null;
    }
}
