package com.markbudai.openfleet.controller;

import com.markbudai.openfleet.model.*;
import com.markbudai.openfleet.pojo.Badge;
import com.markbudai.openfleet.services.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.util.*;

/**
 * Created by Mark on 2017. 04. 29..
 */
@Controller
@RequestMapping("/api")
public class ApiController {

    private static Logger logger = LoggerFactory.getLogger(ApiController.class);

    private TransferCostService provider;
    private TractorService tractorService;
    private TrailerService trailerService;
    private EmployeeService employeeService;
    private LocationService locationService;
    private TransportService transportService;
    private PaymentService paymentService;

    @Autowired
    public ApiController(TractorService tractorService, TrailerService trailerService,
                         EmployeeService employeeService, LocationService locationService,
                         TransportService transportService, PaymentService paymentService){
        this.employeeService = employeeService;
        this.trailerService = trailerService;
        this.tractorService = tractorService;
        this.locationService = locationService;
        this.transportService = transportService;
        this.paymentService = paymentService;

    }

    @RequestMapping(value = "/tractors", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody List<Tractor> tractors(){
        return tractorService.getAllTractors();
    }

    @RequestMapping(value = "/badges", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody Badge badge(){
        Badge badges = new Badge();
        badges.setLocation_count(this.allLocations().size());
        badges.setEmployee_count(this.employees().size());
        badges.setTrailer_count(this.trailers().size());
        badges.setTractor_count(this.tractors().size());
        badges.setJob_count(this.transportService.getAllTransports().size());
        return badges;
    }

    @RequestMapping(value = "/trailers", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody List<Trailer> trailers(){
        return trailerService.getAllTrailers();
    }

    @RequestMapping(value = "/employees", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody List<Employee> employees(){
        return employeeService.getAllEmployees();
    }


    @RequestMapping(value = "/locations", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody List<Location> allLocations(){
        List<Location> locations = locationService.getAllLocations();
        return locations;
    }

    @RequestMapping(value = "/employeePerformance", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody  List<Pair<String,Pair<Double,Double>>> getDriversPerformance(){
        return paymentService.getDriversPerformance(LocalDate.now().getYear(), LocalDate.now().getMonth().getValue());
    }




}

@@ -810,50 +810,8 @@
 );%0A%0A
-    private TransferCostService provider;%0A
     
@@ -1081,23 +1081,8 @@
     
-@Autowired%0A    
 publ
@@ -1097,16 +1097,70 @@
 ntroller
+()%7B%7D%0A%0A    @Autowired%0A    public void setTractorService
 (Tractor
@@ -1185,24 +1185,38 @@
 vice
-, Traile
+)%7B%0A        this.tracto
 rService
  tra
@@ -1211,31 +1211,33 @@
 rService
+ =
  tra
-ile
+cto
 rService
 ,%0A      
@@ -1232,100 +1232,97 @@
 vice
-,
+;
 %0A    
+%7D%0A%0A
     
-                 EmployeeService employeeService, LocationService location
+@Autowired%0A    public void setTrailerService(TrailerService trailer
 Service
-,
+)%7B
 %0A   
@@ -1330,82 +1330,127 @@
     
-  
+this.trailerService = trailerService;%0A
     
+%7D%0A%0A
     
-       TransportService transportService, PaymentService payment
+@Autowired%0A    public void setEmployeeService(EmployeeService employee
 Serv
@@ -1511,49 +1511,94 @@
     
+%7D%0A%0A
     
-this.trailerService = trailer
+@Autowired%0A    public void setLocationService(LocationService location
 Service
-;
+)%7B
 %0A   
@@ -1599,39 +1599,40 @@
 )%7B%0A        this.
-tractor
+location
 Service = tracto
@@ -1617,39 +1617,40 @@
 cationService = 
-tractor
+location
 Service;%0A       
@@ -1650,51 +1650,97 @@
     
+%7D%0A%0A
     
-this.locationService = location
+@Autowired%0A    public void setTransportService(TransportService transport
 Service
-;
+)%7B
 %0A   
@@ -1782,24 +1782,112 @@
 ortService;%0A
+    %7D%0A%0A    @Autowired%0A    public void setPaymentService(PaymentService paymentService)%7B%0A
         this
@@ -1916,25 +1916,24 @@
 entService;%0A
-%0A
     %7D%0A%0A    @
@@ -3655,13 +3655,10 @@
 %0A    %7D%0A%0A
-%0A%0A%0A
 %7D%0A

Create setters for Dependency Injection