package cn.newfeifan.mall.module.system.controller.app.user;

import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserRespVO;
import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
import cn.newfeifan.mall.module.system.service.user.AdminUserService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 用户信息")
@RestController
@RequestMapping("/system/users")
@Validated
public class UsersController {

    @Resource
    private AdminUserService usersService;

    @GetMapping("/get")
    @Operation(summary = "获得用户信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<UserRespVO> getUsers(@RequestParam("id") Long id) {
        AdminUserDO users = usersService.getUser(id);
        return success(BeanUtils.toBean(users, UserRespVO.class));
    }

    @GetMapping("/getUserMobile")
    @Operation(summary = "查询系统用户号码是否存在")
    @Parameter(name = "mobile", description = "手机号码", required = true, example = "1024")
    public CommonResult<Boolean> getUserMobile(@RequestParam("mobile") String mobile) {
        return success(usersService.getUserByMobile(mobile) == null);
    }
}