package com.njcn.energy.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.common.utils.LogUtil;
import com.njcn.energy.pojo.param.DevVersionParam;
import com.njcn.energy.pojo.po.DevVersion;
import com.njcn.energy.service.IDevVersionService;
import com.njcn.web.controller.BaseController;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 类的介绍：设备版本信息表
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/7 18:56
 */
@Slf4j
@RestController
@RequestMapping("/version")
@RequiredArgsConstructor
@Api(tags = "版本信息")
public class DevVersionController extends BaseController {

    private final IDevVersionService IDevVersionService;

    @PostMapping("add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增设备版本信息")
    @ApiImplicitParam(name = "devVersionParam", value = "设备版本信息", required = true)
    public HttpResult<DevVersion> add(@RequestBody DevVersionParam devVersionParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，网关设备数据为：{}", methodDescribe, devVersionParam);
        DevVersion devVersion = IDevVersionService.addDevVersion(devVersionParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @DeleteMapping("delete")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.DELETE)
    @ApiOperation("删除设备版本信息")
    @ApiImplicitParam(name = "id", value = "设备版本id", required = true)
    public HttpResult<Boolean> delete(@RequestParam String id){
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，设备版本id：{}", methodDescribe, id);
        boolean result = IDevVersionService.deleteDevVersion(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
