package es.uv.saic.web;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import es.uv.saic.feign.TascaClient;

@Controller
public class TascaController {
    
    @Autowired
    private TascaClient tc;

    @PostMapping("/search/evidences")
	public String getEvidencesByCenterTitulationYear(Model model, Authentication auth,
			@RequestParam(name="centers[]", required=false) List<Integer> centres,
			@RequestParam("years[]") List<Integer> cursos,
			@RequestParam("titulations[]") List<Integer> titulacions) throws IOException {	
		
        HashMap<String, Object> response =
                tc.getEvidencesByCenterTitulationYear(centres, cursos, titulacions);
        
		if (response == null) {
        	return "401";
		}

		return "components/selector_evidencies";
	}

    //NO se usa
	@PostMapping("/find/templates")
	public String findTemplates(Model model, Authentication auth, @RequestParam("procedure") Integer idProces, 
			@RequestParam("center") String idCentre, @RequestParam("titulation") String idTitulacio) throws IOException {	
		model.addAttribute("evs", tc.getEvidencesByProcedure(idProces));
		model.addAttribute("idCentre", idCentre);
		model.addAttribute("idTitulacio", idTitulacio);
		model.addAttribute("idProces", idProces);
		return "components/templates";
	}
}
