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.KamarDao;
import com.jasamedika.medifirst2000.dao.MapKebutuhanSaranaToKamarDao;
import com.jasamedika.medifirst2000.dao.RuanganDao;
import com.jasamedika.medifirst2000.dto.MapKebutuhanSaranaToKamarDto;
import com.jasamedika.medifirst2000.entities.Kamar;
import com.jasamedika.medifirst2000.entities.MapKebutuhanSaranaToKamar;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.service.MapKebutuhanSaranaToKamarService;
import com.jasamedika.medifirst2000.util.CommonUtil;

@Service("MapKebutuhanSaranaToKamarService")
public class MapKebutuhanSaranaToKamarServiceImpl implements MapKebutuhanSaranaToKamarService {
	@Autowired
	private MapKebutuhanSaranaToKamarDao mapKebutuhanSaranaToRuanganDao;
	
	@Autowired
	private KamarDao kamarDao;

	@Override
	public Map<String, Object> save(MapKebutuhanSaranaToKamarDto dto) {
		Map<String, Object> result = new HashMap<>();
		
		MapKebutuhanSaranaToKamar mksr = new MapKebutuhanSaranaToKamar();
		
		Kamar kamar = kamarDao.findOne(dto.getKamarId());
		mksr.setId(dto.getId());
		mksr.setKamar(kamar);
		mksr.setNamaExternal(dto.getNamaExternal());
		mksr.setSatuan(dto.getSatuan());
		mksr.setJumlah(dto.getJumlah());
		mksr.setHarga(dto.getHarga());
		mksr.setStatusEnabled(dto.getStatusEnabled());
		
		MapKebutuhanSaranaToKamar mksrResult = mapKebutuhanSaranaToRuanganDao.save(mksr);
		
		if(CommonUtil.isNotNullOrEmpty(mksrResult)) {
			result.put("id", mksrResult.getId());
		}
		
		
		return result;
	}

	@Override
	public Map<String, Object> getDataAll(Integer idKamar) {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.mapKebutuhanSaranaToRuanganDao.getAll(idKamar));
		return result;
	}

	@Override
	public Map<String, Object> getDataById(Integer id) {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.mapKebutuhanSaranaToRuanganDao.getDataById(id));
		return result;
	}

}
