package cd.casic.ci.api;

import cd.casic.ci.process.dto.req.aflManager.AflManagerReq;
import cd.casic.ci.process.dto.resp.aflManager.*;
import cd.casic.ci.process.process.service.aflManager.AflCrashesInfoService;
import cd.casic.ci.process.process.service.aflManager.AflInfoService;
import cd.casic.ci.process.process.service.aflManager.AflPlotInfoService;
import cd.casic.ci.process.process.service.aflManager.AflSeedInfoService;
import cd.casic.ci.process.util.SftpUploadUtil;
import cd.casic.framework.commons.pojo.CommonResult;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HopeLi
 * @version v1.0
 * @ClassName AflInfoController
 * @Date: 2025/7/1 9:03
 * @Description:
 */
@RestController
@RequestMapping("/aflManager")
public class AflManagerController {

    @Resource
    private AflInfoService aflInfoService;

    @Resource
    private AflCrashesInfoService aflCrashesInfoService;

    @Resource
    private AflSeedInfoService aflSeedInfoService;

    @Resource
    private AflPlotInfoService aflPlotInfoService;

    @PostMapping(path="/saveAflInfo")
    public CommonResult<String> saveAflInfo(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        String groupIdentifier = aflInfoService.saveAflInfo(req);

        return CommonResult.success(groupIdentifier);
    }


    @PostMapping(path="/findAflInfoNow")
    public CommonResult<AflInfoResp> findAflInfo(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        AflInfoResp resp = aflInfoService.findAflInfo(req);

        return CommonResult.success(resp);
    }


    @PostMapping(path="/findAflInfoListByHistory")
    public CommonResult<List<AflInfoResp>> findAflInfoListByHistory(@RequestBody @Valid AflManagerReq req){

        List<AflInfoResp> respList = aflInfoService.findAflInfoListByHistory(req);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/saveAflCrashesInfo")
    public CommonResult<String> saveAflCrashesInfo(@RequestBody @Valid AflManagerReq req){

        String groupIdentifier = aflCrashesInfoService.saveAflCrashesInfo(req);

        return CommonResult.success(groupIdentifier);
    }


    @PostMapping(path="/findCrashesCount")
    public CommonResult<AflCrashesResp> findCrashesCount(@RequestBody @Valid AflManagerReq req){

        AflCrashesResp resp = aflCrashesInfoService.findCrashesCount(req);

        return CommonResult.success(resp);
    }


    @PostMapping(path="/findCrashesNow")
    public CommonResult<List<AflCrashesInfoResp>> findCrashesNow(@RequestBody @Valid AflManagerReq req){

        List<AflCrashesInfoResp> respList = aflCrashesInfoService.findCrashesNow(req);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/findAflCrashesInfoListByHistory")
    public CommonResult<List<AflCrashesInfoResp>> findAflCrashesInfoListByHistory(@RequestBody @Valid AflManagerReq req){

        List<AflCrashesInfoResp> respList = aflCrashesInfoService.findAflCrashesInfoListByHistory(req);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/findSeedsCount")
    public CommonResult<List<SeedsCountResp>> findSeedsCount(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        List<SeedsCountResp> seedsCount = aflSeedInfoService.findSeedsCount(req);

        return CommonResult.success(seedsCount);
    }


    @PostMapping(path="/saveAflSeedInfo")
    public CommonResult<Void> saveAflSeedInfo(@RequestBody @Valid AflManagerReq req){

        aflSeedInfoService.saveAflSeedInfo(req);

        return CommonResult.success();
    }



    @PostMapping(path="/saveAflPlotInfo")
    public CommonResult<String> saveAflPlotInfo(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        String groupIdentifier = aflPlotInfoService.saveAflPlotInfo(req);

        return CommonResult.success(groupIdentifier);
    }


    @PostMapping(path="/findAflPlotInfoNow")
    public CommonResult<AflPlotInfoResp> findAflPlotInfoNow(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        AflPlotInfoResp resp = aflPlotInfoService.findAflPlotInfoNow(req);

        return CommonResult.success(resp);
    }


    @PostMapping(path="/findAflPlotInfoListByHistory")
    public CommonResult<List<AflPlotInfoResp>> findAflPlotInfoListByHistory(@RequestBody @Valid AflManagerReq req){

        List<AflPlotInfoResp> respList = aflPlotInfoService.findAflPlotInfoListByHistory(req);

        return CommonResult.success(respList);
    }


    @PostMapping(path="/findAflBaseInfoList")
    public CommonResult<AflBaseInfoResp> findAflBaseInfoList(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {

        AflBaseInfoResp resp = aflInfoService.findAflBaseInfoList(req);

        return CommonResult.success(resp);
    }
}
