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.OrderPelayananDao;
import com.jasamedika.medifirst2000.entities.OrderPelayanan;
import com.jasamedika.medifirst2000.service.DaftarOrderAmbulanceService;
import com.jasamedika.medifirst2000.util.CommonUtil;

@Service("DaftarOrderAmbulanceService")
public class DaftarOrderAmbulanceServiceImpl extends BaseVoServiceImpl implements DaftarOrderAmbulanceService {

	@Autowired
	private OrderPelayananDao orderPelayananDao;

	@Override
	public Map<String, Object> findDaftarOrderAmbulanceByPeriode(String periodeAwal, String periodeAkhir) {

		System.out.println("=======START FIND DAFTAR ORDER AMBULANCE BY PERIODE=======");
		Map<String, Object> result = new HashMap<String, Object>();
		List<OrderPelayanan> resultModel = orderPelayananDao.findDaftarOrderAmbulanceByPeriode(periodeAwal,
				periodeAkhir);
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("data", resultModel);
			result.put("dataFound", true);
		} else {
			result.put("dataFound", false);
		}
		System.out.println("=======END FIND DAFTAR ORDER AMBULANCE BY PERIODE=======");
		return result;
	}

	@Override
	public Map<String, Object> findDaftarOrderAmbulanceByNoOrder(String noOrder) {

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			System.out.println("=======START FIND DAFTAR ORDER AMBULANCE BY NO ORDER=======");
			List<OrderPelayanan> resultModel = orderPelayananDao.findDaftarOrderAmbulanceByNoOrder(noOrder);
			if (CommonUtil.isNotNullOrEmpty(resultModel)) {
				result.put("data", resultModel);
				result.put("dataFound", true);
			} else {
				result.put("dataFound", false);
			}
			System.out.println("=======END FIND DAFTAR ORDER AMBULANCE BY NO ORDER=======");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public Map<String, Object> getAllDaftarOrderAmbulance() {

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			System.out.println("==================START GET ALL ORDER AMBULANCE======================");
			List<OrderPelayanan> resultModel = orderPelayananDao.getAllDaftarOrderAmbulance();
			if (CommonUtil.isNotNullOrEmpty(resultModel)) {
				result.put("data", resultModel);
				result.put("dataFound", true);
			} else {
				result.put("dataFound", false);
			}
			System.out.println("==================END GET ALL ORDER AMBULANCE======================");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	@Override
	public Map<String, Object> findByPeriodeDanNoOrder(String noOrder, String periodeAwal, String periodeAkhir) {

		Map<String, Object> result = new HashMap<String, Object>();
		try {
			System.out.println("=======START FIND DAFTAR ORDER AMBULANCE BY PERIODE DAN NO ORDER=======");
			List<OrderPelayanan> resultModel = orderPelayananDao.findByPeriodeDanNoOrder(noOrder, periodeAwal,
					periodeAkhir);
			if (CommonUtil.isNotNullOrEmpty(resultModel)) {
				result.put("data", resultModel);
				result.put("dataFound", true);
			} else {
				result.put("dataFound", false);
			}
			System.out.println("=======END FIND DAFTAR ORDER AMBULANCE BY PERIODE DAN NO ORDER=======");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public Map<String, Object> findDaftarOrderAmbulanceByNoRec(String noRec) {

		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> resultModel = new ArrayList<>();
		try {
			System.out.println("=======START FIND DAFTAR ORDER AMBULANCE BY NO REC=======");
			List<Map<String, Object>> list = orderPelayananDao.getDaftarOrderAmbulanceByNoRec(noRec);
			for(Map<String, Object>item:list){
				item.put("petugas", this.orderPelayananDao.getPerawatAmbulanceByNoRec(noRec));
				resultModel.add(item);
			}
			
			if (CommonUtil.isNotNullOrEmpty(list)) {
				result.put("data", resultModel);
				//result.put("data", data);
				result.put("dataFound", true);
			} else {
				result.put("dataFound", false);
			}
			System.out.println("=======END FIND DAFTAR ORDER AMBULANCE BY NO REC=======");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
