package com.nisum.mytime.controller;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.Location;
import com.nisum.mytime.service.impl.OrgLocationService;

@RestController
public class OrgLocationController {

	@Autowired
	OrgLocationService orgLocationService;
	private static final Logger logger = LoggerFactory.getLogger(OrgLocationController.class);

	// @RequestMapping(value = "/getLocations", method = RequestMethod.GET,
	// produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = "/employees/locations/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<String>> getLocations() throws MyTimeException {
		// System.out.println(" userService.getLocations()" +
		// orgLocationService.getLocations());
		List<String> locations = orgLocationService.getLocations().stream().filter(e -> (e.isActiveStatus() == true))
				.map(Location::getLocation).sorted().collect(Collectors.toList());
		logger.info("getLocations " + locations);
		return new ResponseEntity<>(locations, HttpStatus.OK);

	}
}
