package com.ruoyi.xq.controller.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.BeanConvertUtil;
import com.ruoyi.xq.domain.UserStatus;
import com.ruoyi.xq.dto.app.userstatus.UserStatusInfoAppVo;
import com.ruoyi.xq.dto.app.userstatus.UserStatusUpdateAppReq;
import com.ruoyi.xq.dto.app.userstatus.UserStatusUpdateMasterAppReq;
import com.ruoyi.xq.service.UserStatusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/userStatus")
@Tag(name = "用户状态")
public class UserStatusAppController {
    @Autowired
    private UserStatusService userStatusService;

    @GetMapping("/info")
    @Operation(summary = "获取当前用户状态")
    @Log(title = "获取当前用户状态", businessType = BusinessType.OTHER,isPrintResponseData = false, isSaveDb = false)
    public R<UserStatusInfoAppVo> info(){
        UserStatus userStatus = userStatusService.getByUserId(LoginHelper.getUserId());
        UserStatusInfoAppVo vo = BeanConvertUtil.convertTo(userStatus, UserStatusInfoAppVo::new);
        return R.ok(vo);
    }

    @PostMapping("/updateMaster")
    @Operation(summary = "修改当前用户主状态")
    @Log(title = "修改当前用户主状态", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Void> updateMaster(@RequestBody UserStatusUpdateMasterAppReq req){
        req.setUserId(LoginHelper.getUserId());
        userStatusService.updateStatusMaster(req);
        return R.ok();
    }

    @PostMapping("/update")
    @Operation(summary = "修改当前用户状态")
    @Log(title = "修改当前用户状态", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Void> update(@RequestBody UserStatusUpdateAppReq req){
        req.setUserId(LoginHelper.getUserId());
        userStatusService.updateStatus(req);
        return R.ok();
    }
}
