package com.sckw.system.controller.forkliftapp;

import com.sckw.core.web.response.BaseResult;
import com.sckw.system.model.vo.req.LoginReqVo;
import com.sckw.system.model.vo.req.LogoutReqVo;
import com.sckw.system.model.vo.req.SwitchAccountReqVo;
import com.sckw.system.model.vo.req.UpdatePasswordReqVo;
import com.sckw.system.model.vo.req.UserInfoReqVo;
import com.sckw.system.model.vo.res.LoginResVo;
import com.sckw.system.model.vo.res.SwitchAccountResVo;
import com.sckw.system.model.vo.res.UserInfoResVo;
import com.sckw.system.service.KwsUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户基础信息Controller
 * @author chenxiaofei
 * @date 2026-01-07
 */
@RestController
@RequestMapping("/users")
@Tag(name = "用户信息相关接口")
@RequiredArgsConstructor
public class UsersController {

    private final KwsUserService kwsUserService;

    /**
     * 用户登录
     * @param reqVo 登录请求对象
     * @param request HTTP请求
     * @return BaseResult<LoginResVo>
     */
//    @PostMapping("/login")
//    @Operation(summary = "用户登录", description = "用户登录，返回用户信息和角色")
//    public BaseResult<LoginResVo> login(@RequestBody @Valid LoginReqVo reqVo, HttpServletRequest request) {
//        return BaseResult.success(kwsUserService.login(
//                reqVo.getAccount(),
//                reqVo.getPassword(),
//                reqVo.getSystemType(),
//                request));
//    }

    /**
     * 根据用户ID查询用户信息
     * @param reqVo 用户信息查询请求对象
     * @return BaseResult<UserInfoResVo>
     */
//    @PostMapping("/getUserInfo")
//    @Operation(summary = "查询用户信息", description = "根据用户ID查询头像、姓名、电话、角色、账号状态")
//    public BaseResult<UserInfoResVo> getUserInfo(@RequestBody UserInfoReqVo reqVo) {
//        return BaseResult.success(kwsUserService.getUserInfoById(reqVo.getUserId()));
//    }

    /**
     * 修改密码
     * @param reqVo 修改密码请求对象
     * @return BaseResult<String>
     */
    @PostMapping("/updatePassword")
    @Operation(summary = "修改密码", description = "用户修改密码")
    public BaseResult<String> updatePassword(@RequestBody @Valid UpdatePasswordReqVo reqVo, HttpServletRequest request) {
        int systemType = request.getIntHeader("System-Type");
        String clientType = request.getHeader("Client-Type");
        kwsUserService.updatePasswordForApp(reqVo.getUserId(),
                reqVo.getOldPassword(), reqVo.getNewPassword(),
                clientType, systemType, reqVo.getDeviceId());
        return BaseResult.success("密码修改成功");
    }

    /**
     * 切换账号
     * @param reqVo 切换账号请求对象
     * @return BaseResult<SwitchAccountResVo>
     */
//    @PostMapping("/switchAccount")
//    @Operation(summary = "切换账号", description = "切换到其他用户账号")
//    public BaseResult<SwitchAccountResVo> switchAccount(@RequestBody @Valid SwitchAccountReqVo reqVo, HttpServletRequest request) {
//        return BaseResult.success(kwsUserService.switchAccount(
//                reqVo.getAccount(),
//                reqVo.getPassword(),
//                reqVo.getSystemType(),
//                request));
//    }

    /**
     * 退出登录
     * @param reqVo 退出登录请求对象
     * @return BaseResult<String>
     */
//    @PostMapping("/logout")
//    @Operation(summary = "退出登录", description = "用户退出登录，清除登录状态和Token")
//    public BaseResult<String> logout(@RequestBody @Valid LogoutReqVo reqVo) {
//        kwsUserService.logout(reqVo.getUserId());
//        return BaseResult.success("退出登录成功");
//    }

}

