package com.fkzy.warn.controller;

import com.fkzy.warn.model.Report;
import com.fkzy.warn.model.params.PdfRequestParams;
import com.fkzy.warn.service.PdfService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangjing
 * @date 2026/01/13 10:40
 * @description
 */
@Api(tags = "生成报告相关")
@RestController
@RequestMapping("generateReport/")
@Slf4j
public class PdfController {
    @Autowired
    private PdfService pdfService;

    @PostMapping("download")
    public ResponseEntity<byte[]> generateReport(@RequestBody PdfRequestParams params) {
        byte[] pdfBytes = pdfService.generatePdfFromUrl(params.getUrl());

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "report.pdf");

        return ResponseEntity.ok()
            .headers(headers)
            .body(pdfBytes);
    }
}
