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.qinan.safetyeval.infrastructure.dataobject.base.Req;
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("创建资质备案草稿")
    @PostMapping("/draft")
    public SingleResponse<QualFilingCO> draft(
            @ApiParam("申请类型编码(1资质备案申请3已备案资质管理)") @RequestParam(required = false) Integer applyTypeCode) {
        return qualFilingApi.draft(applyTypeCode);
    }

    @ApiOperation("暂存资质备案基本信息")
    @PostMapping("/save-draft")
    public SingleResponse<QualFilingCO> saveDraft(@Validated @RequestBody QualFilingModifyCmd cmd) {
        return qualFilingApi.saveDraft(cmd);
    }

    @ApiOperation("创建已备案资质管理草稿")
    @PostMapping("/filed/draft")
    public SingleResponse<QualFilingCO> filedDraft() {
        return qualFilingApi.filedDraft();
    }

    @ApiOperation("提交资质备案申请")
    @PostMapping("/submit")
    public SingleResponse<QualFilingCO> submit(@ApiParam("主键ID") @RequestParam String id) {
        return qualFilingApi.submit(Long.parseLong(id));
    }

    @ApiOperation("上传备案主附件")
    @PostMapping("/upload-attachment")
    public SingleResponse<QualFilingCO> uploadAttachment(@Validated @RequestBody QualFilingAttachmentUploadCmd cmd) {
        return qualFilingApi.uploadAttachment(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") @RequestBody Req<Long> req) {
        return qualFilingApi.delete(req.getData());
    }

    @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);
    }

}
