package com.cslg.ppa.controller;

import com.cslg.ppa.common.core.auth.Response;
import com.cslg.ppa.common.core.base.Constants;
import com.cslg.ppa.dto.*;
import com.cslg.ppa.service.ReportService;
import com.cslg.ppa.vo.SelectAssoReportArticleVO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping(Constants.API_PPA + "/report")
@RestController
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ReportController {

    @Autowired
    private ReportService reportService;

    @Operation(summary = "查询报告列表")
    @PostMapping("/selectReportList")
    public String selectReportList(@RequestBody SelectReportListDTO vo) {
        return reportService.selectReportList(vo);
    }

    @Operation(summary = "查询报告详情")
    @PostMapping("/selectReportDetail")
    public String selectReportDetail(@RequestBody ReportIdDTO vo) {
        return reportService.selectReportDetail(vo);
    }

    @Operation(summary = "新增报告信息")
    @PostMapping("/addReport")
    public String addReport(@RequestBody ReportDTO vo) {
        Integer id = reportService.addReport(vo);
        return Response.success(id);
    }

    @Operation(summary = "编辑报告信息")
    @PostMapping("/editReport")
    public String editReport(@RequestBody ReportDTO vo) {
        Integer id = reportService.editReport(vo);
        return Response.success(id);
    }

    @Operation(summary = "删除报告")
    @PostMapping("/deleteReport")
    public String deleteReport(@RequestBody ReportIdDTO vo) {
        reportService.deleteReport(vo);
        return Response.success("删除成功");
    }

    @Operation(summary = "查询报告及关联资讯列表")
    @PostMapping("/selectAssoReportArticleList")
    public String selectAssoReportArticleList(@RequestBody SelectAssoReportArticleDTO vo) {
        List<SelectAssoReportArticleVO> articleVOS = reportService.selectAssoReportArticleList(vo);
        return Response.success(articleVOS);
    }

    @Operation(summary = "添加资讯到报告中")
    @PostMapping("/addArticleToReport")
    public String addArticleToReport(@RequestBody ReportDTO vo) {
        Integer id = reportService.addArticleToReport(vo);
        return Response.success(id);
    }

    @Operation(summary = "移除报告的关联资讯")
    @PostMapping("/removeAssoArticleReport")
    public String removeAssoArticleReport(@RequestBody AssoReportArticleIdDTO vo) {
        Integer id = reportService.removeAssoArticleReport(vo);
        return Response.success(id);
    }

    @Operation(summary = "导出报告信息")
    @GetMapping("/exportReport")
    public String exportReport(Integer reportId) {
        String guid = reportService.exportReport(reportId);
        return Response.success(guid);
    }

    @Operation(summary = "一键导出上个月报告信息")
    @GetMapping("/oneClickExport")
    public String oneClickExport() {
        String guid = reportService.oneClickExport();
        return Response.success(guid);
    }
}
