package com.njcn.csdevice.controller.icd;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.param.IcdBzParam;
import com.njcn.csdevice.param.IcdLedgerParam;
import com.njcn.csdevice.param.IcdParam;
import com.njcn.csdevice.pojo.vo.CldLedgerVo;
import com.njcn.csdevice.pojo.vo.DeviceInfo;
import com.njcn.csdevice.service.IcdService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xy
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/icd")
@Api(tags = "云前置改造")
@AllArgsConstructor
public class IcdController extends BaseController {

    private final IcdService icdService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLedgerInfo")
    @ApiOperation("获取台账信息")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<DeviceInfo>> getLedgerInfo(@RequestBody @Validated IcdParam param){
        String methodDescribe = getMethodDescribe("getLedgerInfo");
        List<DeviceInfo> result = icdService.getLedgerInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addLedgerInfo")
    @ApiOperation("新增台账信息")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<List<DeviceInfo>> addLedgerInfo(@RequestBody @Validated IcdLedgerParam param){
        String methodDescribe = getMethodDescribe("addLedgerInfo");
        icdService.addLedgerInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLedgerById")
    @ApiOperation("根据Id获取台账信息")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public HttpResult<CldLedgerVo> getLedgerById(@RequestParam String id){
        String methodDescribe = getMethodDescribe("getLedgerById");
        CldLedgerVo vo = icdService.getLedgerById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/bzFileByEventId")
    @ApiOperation("指定事件补召波形指令下发")
    @ApiImplicitParam(name = "eventId", value = "事件id", required = true)
    public HttpResult<String> bzFileByEventId(@RequestParam String eventId){
        String methodDescribe = getMethodDescribe("bzFileByEventId");
        icdService.bzFileByEventId(eventId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/bzEvent")
    @ApiOperation("补召事件指令下发")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<String> bzEvent(@RequestBody @Validated IcdBzParam param){
        String methodDescribe = getMethodDescribe("bzEvent");
        icdService.bzEvent(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/bzFile")
    @ApiOperation("补召波形指令下发")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<String> bzFile(@RequestBody @Validated IcdBzParam param){
        String methodDescribe = getMethodDescribe("bzFile");
        icdService.bzFile(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
