package com.jasamedika.medifirst2000.service.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.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.IpsrsTagihanBusinessCenterDao;
import com.jasamedika.medifirst2000.entities.IpsrsKapasitasJenisPemakaian;
import com.jasamedika.medifirst2000.entities.IpsrsTagihanBusinessCenter;
import com.jasamedika.medifirst2000.entities.Rekanan;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.service.IpsrsTagihanBusinessCenterService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.IpsrsKapasitasJenisPemakaianVO;
import com.jasamedika.medifirst2000.vo.IpsrsTagihanBusinessCenterVO;
import com.jasamedika.medifirst2000.vo.RekananVO;
import com.jasamedika.medifirst2000.vo.RuanganVO;

@Service("ipsrsTagihanBusinessCenterService")
public class IpsrsTagihanBusinessCenterServiceImpl implements IpsrsTagihanBusinessCenterService{

	@Autowired
	private IpsrsTagihanBusinessCenterDao ipsrsTagihanBusinessCenterDao;
	
	@Autowired
	private BaseConverterImpl <IpsrsTagihanBusinessCenterVO, IpsrsTagihanBusinessCenter> ipsrsTagihanBusinessCenterConverter;
	
	@Autowired
	private BaseConverterImpl <RekananVO, Rekanan> ruanganConverter;
	
	@Autowired
	private BaseConverterImpl <IpsrsKapasitasJenisPemakaianVO, IpsrsKapasitasJenisPemakaian> ipsrsKapasitasJenisPemakaianConverter;
	
	
	@Override
	public Map<String, Object> getRuanganTagihanBusinessCenter(){
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> listRuangan = ipsrsTagihanBusinessCenterDao.getRuanganTagihanBusinessCenter();
		result.put("listRuangan", listRuangan);
		return result;
	}
	
	@Override
	public Map<String, Object> getJenisPemakaianBusinessCenter(){
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> jenisPemakaian = ipsrsTagihanBusinessCenterDao.getJenisPemakaianBusinessCenter();
		result.put("jenisPemakaian", jenisPemakaian);
		return result;
	}
	
	@Override
	public Map<String, Object> getKapasitasJenisPemakaianBusinessCenter(Integer id){
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> kapasitasJenisPemakaian = ipsrsTagihanBusinessCenterDao.getKapasitasJenisPemakaianBusinessCenter(id);
		result.put("kapasitasJenisPemakaian", kapasitasJenisPemakaian);
		return result;
	}
	
	@Override
	public Map<String, Object> saveTagihanBusinessCenter(IpsrsTagihanBusinessCenterVO vo){
		Map<String, Object> result = new HashMap<>();
		IpsrsTagihanBusinessCenter ipsrsTagihanBusinessCenter = new IpsrsTagihanBusinessCenter();
		if(CommonUtil.isNotNullOrEmpty(vo)){
			ipsrsTagihanBusinessCenter = ipsrsTagihanBusinessCenterConverter.transferVOToModel(vo, new IpsrsTagihanBusinessCenter());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getIpsrsKapasitasJenisPemakaian())){
			ipsrsTagihanBusinessCenter.setIpsrsKapasitasJenisPemakaian(ipsrsKapasitasJenisPemakaianConverter.transferVOToModel(vo.getIpsrsKapasitasJenisPemakaian(), new IpsrsKapasitasJenisPemakaian()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getRuangan())){
			ipsrsTagihanBusinessCenter.setRuangan(ruanganConverter.transferVOToModel(vo.getRuangan(), new Rekanan()));
		}
		if(CommonUtil.isNotNullOrEmpty(ipsrsTagihanBusinessCenter)){
			IpsrsTagihanBusinessCenter ipsrsTagihanBusinessCenterResult = ipsrsTagihanBusinessCenterDao.save(ipsrsTagihanBusinessCenter);
			result.put("noRec", ipsrsTagihanBusinessCenterResult.noRec);
		}		
		return result;
	}
	
	@Override
	public Map<String, Object> getAllTagihanBusinessCenter(){
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> listTagihanBusinessCenter = ipsrsTagihanBusinessCenterDao.getAllTagihanBusinessCenter();
		result.put("listTagihanBusinessCenter", listTagihanBusinessCenter);
		return result;
	}
	
	@Override
	public boolean deleteTagihanBusinessCenter(String noRec){
		IpsrsTagihanBusinessCenter ipsrsTagihanBusinessCenter = new IpsrsTagihanBusinessCenter();
		if(CommonUtil.isNotNullOrEmpty(noRec)){
			ipsrsTagihanBusinessCenter = ipsrsTagihanBusinessCenterDao.findOne(noRec);
			ipsrsTagihanBusinessCenterDao.delete(ipsrsTagihanBusinessCenter);
			return true;
		} else{
			return false;
		}
	}
	
	@Override
	public Map<String, Object> findTagihanBusinessCenterByPeriode(String periodeAwal, String periodeAkhir, Integer id){
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> ipsrsTagihanBusinessCenter = 
				ipsrsTagihanBusinessCenterDao.findTagihanBusinessCenterByPeriode(periodeAwal, periodeAkhir, id);
		result.put("ipsrsTagihanBusinessCenter", ipsrsTagihanBusinessCenter);
		return result;
	}
}
