package com.madeu.service.mobile.mobileevent.impl;

import com.madeu.constants.Constants;
import com.madeu.dao.mobile.mobileevent.MobileEventSqlMapDAO;
import com.madeu.service.mobile.mobileevent.MobileEventService;
import com.madeu.util.ValidationCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service("MobileEventService")
public class MobileEventServiceImpl implements MobileEventService {
    @Autowired
    private MobileEventSqlMapDAO mobileEventSqlMapDAO;

    /**
     * 이벤트리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListEvent(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("MobileEventServiceImpl selectListAppEvent START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginUserId       :"+paramMap.get("loginUserId"));
        log.debug("exposedYn  :"+paramMap.get("exposedYn"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){

                paramMap.put("useYn", "Y");

                List<Map<String, Object>> totalCountListMap = mobileEventSqlMapDAO.selectListEventCount(paramMap);
                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = mobileEventSqlMapDAO.selectListEvent(paramMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("totalCount", totalCount);
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("MobileEventServiceImpl selectListAppEvent END");
        return map;
    }

    /**
     * 이벤트정보 상세 조회 (one)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectEvent(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("MobileEventServiceImpl selectEvent START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginUserId       :"+paramMap.get("loginUserId"));

        log.debug("muAppEventId          :"+paramMap.get("muAppEventId"));

        try{
            boolean check  = true;
            String muAppEventId    = String.valueOf(paramMap.get("muAppEventId"));

            if(true != ValidationCheckUtil.emptyCheck(muAppEventId)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","이벤트정보가 없습니다.");
            }

            if(true == check){
                List<Map<String, Object>> listMap = mobileEventSqlMapDAO.selectEvent(paramMap);

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("MobileEventServiceImpl selectEvent END");
        return map;
    }

}
