package com.jasamedika.medifirst2000.controller;

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.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.notification.antrian.InfoTambahanAntrian;
import com.jasamedika.medifirst2000.util.rest.RestUtil;


/**
 *  @author Syamsu
*/

@RestController
@RequestMapping({"/test-tanpa-auth/info-tambahan-antrian", "/info-tambahan-antrian"})
public class InfoTambahanAntrianController {

	@Autowired
	InfoTambahanAntrian infoAntrian;
	
	@RequestMapping(value="/kirim-pesan", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> kirimPesankeLayar(@RequestParam("pesan") String pesan, @RequestParam("targetlayar") String targetlayar){
		try{
			infoAntrian.kirimPesan(pesan, targetlayar);		
			return RestUtil.getJsonResponse("Pesan berhasil terkirim", HttpStatus.OK);
		}catch(Exception e){
			return RestUtil.getJsonResponse("Pesan gagal terkirim penyebab " + e.getMessage(), HttpStatus.BAD_REQUEST);
		}
	}
	
	@RequestMapping(value="/jenis-total-antrian", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> tambahTotalPerJenisAntrian(@RequestParam("label") String label, 
			@RequestParam("tipe") String tipe, @RequestParam("total") Integer total, 
			@RequestParam("hapus") boolean hapus,
			@RequestParam("targetlayar") String targetlayar){
		try{
			infoAntrian.kirimJumlahAntrian(label, tipe, String.valueOf(total), hapus,  targetlayar);		
			return RestUtil.getJsonResponse("Total antrian berhasil diinfokan", HttpStatus.OK);
		}catch(Exception e){
			return RestUtil.getJsonResponse("Total antrian gagal diinfokan penyebab " + e.getMessage(), HttpStatus.BAD_REQUEST);
		}
	}
			
}
