package com.nisum.myteam.controller;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.exception.handler.ResponseDetails;
import com.nisum.myteam.model.Designation;
import com.nisum.myteam.service.IDesignationService;
import com.nisum.myteam.service.impl.DesignationService;

@RestController
public class DesignationController {

	@Autowired
	IDesignationService designationService;

	// @RequestMapping(value = "/getAllDesignations"
	@RequestMapping(value = "/employees/designations/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<?> getAllDesignations(HttpServletRequest request) throws MyTeamException {
		List<String> designations = designationService.getAllDesignations().stream()
				.filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())).map(Designation::getDesignationName).sorted()
				.collect(Collectors.toList());
		
		ResponseDetails getRespDetails = new ResponseDetails(new Date(), 908, "Retrieved Designations successfully",
				"Designations list", designations, request.getRequestURI(), "Employee Designation Details", null);
		return new ResponseEntity<>(getRespDetails, HttpStatus.OK);
	}

}
