/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package io.gmss.fiscad.controllers.report;

import io.gmss.fiscad.enums.FormatRapport;
import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad;
import io.gmss.fiscad.repositories.infocad.parametre.BlocRepository;
import io.gmss.fiscad.repositories.infocad.parametre.StructureRepository;
import io.gmss.fiscad.service.ReportService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


/**
 * @author AKAKPO Aurince
 */
@RestController
@RequestMapping(value = "/api/rapport", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "bearer")
@Tag(name = "Report")
@CrossOrigin(origins = "*")
public class ReportingController {
    private final ReportService reportService;

    private final BlocRepository blocRepository;
    private final StructureRepository structureRepository;
    private static final Logger logger = LoggerFactory.getLogger(ReportingController.class);

    public ReportingController(ReportService reportService, BlocRepository blocRepository, StructureRepository structureRepository) {
        this.reportService = reportService;
        this.blocRepository = blocRepository;
        this.structureRepository = structureRepository;
    }


    @GetMapping("/structure/blocs/{formatRapport}/{structureId}")
    public void imprimerBlocsParStructure(HttpServletResponse response, @PathVariable FormatRapport formatRapport, @PathVariable Long structureId) {
        try {
            reportService.imprimerBlocsStructure(response, formatRapport, structureId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @GetMapping("/bloc/enquetes/{formatRapport}/{blocId}")
    public void imprimerEnqueteParBloc(HttpServletResponse response, @PathVariable FormatRapport formatRapport, @PathVariable Long blocId) {
        try {
            reportService.imprimerEnqueteParBloc(response, formatRapport, blocId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/filtre/enquetes/{formatRapport}")
    public void imprimerEnqueteParFiltre(HttpServletResponse response, @RequestBody FiltreEnquetePayLoad filtreEnquetePayLoad, @PathVariable FormatRapport formatRapport) {
        try {
            reportService.imprimerEnqueteParFiltre(response, filtreEnquetePayLoad, formatRapport);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}