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.QualFilingMaterialApi;
import org.qinan.safetyeval.client.co.QualFilingMaterialCO;
import org.qinan.safetyeval.client.dto.QualFilingMaterialAddCmd;
import org.qinan.safetyeval.client.dto.QualFilingMaterialModifyCmd;
import org.qinan.safetyeval.client.dto.QualFilingMaterialPageQuery;
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-material")
public class QualFilingMaterialController {

    @Resource
    private QualFilingMaterialApi qualFilingMaterialApi;

    @ApiOperation("新增备案申请材料")
    @PostMapping("/save")
    public SingleResponse<QualFilingMaterialCO> add(@Validated @RequestBody QualFilingMaterialAddCmd cmd) {
        return qualFilingMaterialApi.add(cmd);
    }

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

    @ApiOperation("修改备案申请材料")
    @PostMapping("/modify")
    public SingleResponse<QualFilingMaterialCO> modify(@Validated @RequestBody QualFilingMaterialModifyCmd cmd) {
        return qualFilingMaterialApi.modify(cmd);
    }

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

    @ApiOperation("分页查询备案申请材料")
    @GetMapping("/page")
    public PageResponse<QualFilingMaterialCO> page(@Validated QualFilingMaterialPageQuery query) {
        return qualFilingMaterialApi.page(query);
    }

    @ApiOperation("初始化材料模板")
    @PostMapping("/init-template")
    public SingleResponse<Void> initTemplate(@ApiParam("备案申请id") @RequestParam Long filingId) {
        return qualFilingMaterialApi.initTemplate(filingId);
    }

    @ApiOperation("上传材料附件")
    @PostMapping("/upload")
    public SingleResponse<QualFilingMaterialCO> upload(
            @Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingAttachmentUploadCmd cmd) {
        return qualFilingMaterialApi.upload(cmd);
    }
}
