package com.zcloud.zcGbsServicer.web;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.zcGbsServicer.api.FireBrigadeMemberServiceI;
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberAddCmd;
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberPageQry;
import com.zcloud.zcGbsServicer.dto.FireBrigadeMemberUpdateCmd;
import com.zcloud.zcGbsServicer.dto.FireBrigadeScreenMemberQry;
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberCO;
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeMemberStatusCO;
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeScreenMemberCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "消防队伍成员")
@RestController
@AllArgsConstructor
@RequestMapping("/${application.gateway}/fireBrigade/member")
public class FireBrigadeMemberController {

    private final FireBrigadeMemberServiceI fireBrigadeMemberService;

    @ApiOperation("查询当前登录用户是否为消防队成员")
    @GetMapping("/current/status")
    public SingleResponse<FireBrigadeMemberStatusCO> currentMemberStatus() {
        return fireBrigadeMemberService.currentMemberStatus();
    }

    @ApiOperation("可视化大屏-大屏队员分页列表")
    @PostMapping("/screen/list")
    public PageResponse<FireBrigadeScreenMemberCO> screenList(@RequestBody(required = false) FireBrigadeScreenMemberQry qry) {
        return fireBrigadeMemberService.listScreenMembers(qry == null ? new FireBrigadeScreenMemberQry() : qry);
    }

    @ApiOperation("分页查询")
    @PostMapping("/list")
    public PageResponse<FireBrigadeMemberCO> list(@RequestBody FireBrigadeMemberPageQry qry) {
        return fireBrigadeMemberService.listPage(qry);
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<FireBrigadeMemberCO> save(@Validated @RequestBody FireBrigadeMemberAddCmd cmd) {
        return fireBrigadeMemberService.add(cmd);
    }

    @ApiOperation("编辑")
    @PutMapping("/edit")
    public Response edit(@Validated @RequestBody FireBrigadeMemberUpdateCmd cmd) {
        fireBrigadeMemberService.edit(cmd);
        return Response.buildSuccess();
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<FireBrigadeMemberCO> get(@PathVariable Long id) {
        return SingleResponse.of(fireBrigadeMemberService.get(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable Long id) {
        fireBrigadeMemberService.remove(id);
        return Response.buildSuccess();
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        fireBrigadeMemberService.removeBatch(ids);
        return Response.buildSuccess();
    }
}
