package com.madeu.service.web.webmenu.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.madeu.constants.Constants;
import com.madeu.dao.web.webmenu.WebMenuSqlMapDAO;
import com.madeu.service.web.webmenu.WebMenuService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebMenuService")
public class WebMenuServiceImpl implements WebMenuService {
	
	@Autowired
	private WebMenuSqlMapDAO webMenuSqlMapDAO;
	
	/**
	 * 메뉴 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListMenu(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMenuServiceImpl selectListMenu START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("type                :"+paramMap.get("type"));
		log.debug("groupCode           :"+paramMap.get("groupCode"));

		try{
			boolean check  = true;

			String type       = String.valueOf(paramMap.get("type"));
			String groupCode  = String.valueOf(paramMap.get("groupCode"));
			
			if(true != ValidationCheckUtil.emptyCheck(type)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","유형 정보가 없습니다.");
			}
			else {
				if(("B").equals(type)) {
					if(true != ValidationCheckUtil.emptyCheck(groupCode)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","상위 메뉴 정보가 없습니다.");
					}
				}
			}
			
			if(true == check){
				List<Map<String, Object>> listMap = webMenuSqlMapDAO.selectListMenu(paramMap);

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

	/**
	 * 메뉴 코드 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectMenuCode(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMenuServiceImpl selectMenuCode START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		log.debug("menuName            :"+paramMap.get("menuName"));


		try{
			boolean check  = true;

			String menuName       = String.valueOf(paramMap.get("menuName"));

			if(true != ValidationCheckUtil.emptyCheck(menuName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","메뉴 정보가 없습니다.");
			}
			if(true == check){
				String menuCode = webMenuSqlMapDAO.selectMenuCode(paramMap);

				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("menuCode",menuCode);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMenuServiceImpl selectListMenu END");
		return map;
	}
}
