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.QualFilingPersonnelApi;
import org.qinan.safetyeval.client.co.QualFilingPersonnelCO;
import org.qinan.safetyeval.client.dto.QualFilingPersonnelAddCmd;
import org.qinan.safetyeval.client.dto.QualFilingPersonnelModifyCmd;
import org.qinan.safetyeval.client.dto.QualFilingPersonnelPageQuery;
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-personnel")
public class QualFilingPersonnelController {

    @Resource
    private QualFilingPersonnelApi qualFilingPersonnelApi;

    @ApiOperation("新增备案申请人员")
    @PostMapping("/save")
    public SingleResponse<QualFilingPersonnelCO> add(@Validated @RequestBody QualFilingPersonnelAddCmd cmd) {
        return qualFilingPersonnelApi.add(cmd);
    }

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

    @ApiOperation("修改备案申请人员")
    @PostMapping("/modify")
    public SingleResponse<QualFilingPersonnelCO> modify(@Validated @RequestBody QualFilingPersonnelModifyCmd cmd) {
        return qualFilingPersonnelApi.modify(cmd);
    }

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

    @ApiOperation("分页查询备案申请人员")
    @GetMapping("/page")
    public PageResponse<QualFilingPersonnelCO> page(@Validated QualFilingPersonnelPageQuery query) {
        return qualFilingPersonnelApi.page(query);
    }

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