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.QualFilingEquipmentApi;
import org.qinan.safetyeval.client.co.QualFilingEquipmentCO;
import org.qinan.safetyeval.client.dto.QualFilingEquipmentAddCmd;
import org.qinan.safetyeval.client.dto.QualFilingEquipmentModifyCmd;
import org.qinan.safetyeval.client.dto.QualFilingEquipmentPageQuery;
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-equipment")
public class QualFilingEquipmentController {

    @Resource
    private QualFilingEquipmentApi qualFilingEquipmentApi;

    @ApiOperation("新增备案申请装备")
    @PostMapping("/save")
    public SingleResponse<QualFilingEquipmentCO> add(@Validated @RequestBody QualFilingEquipmentAddCmd cmd) {
        return qualFilingEquipmentApi.add(cmd);
    }

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

    @ApiOperation("修改备案申请装备")
    @PostMapping("/modify")
    public SingleResponse<QualFilingEquipmentCO> modify(@Validated @RequestBody QualFilingEquipmentModifyCmd cmd) {
        return qualFilingEquipmentApi.modify(cmd);
    }

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

    @ApiOperation("分页查询备案申请装备")
    @GetMapping("/page")
    public PageResponse<QualFilingEquipmentCO> page(@Validated QualFilingEquipmentPageQuery query) {
        return qualFilingEquipmentApi.page(query);
    }

    @ApiOperation("从企业装备库批量引入")
    @PostMapping("/batch-add-from-org")
    public SingleResponse<Integer> batchAddFromOrg(
            @Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingEquipmentBatchAddCmd cmd) {
        return qualFilingEquipmentApi.batchAddFromOrg(cmd);
    }

    @ApiOperation("上传计量检定报告")
    @PostMapping("/upload-calibration")
    public SingleResponse<QualFilingEquipmentCO> uploadCalibration(
            @Validated @RequestBody org.qinan.safetyeval.client.dto.QualFilingAttachmentUploadCmd cmd) {
        return qualFilingEquipmentApi.uploadCalibration(cmd);
    }
}
