package com.artfess.rescue.event.controller;


import com.artfess.base.annotation.ApiGroup;
import com.artfess.base.constants.ApiGroupConsts;
import com.artfess.base.enums.ResponseErrorEnums;
import com.artfess.base.model.CommonResult;
import com.artfess.base.valid.AddGroup;
import com.artfess.base.valid.UpdateGroup;
import com.artfess.rescue.event.dto.EventInfoDto;
import com.artfess.rescue.event.vo.HandInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.artfess.base.controller.BaseController;
import com.artfess.rescue.event.model.BizEventHandle;
import com.artfess.rescue.event.manager.BizEventHandleManager;

import java.util.Arrays;
import java.util.List;

/**
 * 事件处置记录 前端控制器
 *
 * @company 阿特菲斯信息技术有限公司
 * @author 系统管理员
 * @since 2024-08-05
 */
@RestController
@RequestMapping("/event/bizEventHandle/v1/")
@Api(tags = "事件处置记录")
@ApiGroup(group = {ApiGroupConsts.GROUP_BIZ_RESCUE})
public class BizEventHandleController extends BaseController<BizEventHandleManager, BizEventHandle> {

    @RequestMapping(value = "/accept", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "事件接收", httpMethod = "POST", notes = "事件接收")
    public CommonResult<String> accept(@RequestBody EventInfoDto t) {
        boolean res = baseService.accept(t);
        return new CommonResult<>(res,res?"接收成功":"接收失败");
    }

    @Override
    @PostMapping("/")
    @ApiOperation("添加实体的接口")
    public CommonResult<String> create(@ApiParam(name = "model", value = "实体信息") @Validated({AddGroup.class}) @RequestBody BizEventHandle t) {
         baseService.saveInfo(t);
        return new CommonResult<>(true,"添加成功");
    }


    @PostMapping("/pc")
    @ApiOperation("添加实体的接口(pc管理)")
    public CommonResult<String> createPc(@ApiParam(name = "model", value = "实体信息") @Validated({AddGroup.class}) @RequestBody BizEventHandle t) {
        baseService.savePcInfo(t);
        return new CommonResult<>(true,"添加成功");
    }

    @Override
    @PutMapping("/")
    @ApiOperation("更新实体")
    public CommonResult<String> updateById(@ApiParam(name = "model", value = "实体信息") @Validated({UpdateGroup.class}) @RequestBody BizEventHandle t) {
        boolean res = baseService.updateInfo(t);
        if (!res) {
            return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "更新实体失败");
        }
        return new CommonResult<>("更新实体成功");
    }

    @GetMapping("/list")
    @ApiOperation("根据事件id查询list集合")
    public CommonResult<String> list(@RequestParam("eventId") String eventId) {
        List<HandInfoVO> hands = baseService.getHands(eventId);
        return CommonResult.success(hands,"");
    }

    @GetMapping("/handList")
    @ApiOperation("根据事件id查询list集合")
    public CommonResult<String> handList(@RequestParam("eventId") String eventId) {
        List<HandInfoVO> hands = baseService.getHandInfo(eventId);
        return CommonResult.success(hands,"");
    }

    @PostMapping("/finish")
    @ApiOperation("事件批量完结")
    public CommonResult<String> batchFinish(@ApiParam(name = "ids", value = "实体ID集合") @RequestParam String... ids) {
        return baseService.batchFinish(Arrays.asList(ids));
    }
}
