package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.client.api.QualFilingApi;
import org.qinan.safetyeval.client.co.QualFilingCO;
import org.qinan.safetyeval.client.co.QualFilingComplianceCheckResultCO;
import org.qinan.safetyeval.client.co.QualFilingDetailCO;
import org.qinan.safetyeval.client.dto.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资质备案申请适配层（Controller）
 */
@Api(tags = "资质备案申请管理")
@RestController
@RequestMapping("/safetyEval/qual-filing")
public class QualFilingController {

    @Resource
    private QualFilingApi qualFilingApi;

    @ApiOperation("新增资质备案申请")
    @PostMapping("/save")
    public SingleResponse<QualFilingCO> add(@Validated @RequestBody QualFilingAddCmd cmd) {
        return qualFilingApi.add(cmd);
    }

    @ApiOperation("查询资质备案申请详情")
    @GetMapping("/get")
    public SingleResponse<QualFilingCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingApi.get(id);
    }

    @ApiOperation("修改资质备案申请")
    @PostMapping("/modify")
    public SingleResponse<QualFilingCO> modify(@Validated @RequestBody QualFilingModifyCmd cmd) {
        return qualFilingApi.modify(cmd);
    }


/////////////////////////////////////聚合接口
    @ApiOperation("聚合新增or编辑资质备案申请")
    @PostMapping("/aggregationSaveOrEdit")
    public SingleResponse<QualFilingCO> aggregationSaveOrEdit(@RequestBody AggregationSaveOrEditQualFilingCmd cmd) {
        return qualFilingApi.aggregationSaveOrEdit(cmd);
    }

    @ApiOperation("分页查询资质备案,已备案资质管理列表")
    @GetMapping("/page")
    public PageResponse<QualFilingCO> page(@Validated QualFilingPageQuery query) {
        return qualFilingApi.page(query);
    }

    @ApiOperation("审核")
    @PostMapping("/review")
    public SingleResponse<Void> review(@Validated @RequestBody QualFilingReviewAddCmd cmd) {
        qualFilingApi.review(cmd);
        return SingleResponse.success();
    }

    @ApiOperation("删除资质备案申请")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingApi.delete(id);
    }

    @ApiOperation("合规检查")
    @GetMapping("/compliance-check")
    public SingleResponse<List<QualFilingComplianceCheckResultCO>> complianceCheck(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingApi.complianceCheck(id);
    }

    @ApiOperation("备案详情（5步聚合）")
    @GetMapping("/detail")
    public SingleResponse<QualFilingDetailCO> detail(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingApi.detail(id);
    }

}
