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.OrgPersonnelApi;
import org.qinan.safetyeval.client.co.OrgPersonnelCO;
import org.qinan.safetyeval.client.dto.OrgPersonnelAddCmd;
import org.qinan.safetyeval.client.dto.OrgPersonnelModifyCmd;
import org.qinan.safetyeval.client.dto.OrgPersonnelPageQuery;
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/org-personnel")
public class OrgPersonnelController {

    @Resource
    private OrgPersonnelApi orgPersonnelApi;

    @ApiOperation("新增人员信息")
    @PostMapping("/save")
    public SingleResponse<OrgPersonnelCO> add(@Validated @RequestBody OrgPersonnelAddCmd cmd) {
        return orgPersonnelApi.add(cmd);
    }

    @ApiOperation("查询人员信息详情")
    @GetMapping("/get")
    public SingleResponse<OrgPersonnelCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return orgPersonnelApi.get(id);
    }

    @ApiOperation("修改人员信息")
    @PostMapping("/modify")
    public SingleResponse<OrgPersonnelCO> modify(@Validated @RequestBody OrgPersonnelModifyCmd cmd) {
        return orgPersonnelApi.modify(cmd);
    }

    @ApiOperation("删除人员信息")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return orgPersonnelApi.delete(id);
    }

    @ApiOperation("分页查询人员信息")
    @GetMapping("/page")
    public PageResponse<OrgPersonnelCO> page(@Validated OrgPersonnelPageQuery query) {
        return orgPersonnelApi.page(query);
    }

    @ApiOperation("重置人员密码")
    @PostMapping("/reset-password")
    public SingleResponse<Void> resetPassword(@ApiParam("主键ID") @RequestParam Long id) {
        return orgPersonnelApi.resetPassword(id);
    }
}
