package com.nisum.mytime.controller;

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

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.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Designation;
import com.nisum.mytime.service.impl.DesignationService;

@RestController
public class DesignationController {

	@Autowired
	DesignationService designationService;

	// @RequestMapping(value = "/getAllDesignations", method =
	// RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = "/employees/designations/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<String>> getAllDesignations() throws MyTimeException {
		List<String> designations = designationService.getAllDesignations().stream()
				.filter(e -> "Y".equalsIgnoreCase(e.getActiveStatus())).map(Designation::getDesignationName).sorted()
				.collect(Collectors.toList());
		return new ResponseEntity<>(designations, HttpStatus.OK);
	}

}
