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.QualFilingChangeApi;
import org.qinan.safetyeval.client.co.QualFilingChangeAggregationCO;
import org.qinan.safetyeval.client.co.QualFilingChangeCO;
import org.qinan.safetyeval.client.co.QualFilingChangeComplianceCheckResultCO;
import org.qinan.safetyeval.client.dto.*;
import org.qinan.safetyeval.infrastructure.utils.RequestHandlerUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 备案变更适配层（Controller）
 *
 * @author safety-eval
 */
@Api(tags = "备案变更管理")
@RestController
@RequestMapping("/safetyEval/qual-filing-change")
public class QualFilingChangeController {

    @Resource
    private QualFilingChangeApi qualFilingChangeApi;


    @ApiOperation("删除备案变更")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingChangeApi.delete(id);
    }

    @ApiOperation("分页查询备案变更-监管端")
    @GetMapping("/page")
    public PageResponse<QualFilingChangeCO> page(@Validated QualFilingChangePageQuery query) {
        return qualFilingChangeApi.page(query);
    }

    @ApiOperation("分页查询备案变更-机构端")
    @GetMapping("/org/page")
    public PageResponse<QualFilingChangeCO> orgPage(@Validated QualFilingChangePageQuery query) {
        Long orgId = RequestHandlerUtil.getOrgId();
        query.setOrgId(orgId);
        return qualFilingChangeApi.page(query);
    }


    @ApiOperation("备案变更历史")
    @GetMapping("/history")
    public SingleResponse<org.qinan.safetyeval.client.co.QualFilingChangeHistoryCO> history(
            @ApiParam("备案申请id") @RequestParam Long filingId) {
        return qualFilingChangeApi.history(filingId);
    }


    @ApiOperation("聚合新增or编辑资质备案变更申请")
    @PostMapping("/aggregationSaveOrEdit")
    public SingleResponse<QualFilingChangeCO> aggregationSaveOrEdit(@RequestBody AggregationSaveOrEditQualFilingChangeCmd cmd) {
        return qualFilingChangeApi.aggregationSaveOrEdit(cmd);
    }

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

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

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