package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
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.jasamedika.medifirst2000.dao.CekListGedungBangunanDao;
import com.jasamedika.medifirst2000.service.CekListGedungBangunanService;
import com.jasamedika.medifirst2000.util.CommonUtil;

@Service("CekListGedungBangunanService")
public class CekListGedungBangunanServiceImpl implements CekListGedungBangunanService {
	@Autowired
	private CekListGedungBangunanDao cekListGedungBangunanDao;

	@Override
	public Map<String, Object> getCekListGedungBangunan() {
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> listData = new ArrayList<>();
		
		try {
			Map<String, Object> dataParent = new HashMap<>();
			List<Map<String, Object>> parentList = new ArrayList<>();
			List<Map<String, Object>> parent = this.cekListGedungBangunanDao.getCekListGedungBangunanParent();
			for(Map<String, Object> data:parent){
				if(CommonUtil.isNotNullOrEmpty(data)){
					Map<String, Object> tempMap = new HashMap<>();
					List<Map<String, Object>> child = this.cekListGedungBangunanDao.getCekListGedungBangunanChild((Integer)data.get("id"));
					tempMap.put("id", data.get("id"));
					tempMap.put("name", data.get("namaExternal"));
					tempMap.put("detail", child);
					parentList.add(tempMap);
				}
			}
			dataParent.put("data", parentList);
			listData.add(dataParent);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		result.put("loadData", listData);

		return result;
	}

}
