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

import com.madeu.constants.Constants;

import com.madeu.dao.mobile.mobilesystem.MobileSystemSqlMapDAO;
import com.madeu.service.mobile.mobilesystem.MobileSystemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service("SystemService")
public class MobileSystemServiceImpl implements MobileSystemService {
	
	
	@Autowired
	private MobileSystemSqlMapDAO mobileSystemSqlMapDAO;
	
	/**
	 * 시스템 버전 정보를 가지고 온다. 
	 * phoneType, appType
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectSystemVersion(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("SystemServiceImpl selectSystemVersion START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("phoneType :"+paramMap.get("phoneType"));
		log.debug("modelName :"+paramMap.get("modelName"));
		
		try{
			
			boolean check  = true;
			
			if(null==paramMap.get("phoneType")||("").equals(paramMap.get("phoneType"))){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","폰 타입 정보가 없습니다.");
			}
			/*
			String modelName = String.valueOf(paramMap.get("modelName"));
			
			if(("iPhone 6 Plus").equals(modelName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("checkMessage", "해당 단말기 준비중입니다.");
				map.put("msgDesc","해당 단말기 준비중입니다.");
			}else if(("iPhone 6").equals(modelName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("checkMessage", "해당 단말기 준비중입니다.");
				map.put("msgDesc","해당 단말기 준비중입니다.");
			}
			*/
			if(check == true){
				
				List<Map<String, Object>> listMap = mobileSystemSqlMapDAO.selectSystemVersion(paramMap);
				
				if(listMap.size() == 1){
					
					String version = String.valueOf( listMap.get(0).get("version"));
					String checkYn = String.valueOf( listMap.get(0).get("checkYn"));
					
					map.put("version", version);
					
					if(("Y").equals(checkYn)){
						map.put("msgCode", Constants.FAIL);
						String checkMessage = String.valueOf( listMap.get(0).get("checkMessage"));
						map.put("checkMessage", checkMessage);
						map.put("msgDesc", checkMessage);
					}else{
						map.put("msgCode", Constants.OK);
					}
				}else{
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","버전 정보가 없습니다.");
				}
			}
		}catch(Exception e){
			e.printStackTrace();
            throw e;
		}
		
		log.debug("SystemServiceImpl selectSystemVersion END");
		return map;
	}

}
