package com.om.controller.admin;


import com.om.entity.dto.UserLoginDTO;
import com.om.entity.dto.UserLoginDTO;
import com.om.entity.dto.UserQueryPageDTO;
import com.om.entity.po.User;
import com.om.entity.po.VciInfo;
import com.om.entity.vo.AppBindVO;
import com.om.entity.vo.UserAddVO;
import com.om.entity.vo.UserQueryPageVO;
import com.om.entity.vo.UserVO;
import com.om.service.IUserService;
import com.om.utils.Result;
import com.om.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 应用用户信息表 前端控制器
 * </p>
 *
 * @author bmmx
 * @since 2024-01-29
 */
@RestController
@Api(tags = "客户端用户模块")
@RequestMapping("/web/app-user-info")
public class AppUserController {
    @Resource
    private IUserService userService;


    @PostMapping("/login")
    @ApiOperation("客户端用户登录")
    public Result login(@RequestBody UserLoginDTO dto){
        return userService.login(dto);
    }

    @GetMapping("/get")
    @ApiOperation("获取当前登录id")
    public Result get(){
        Integer userId = UserContext.getUserId();
        return Result.ok(userId);
    }


    @PostMapping("/add")
    @ApiOperation("新增客户端用户")
    public Result add(@RequestBody UserAddVO userAddVO){

        return userService.add(userAddVO);

    }
    @GetMapping("/delete")
    @ApiOperation("删除客户端用户")
    public Result delete(@RequestParam Integer id){

        return userService.delete(id);
    }
    @GetMapping("/getById")
    @ApiOperation("根据id获取指定的客户端用户")
    public Result<UserVO> getById(@RequestParam Integer userId){

        return userService.getByUserId(userId);
    }
    @GetMapping("/getListByUserId")
    @ApiOperation("通过user获得vci相关的用户信息(返回集合)")
    public Result getListByUserId(@RequestParam Integer userId){

        return userService.getListByUserId(userId);
    }

    @PostMapping("/getPageList")
    @ApiOperation("分页获取所有的用户List集合")
    public Result<UserQueryPageVO> getPageList(@RequestBody UserQueryPageDTO dto){

        return userService.getPageList(dto);
    }

    @GetMapping("/list")
    @ApiOperation("获取客户端用户List集合")
    public Result<List<User>> list(){

        return Result.ok(userService.listByDevice());
    }

    @GetMapping("/relieve(未写)")
    @ApiOperation("(未写)")
    public Result relieve(){
        //这里未写，未知要求
        return userService.relieve();
    }

    @GetMapping("/updateState")
    @ApiOperation("更新用户状态")
    public Result updateState(@RequestParam Integer id,@RequestParam Integer state){

        return userService.updateState(id,state);
    }
    @GetMapping("/updateType")
    @ApiOperation("更新类型")
    Result updateType(@RequestParam Integer id,@RequestParam Integer type){

        return userService.updateType(id,type);
    }

    @PostMapping("/updateUserInfo")
    @ApiOperation("更新用户信息")
    Result updateUserInfo(@RequestBody UserAddVO user){

        return userService.updateUserInfo(user);
    }
    @PostMapping("/bindingVci")
    @ApiOperation("绑定vci")
    Result bindingVci(@RequestBody AppBindVO bindVO){

        return userService.bindingVci(bindVO);
    }

    @PostMapping("/relieveVci")
    @ApiOperation("解绑vci")
    Result relieveVci(@RequestBody AppBindVO bindVO){

        return userService.relieveVci(bindVO);
    }

    @GetMapping("/getVciByUserId")
    @ApiOperation("根据用户id获取vci设备列表")
    public Result<List<VciInfo>> getVciByUserId(@RequestParam Integer userId){
        return userService.getVciByUserId(userId);
    }

    @GetMapping("updateDefaultVci")
    @ApiOperation("修改用户绑定的vci状态")
    public Result updateDefaultVci(@RequestParam Integer userId,@RequestParam Integer vciId,@RequestParam Integer status){
        return userService.updateDefaultVci(userId,vciId,status);
    }

    @GetMapping("resetPassword")
    @ApiOperation("重置用户密码")
    public Result resetPassword(@RequestParam Integer id){
        return userService.resetPassword(id);
    }

}
