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.OrgInfoApi;
import org.qinan.safetyeval.client.co.OrgInfoCO;
import org.qinan.safetyeval.client.dto.OrgInfoAddCmd;
import org.qinan.safetyeval.client.dto.OrgInfoModifyCmd;
import org.qinan.safetyeval.client.dto.OrgInfoPageQuery;
import org.qinan.safetyeval.client.dto.OrgInfoUpdateStateCmd;
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-info")
public class OrgInfoController {

    @Resource
    private OrgInfoApi orgInfoApi;

    @ApiOperation("新增机构信息")
    @PostMapping("/save")
    public SingleResponse<OrgInfoCO> add(@Validated @RequestBody OrgInfoAddCmd cmd) {
        return orgInfoApi.add(cmd);
    }

    @ApiOperation("根据查询机构信息详情")
    @GetMapping("/get")
    public SingleResponse<OrgInfoCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return orgInfoApi.get(id);
    }

    @ApiOperation("查询机构信息详情(内部查询)")
    @GetMapping("/getInfo")
    public SingleResponse<OrgInfoCO> getInfo() {
        return orgInfoApi.getInfo();
    }

    @ApiOperation("修改机构信息")
    @PostMapping("/modify")
    public SingleResponse<OrgInfoCO> modify(@Validated @RequestBody OrgInfoModifyCmd cmd) {
        return orgInfoApi.modify(cmd);
    }

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

    @ApiOperation("启用/禁用机构信息")
    @PostMapping("/update-state")
    public SingleResponse<Void> updateState(@Validated @RequestBody OrgInfoUpdateStateCmd cmd) {
        return orgInfoApi.updateState(cmd);
    }

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

    @ApiOperation("分页查询机构信息")
    @GetMapping("/page")
    public PageResponse<OrgInfoCO> page(@Validated OrgInfoPageQuery query) {
        return orgInfoApi.page(query);
    }
}
