package es.uv.saic.web;

import java.math.BigInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import es.uv.saic.domain.InstanciaTasca;
import es.uv.saic.domain.Plantilla;
import es.uv.saic.dto.PdfDTO;
import es.uv.saic.service.PlantillaService;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


@RestController
public class PlantillaController {
    @Autowired
    private PlantillaService ps;

    @PostMapping("/toPDF")
    public ResponseEntity<?> toPDF(@RequestBody PdfDTO pdfDTO) {
        try {
            byte[] pdf = ps.toPDF(pdfDTO.getContent(), pdfDTO.getIdtascai());  
            return (pdf != null && pdf.length != 0) ? ResponseEntity.ok(pdf) : ResponseEntity.badRequest().body("El pdf esta vacio o es null");
        } catch (Exception e) {
             e.printStackTrace();
            return ResponseEntity.badRequest().body("Error al pdf:" +  e.getMessage());
        }
    }
    
    // @PostMapping("/plantilla/{id}")
    // public ResponseEntity<?> findByID(@PathVariable BigInteger idPlantilla) {
    //     try {
    //         InstanciaTasca plantilla = ps.findById(idPlantilla);
            
    //     } catch (Exception e) {
    //         // TODO: handle exception
    //     }
        
    //     return entity;
    // }
    
    
}
