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

import com.madeu.constants.Constants;
import com.madeu.dao.mobile.mobilemembership.MobileMembershipSqlMapDAO;
import com.madeu.service.mobile.mobilemembership.MobileMembershipService;
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("MobileMembershipService")
public class MobileMembershipServiceImpl implements MobileMembershipService {
    @Autowired
    private MobileMembershipSqlMapDAO mobileMembershipSqlMapDAO;

    /**
     * 멤버십 잔액 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectTotalMembershipBalance(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("MobileMembershipServiceImpl selectTotalMembershipBalance START");

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

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

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

        try{
            boolean check  = true;

            if(true == check){
                listMap = mobileMembershipSqlMapDAO.selectTotalMembershipBalance(paramMap);

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

    /**
     * 멤버십 사용내역 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipUse(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("MobileMembershipServiceImpl selectListMembershipUse 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 = mobileMembershipSqlMapDAO.selectListMembershipUseCount(paramMap);
                int totalCount =Integer.parseInt(String.valueOf(totalCountListMap.get(0)));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = mobileMembershipSqlMapDAO.selectListMembershipUse(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("MobileMembershipServiceImpl selectListMembershipUse END");
        return map;
    }

    /**
     * 멤버십 충전내역 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipCharge(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("MobileMembershipServiceImpl selectListMembershipCharge 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 = mobileMembershipSqlMapDAO.selectListMembershipChargeCount(paramMap);
                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0)));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = mobileMembershipSqlMapDAO.selectListMembershipCharge(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("MobileMembershipServiceImpl selectListMembershipCharge END");
        return map;
    }
}
