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.NetDevParam;
import com.njcn.energy.pojo.po.EleTopic;
import com.njcn.energy.service.IEleTopicService;
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.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/22 19:00
 */
@Slf4j
@RestController
@RequestMapping("/topic")
@RequiredArgsConstructor
@Api(tags = "网关主题管理")
public class EleTopicController extends BaseController {

    private final IEleTopicService topicService;

    /**
     * 新增网关主题信息
     * @author xy
     * @date 2022/3/22 19:02
     */
    @PostMapping("add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增网关主题")
    @ApiImplicitParam(name = "eleTopic", value = "网关主题信息", required = true)
    public HttpResult<Object> add(@RequestBody EleTopic eleTopic){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，网关主题信息：{}", methodDescribe, eleTopic);
        boolean result = topicService.addTopic(eleTopic);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 查询网关主题信息
     * @author xy
     * @date 2022/3/22 19:02
     */
    @GetMapping("list")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.QUERY)
    @ApiOperation("查询网关主题")
    @ApiImplicitParam(name = "id", value = "网关id", required = true)
    public HttpResult<List<EleTopic>> list(@RequestParam String id){
        String methodDescribe = getMethodDescribe("list");
        LogUtil.njcnDebug(log, "{}，网关id：{}", methodDescribe, id);
        List<EleTopic> list = topicService.list(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    /**
     * 删除网关主题信息
     * @author xy
     * @date 2022/3/22 19:02
     */
    @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 = topicService.delete(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }
}
