package com.jasamedika.medifirst2000.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.dto.MapAlatToProdukToBhpDto;
import com.jasamedika.medifirst2000.service.MappingBahanToMesinService;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.MapAlatToProdukToBhpVO;

@RestController
@RequestMapping(value="/map-bahan-to-mesin")
public class MappingBahanToMesinController extends LocaleController<MapAlatToProdukToBhpVO>{
	@Autowired
	private MappingBahanToMesinService mappingBahanToMesinService;
	
	@RequestMapping(value="/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String,Object>>> save(@RequestBody List<MapAlatToProdukToBhpDto> dtos,
			HttpServletRequest request) {
		List<Map<String,Object>> result = mappingBahanToMesinService.saveMappingBahanToMesin(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> get(
			@RequestParam(value="idMappingBahanToMesin", required = true) Integer idMappingBahanToMesin,
			HttpServletRequest request) {
		Map<String, Object> result = mappingBahanToMesinService.getById(idMappingBahanToMesin);
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAll(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.getAll();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-all-mesin-cuci", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllMesinCuci(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findMesinCuci();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-all-proses-cuci", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllProcessCuci(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findProsesCuci();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-kapasitas-mesin-cuci", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getKapasitasMesinCuci(
			@RequestParam(value="alatId", required = true) Integer alatId,
			HttpServletRequest request) {
		Map<String, Object> result = mappingBahanToMesinService.findKapasitasMesinCuci(alatId);
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-all-bahan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getKomponenHargaByJenis(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findBahanCuci();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-satuan-bahan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getSatuanBahan(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findSatuanBahan();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}
	
	@RequestMapping(value="/get-all-proses-cuci-cuci", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllProcessCuciCuci(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findProsesCuciCuci();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value="/get-all-proses-cuci-bilas", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllProcessCuciBilas(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findProsesCuciBilas();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}
	
	@RequestMapping(value="/get-all-proses-cuci-kering", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllProcessCuciKering(
			HttpServletRequest request) {
		List<Map<String, Object>> result = mappingBahanToMesinService.findProsesCuciKering();
		
		if (result!=null) {
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
		}
		return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

}
