package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import org.qinan.safetyeval.client.dto.PageResponse;
import org.qinan.safetyeval.client.dto.SingleResponse;
import io.swagger.annotations.ApiOperation;
import org.qinan.safetyeval.client.api.QualFilingChangeApi;
import org.qinan.safetyeval.client.co.QualFilingChangeCO;
import org.qinan.safetyeval.client.dto.QualFilingChangeAddCmd;
import org.qinan.safetyeval.client.dto.QualFilingChangeModifyCmd;
import org.qinan.safetyeval.client.dto.QualFilingChangePageQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

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

    @Resource
    private QualFilingChangeApi qualFilingChangeApi;

    @ApiOperation("新增备案变更")
    @PostMapping("/save")
    public SingleResponse<QualFilingChangeCO> add(@Validated @RequestBody QualFilingChangeAddCmd cmd) {
        return qualFilingChangeApi.add(cmd);
    }

    @ApiOperation("查询备案变更详情")
    @GetMapping("/get")
    public SingleResponse<QualFilingChangeCO> get(@RequestParam Long id) {
        return qualFilingChangeApi.get(id);
    }

    @ApiOperation("修改备案变更")
    @PostMapping("/modify")
    public SingleResponse<QualFilingChangeCO> modify(@Validated @RequestBody QualFilingChangeModifyCmd cmd) {
        return qualFilingChangeApi.modify(cmd);
    }

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

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

    @ApiOperation("发起备案变更（克隆草稿）")
    @PostMapping("/start")
    public SingleResponse<Long> start(@RequestParam Long originFilingId) {
        return qualFilingChangeApi.start(originFilingId);
    }

    @ApiOperation("提交备案变更")
    @PostMapping("/submit")
    public SingleResponse<Void> submit(@Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingChangeSubmitCmd cmd) {
        return qualFilingChangeApi.submit(cmd);
    }

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

    @ApiOperation("变更审核通过")
    @PostMapping("/approve")
    public SingleResponse<Void> approve(@RequestParam Long changeId) {
        return qualFilingChangeApi.approve(changeId);
    }

    @ApiOperation("变更审核打回")
    @PostMapping("/reject")
    public SingleResponse<Void> reject(@Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingRejectCmd cmd) {
        return qualFilingChangeApi.reject(cmd);
    }
}
