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 io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.client.api.QualFilingCommitmentApi;
import org.qinan.safetyeval.client.co.QualFilingCommitmentCO;
import org.qinan.safetyeval.client.dto.QualFilingCommitmentAddCmd;
import org.qinan.safetyeval.client.dto.QualFilingCommitmentModifyCmd;
import org.qinan.safetyeval.client.dto.QualFilingCommitmentPageQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 法定代表人承诺书适配层（Controller）
 *
 * @author safety-eval
 */
@Api(tags = "法定代表人承诺书管理")
@RestController
@RequestMapping("/safetyEval/qual-filing-commitment")
public class QualFilingCommitmentController {

    @Resource
    private QualFilingCommitmentApi qualFilingCommitmentApi;

    @ApiOperation("新增法定代表人承诺书")
    @PostMapping("/save")
    public SingleResponse<QualFilingCommitmentCO> add(@Validated @RequestBody QualFilingCommitmentAddCmd cmd) {
        return qualFilingCommitmentApi.add(cmd);
    }

    @ApiOperation("查询法定代表人承诺书详情")
    @GetMapping("/get")
    public SingleResponse<QualFilingCommitmentCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingCommitmentApi.get(id);
    }

    @ApiOperation("修改法定代表人承诺书")
    @PostMapping("/modify")
    public SingleResponse<QualFilingCommitmentCO> modify(@Validated @RequestBody QualFilingCommitmentModifyCmd cmd) {
        return qualFilingCommitmentApi.modify(cmd);
    }

    @ApiOperation("删除法定代表人承诺书")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return qualFilingCommitmentApi.delete(id);
    }

    @ApiOperation("分页查询法定代表人承诺书")
    @GetMapping("/page")
    public PageResponse<QualFilingCommitmentCO> page(@Validated QualFilingCommitmentPageQuery query) {
        return qualFilingCommitmentApi.page(query);
    }

    @ApiOperation("保存或更新承诺书")
    @PostMapping("/save-or-update")
    public SingleResponse<QualFilingCommitmentCO> saveOrUpdate(@Validated @RequestBody QualFilingCommitmentModifyCmd cmd) {
        return qualFilingCommitmentApi.saveOrUpdate(cmd);
    }

    @ApiOperation("上传法定代表人签名")
    @PostMapping("/upload-signature")
    public SingleResponse<QualFilingCommitmentCO> uploadSignature(
            @Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingAttachmentUploadCmd cmd) {
        return qualFilingCommitmentApi.uploadSignature(cmd);
    }
}
