package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.utils.Response;

import cn.cslg.report.entity.ReviewHistory;

import cn.cslg.report.service.business.ReviewHistoryService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
@SuppressWarnings({"all"})
@Tag(name = "审查历史")
@RestController
@RequestMapping(Constants.REPORT_API + "/reviewHistory")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ReviewHistoryController {
    public final ReviewHistoryService reviewHistoryService;

    @RequestMapping(value = "/addReviewHistory", method = RequestMethod.POST)
    @Operation(summary = "增加审查历史")
    public String addReviewHistory(String jsons, List<MultipartFile> files) throws IOException {
        ReviewHistory reviewHistory = JSONObject.parseObject(jsons,ReviewHistory.class);
        return reviewHistoryService.addReviewHistory(reviewHistory, files);
    }

    @RequestMapping(value = "/updateReviewHistory", method = RequestMethod.POST)
    @Operation(summary = "修改审查历史")
    @Transactional(rollbackFor = Exception.class)
    public String updateReviewHistory(String jsons, List<MultipartFile> files) throws IOException {
        ReviewHistory reviewHistory = JSONObject.parseObject(jsons,ReviewHistory.class);
        Boolean flag = reviewHistoryService.updateReviewHistory(reviewHistory, files);
        if (flag) {
            return Response.success();
        }
        return Response.error();
    }
    @GetMapping(value = "/deleReviewHistory")
    @Operation(summary = "删除审查历史")
    public String deleReviewHistory(int id) throws IOException {
        return reviewHistoryService.deleteReviewHistory(id);
    }

    @PostMapping(value = "/queryReviewHistory")
    @Operation(summary = "查询审查历史")
    @Transactional(rollbackFor = Exception.class)
    public String queryReviewHistory(@RequestBody ReviewHistory reviewHistory) throws IOException {
        return reviewHistoryService.queryReviewHistory(reviewHistory);
    }


}
