package com.nisum.myteam.controller;

import java.util.List;

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.PathVariable;
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.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Billing;
import com.nisum.myteam.service.IBillingService;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class BillingController {

	@Autowired
	private IBillingService billingService;

	// @RequestMapping(value = "/addEmployeeBilling"
	@RequestMapping(value = "/billing", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Billing> addEmployeeBilling(@RequestBody Billing billing,
			@RequestParam(value = "loginEmpId") String loginEmpId) throws MyTeamException {
		Billing billingList = billingService.addBilling(billing, loginEmpId);

		return new ResponseEntity<>(billingList, HttpStatus.OK);
	}

	// @RequestMapping(value = "/updateEmployeeBilling",
	@RequestMapping(value = "/billing", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Billing> updateEmployeeBilling(@RequestBody Billing billing,
			@RequestParam(value = "loginEmpId") String loginEmpId) throws MyTeamException {
		Billing billingList = billingService.updateBilling(billing, loginEmpId);
		return new ResponseEntity<>(billingList, HttpStatus.OK);
	}

	// @RequestMapping(value = "/deleteEmployeeBilling"
	@RequestMapping(value = "/billing", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Billing> deleteEmployeeBilling(@RequestBody Billing billing) throws MyTeamException {
		billingService.deleteBilling(billing);
		return new ResponseEntity<>(null, HttpStatus.OK);
	}

	// @RequestMapping(value = "/getEmployeeBillingDetailsAll"
	@RequestMapping(value = "/billing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Billing>> getAllBillingsForEmployee(@RequestParam("employeeId") String employeeId)
			throws MyTeamException {
		List<Billing> billingList = billingService.getBillingsForEmployee(employeeId);
		return new ResponseEntity<>(billingList, HttpStatus.OK);
	}

	// @RequestMapping(value = "/getEmployeeBillingDetails"
	@RequestMapping(value = "/billing/project/{projectId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Billing>> getBillingsForProject(@PathVariable("projectId") String projectId,
			@RequestParam("employeeId") String employeeId) throws MyTeamException {
		List<Billing> billingList = billingService.getBillingsForProject(employeeId, projectId);
		return new ResponseEntity<>(billingList, HttpStatus.OK);
	}

}
