package com.njcn.product.cnzutai.zutai.controller;

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.product.cnzutai.zutai.pojo.param.ElementParam;
import com.njcn.product.cnzutai.zutai.service.IElementService;
import com.njcn.product.cnzutai.zutai.pojo.po.CsElement;
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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2023/7/12 16:07
 */
@RestController
@RequestMapping("cs-system-boot/csElement")
@Api(tags = "组态图元")
@AllArgsConstructor
public class ElementController extends BaseController {

    private final IElementService csElementService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("新增图元")
    public HttpResult<CsElement> add(@Validated ElementParam param){
        String methodDescribe = getMethodDescribe("add");
        CsElement csElement = csElementService.addElement(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csElement, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/find")
    @ApiOperation("查询图元")
    public HttpResult<List<CsElement>> find(){
        String methodDescribe = getMethodDescribe("find");
        List<CsElement> list = csElementService.findElement();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/delete")
    @ApiOperation("删除图元")
    @ApiImplicitParam(name = "id", value = "图元Id", required = true)
    public HttpResult<String> deleteById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("deleteById");
        csElementService.deleteById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
