package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
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.OrgQualificationApi;
import org.qinan.safetyeval.client.co.OrgQualificationCO;
import org.qinan.safetyeval.client.dto.OrgQualificationAddCmd;
import org.qinan.safetyeval.client.dto.OrgQualificationModifyCmd;
import org.qinan.safetyeval.client.dto.OrgQualificationPageQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 机构资质证书适配层（Controller）
 *
 * @author safety-eval
 */
@Api(tags = "机构资质证书管理")
@RestController
@RequestMapping("/safetyEval/org-qualification")
public class OrgQualificationController {

    @Resource
    private OrgQualificationApi orgQualificationApi;

    @ApiOperation("新增机构资质证书")
    @PostMapping("/save")
    public SingleResponse<OrgQualificationCO> add(@Validated @RequestBody OrgQualificationAddCmd cmd) {
        return orgQualificationApi.add(cmd);
    }

    @ApiOperation("查询机构资质证书详情")
    @GetMapping("/get")
    public SingleResponse<OrgQualificationCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return orgQualificationApi.get(id);
    }

    @ApiOperation("修改机构资质证书")
    @PostMapping("/modify")
    public SingleResponse<OrgQualificationCO> modify(@Validated @RequestBody OrgQualificationModifyCmd cmd) {
        return orgQualificationApi.modify(cmd);
    }

    @ApiOperation("删除机构资质证书")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return orgQualificationApi.delete(id);
    }

    @ApiOperation("分页查询机构资质证书")
    @GetMapping("/page")
    public PageResponse<OrgQualificationCO> page(@Validated OrgQualificationPageQuery query) {
        return orgQualificationApi.page(query);
    }

    @ApiOperation("分类查询机构资质证书")
    @GetMapping("/classGet")
    public SingleResponse<Map<String, List<OrgQualificationCO>>> classGet(@ApiParam (value = "机构信息id") @RequestParam Long id) {
        return orgQualificationApi.classGet(id);
    }
}
