package com.ffii.lioner.modules.lioner.web;

import java.time.LocalDate;

import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ffii.lioner.modules.common.service.WordReportService;

@RestController
@RequestMapping("/report")
public class ReportController {
    
    private WordReportService wordReportService;

    public ReportController(WordReportService wordReportService) {
		this.wordReportService = wordReportService;
	}

    @RequestMapping(value = "/xmlTest", method = RequestMethod.GET)
	public ResponseEntity<Resource> download(@RequestParam(defaultValue = "false") boolean modified) throws Exception {

		byte[] reportResult = wordReportService.generateTestXMLFile();

        return ResponseEntity.ok()
                    .header("filename", "test_xml_report_" + LocalDate.now() + ".doc")
                    .body(new ByteArrayResource(reportResult));
	}
}
