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.DataModelParam;
import com.njcn.energy.pojo.param.DevVersionParam;
import com.njcn.energy.pojo.po.DataMould;
import com.njcn.energy.pojo.po.DevVersion;
import com.njcn.energy.service.IDevModelService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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/8 20:24
 */
@Slf4j
@RestController
@RequestMapping("/devModel")
@RequiredArgsConstructor
@Api(tags = "装置模板管理")
public class DevModelController extends BaseController {

    private final IDevModelService devModelService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增设备数据模板")
    @ApiImplicitParam(name = "dataModelParam", value = "设备版本信息", required = true)
    public HttpResult<DataMould> add(@RequestBody DataModelParam dataModelParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，设备版本信息为：{}", methodDescribe, dataModelParam);
        DataMould dataMould = devModelService.addDataMould(dataModelParam);
        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 = devModelService.deleteById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/findMould")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("查找模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "模板名称", required = true),
            @ApiImplicitParam(name = "version", value = "模板版本", required = true),
            @ApiImplicitParam(name = "time", value = "模板时间", required = true)
    })
    public HttpResult<DataMould> findMould(@RequestParam String name,@RequestParam String version,@RequestParam String time){
        String methodDescribe = getMethodDescribe("findMould");
        LogUtil.njcnDebug(log, "{}，模板名称：{}，模板版本：{}，模板时间：{}", methodDescribe, name,version,time);
        DataMould dataMould = devModelService.findMould(name, version, time);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataMould, methodDescribe);
    }

}
