package com.njcn.supervision.controller.databank;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.supervision.pojo.param.databank.LibModelParam;
import com.njcn.supervision.pojo.po.databank.LibModel;
import com.njcn.supervision.service.databank.ILibModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wr
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/libModel")
@RequiredArgsConstructor
@Api(tags = "模型库")
public class LibModelController extends BaseController {

    private final ILibModelService libModelService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageLibModelQuery")
    @ApiOperation("分页查询模型库")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<Page<LibModel>> pageLibModelQuery(@RequestBody @Validated LibModelParam.LibModelParamQuery param) {
        String methodDescribe = getMethodDescribe("pageLibModelQuery");
        Page<LibModel> page = libModelService.page(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/addLibModel")
    @ApiOperation("新增模型库")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<Boolean> addLibModel(@RequestBody @Validated LibModelParam param) {
        String methodDescribe = getMethodDescribe("addLibModel");
        Boolean add = libModelService.add(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, add, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/updateLibModel")
    @ApiOperation("更新模型库")
    @ApiImplicitParam(name = "param", value = "实体参数", required = true)
    public HttpResult<Boolean> updateLibModel(@RequestBody @Validated LibModelParam.LibModelParamUpdate param) {
        String methodDescribe = getMethodDescribe("updateLibModel");
        Boolean update = libModelService.update(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, update, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.DELETE)
    @GetMapping("/deleteByLibModelId")
    @ApiOperation("通过id删除模型库")
    public HttpResult<Boolean> deleteByLibModelId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("deleteByLibModelId");
        boolean update = libModelService.lambdaUpdate().set(LibModel::getStatus, 0).eq(LibModel::getId, id).update();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, update, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/queryByLibModelId")
    @ApiOperation("根据id查询模型库")
    public HttpResult<LibModel> queryByLibModelId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("queryByLibModelId");
        LibModel result = libModelService.lambdaQuery().eq(LibModel::getId,id).one();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


}

