package com.njcn.energy.controller;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/8 10:45
 */

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.param.HardwareParam;
import com.njcn.energy.pojo.po.DevVersion;
import com.njcn.energy.pojo.po.Hardware;
import com.njcn.energy.service.IHardwareService;
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.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/2/28 10:55
 */
@Slf4j
@RestController
@RequestMapping("/hardware")
@AllArgsConstructor
@Api(tags = "硬件管理")
public class HardwareController extends BaseController {

    private final IHardwareService hardwareService;

    @PostMapping("add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.ADD)
    @ApiOperation("新增设备硬件信息")
    @ApiImplicitParam(name = "hardwareParam", value = "设备硬件信息", required = true)
    public HttpResult<DevVersion> add(@RequestBody HardwareParam hardwareParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，设备硬件信息为：{}", methodDescribe, hardwareParam);
        Hardware hardware = hardwareService.addHardware(hardwareParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

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


}
