package com.ningdatech.pmapi.user.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.user.manage.UserInfoManage;
import com.ningdatech.pmapi.user.model.po.*;
import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO;
import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author Liuxinxin
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/api/v1/user-info")
@RequiredArgsConstructor
@Api(value = "UserInfoController", tags = "用户管理")
public class UserInfoController {

    private final UserInfoManage userInfoManage;

    @ApiOperation(value = "用户列表搜索", notes = "用户列表搜索")
    @PostMapping("/list")
    public PageVo<ResUserInfoListVO> userInfoList(@Valid @RequestBody ReqUserInfoListPO reqUserInfoListPO) {
        return userInfoManage.list(reqUserInfoListPO);
    }

    @ApiOperation(value = "用户禁用/启用", notes = "用户禁用/启用")
    @PostMapping("/disable-enable")
    public void disableOrEnable(@Valid @RequestBody ReqUserDisableOrEnablePO reqUserDisableOrEnablePO) {
        userInfoManage.disableOrEnable(reqUserDisableOrEnablePO);
    }

    @ApiOperation(value = "用户详情", notes = "用户详情")
    @PostMapping("/detail")
    public ResUserDetailVO userInfoDetail(@Valid @RequestBody ReqUserDetailPO reqUserDetailPO) {
        return userInfoManage.userInfoDetail(reqUserDetailPO);
    }

    @ApiOperation(value = "用户详情编辑", notes = "用户详情编辑")
    @PostMapping("/detail/edit")
    public void userInfoDetailEdit(@Valid @RequestBody ReqUserDetailEditPO reqUserDetailEditPO) {
        userInfoManage.userInfoDetailEdit(reqUserDetailEditPO);
    }

    @ApiOperation(value = "获取当前登陆用户详情信息", notes = "用户详情")
    @PostMapping("/current-user-info")
    public ResUserDetailVO currentUserInfo() {
        return userInfoManage.currentUserInfo();
    }

    @ApiOperation(value = "代登陆", notes = "代登陆")
    @PostMapping("/generation-login")
    public void generationLogin(@Valid @RequestBody ReqGenerationLoginPO reqGenerationLoginPO, HttpServletRequest httpServletRequest) {
        userInfoManage.generationLogin(reqGenerationLoginPO);
    }

}
