package com.njcn.cssystem.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.cssystem.pojo.param.WlUserParam;
import com.njcn.cssystem.pojo.vo.WlUserVo;
import com.njcn.cssystem.service.IWlUserService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xy
 * @since 2025-11-12
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/wlUser")
@Api(tags = "用户设备分配")
@AllArgsConstructor
public class WlUserController extends BaseController {

    private final IWlUserService wlUserService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/selectDevByUserId")
    @ApiOperation("根据用户id查询工程和便携式设备")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<WlUserVo> selectDevByUserId(@RequestParam @Validated String userId ) {
        String methodDescribe = getMethodDescribe("selectDevByUserId");
        LogUtil.njcnDebug(log, "{}，用户数据为：{}", methodDescribe, userId);
        WlUserVo vo = wlUserService.selectDevByUserId(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/addUserDev")
    @ApiOperation("用户绑定工程和便携式设备")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<WlUserVo> addUserDev(@RequestBody @Validated WlUserParam param) {
        String methodDescribe = getMethodDescribe("addUserDev");
        LogUtil.njcnDebug(log, "{}，参数：{}", methodDescribe, param);
        wlUserService.addUserDev(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/deleteUserDev")
    @ApiOperation("用户取消绑定工程和便携式设备")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<WlUserVo> deleteUserDev(@RequestBody @Validated WlUserParam param) {
        String methodDescribe = getMethodDescribe("deleteUserDev");
        LogUtil.njcnDebug(log, "{}，参数：{}", methodDescribe, param);
        wlUserService.deleteUserDev(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}

