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.LitigationHistory;
import cn.cslg.report.entity.References;
import cn.cslg.report.service.business.ReferencesService;
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;

@Tag(name = "其他参考资料")
@RestController
@RequestMapping(Constants.REPORT_API + "/References")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@SuppressWarnings({"all"})
public class ReferencesController {
    public final ReferencesService referencesService;
    @RequestMapping(value = "/addReferences", method = RequestMethod.POST)
    @Operation(summary = "增加参考资料")
    public  String addReferences( String jsons, List<MultipartFile> files) throws IOException{
        References references = JSONObject.parseObject(jsons,References.class);
        return referencesService.addReferences(references,files);
    }
    @RequestMapping(value = "/updateReferences", method = RequestMethod.POST)
    @Operation(summary = "修改参考资料")
    @Transactional(rollbackFor = Exception.class)
    public String updateReferences( String jsons, List<MultipartFile> files)throws IOException{
        References references = JSONObject.parseObject(jsons,References.class);
        Boolean flag=referencesService.updateReferences(references,files);
        if (flag) {
            return Response.success();
        }
        return Response.error();

    }
    @GetMapping(value = "/deleReferences")
    @Operation(summary = "删除参考资料")
    public String deleReferences(int id)throws IOException{
        return referencesService.deleteReferences(id);
    }
    @PostMapping(value = "/queryReferences")
    @Operation(summary = "查询参考资料")
    @Transactional(rollbackFor = Exception.class)
    public String queryReferences(@RequestBody References references)throws IOException{
        return referencesService.queryReferences(references);
    }


}
