package com.fzm.mall.server.admin.user_center.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzm.mall.server.admin.annotation.AdminLog;
import com.fzm.mall.server.admin.enums.log.OperateModuleEnum;
import com.fzm.mall.server.admin.enums.log.OperateTypeEnum;
import com.fzm.mall.server.admin.home_page.enums.type.AdminTypeEnum;
import com.fzm.mall.server.admin.home_page.service.IAdminService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.fzm.mall.server.admin.user_center.entity.dto.UserLockDTO;
import com.fzm.mall.server.admin.user_center.entity.vo.UserVO;
import com.fzm.mall.server.admin.user_center.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wangp
 * @date 2021/3/22 14:33
 * @description 用户
 * @since JDK 1.8
 */
@Api(tags = "用户中心-用户")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {

    private final IAdminService adminService;
    private final IUserService userService;
    private final ResponseFactory resFac;

    @ApiOperation("分页查询-用户列表")
    @GetMapping("/userList/page")
    public ResponseVO page(
            @ApiParam(name = "uid", value = "用户唯一标识")
            @RequestParam(required = false) String uid,
            @ApiParam(name = "account", value = "登陆账号")
            @RequestParam(required = false) String account,
            @ApiParam(name = "pageNum", value = "当前页数")
            @RequestParam Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页个数")
            @RequestParam Integer pageSize,
            @ApiParam(name = "adminId", value = "管理员id")
            @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        IPage<UserVO> page = userService.page(uid, account, pageNum, pageSize);
        return resFac.getSuccessResponseWithData(page);
    }

    @ApiOperation("锁定/解锁")
    @PutMapping("/userList/lock")
    @AdminLog(description = "用户中心-用户锁定/解锁", module = OperateModuleEnum.USER_CENTER, opType = OperateTypeEnum.USER_LOCK)
    public ResponseVO lock(@RequestBody @Valid UserLockDTO lockDTO, @ApiParam(name = "adminId", value = "管理员id")
    @RequestHeader String adminId) {
        adminService.adminAuthChecks(adminId, AdminTypeEnum.getPlatFormTypeArr());
        userService.lock(lockDTO);
        return resFac.getSimpleSuccessResponse();
    }

    //WAIT reset login password
}
