package com.ruoyi.xq.controller.app;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.xq.dto.app.unread.UserUnreadAppVo;
import com.ruoyi.xq.manager.UserUnreadFlagManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user/unread")
@Tag(name = "当前用户未读消息角标")
public class UserUnreadController {
    @Autowired
    private UserUnreadFlagManager userUnreadFlagManager;

    @GetMapping("/messageNum")
    @Operation(summary = "用户未读的数据")
    public R<UserUnreadAppVo> messageNum(){
        Long userId = LoginHelper.getUserId();
        UserUnreadAppVo vo = new UserUnreadAppVo();
        vo.setStar(userUnreadFlagManager.getStarFlag(userId));
        vo.setStarDynamic(userUnreadFlagManager.getStarDynamicFlag(userId));
        vo.setVisible(userUnreadFlagManager.getVisibleFlag(userId));
        return R.ok(vo);
    }

    @GetMapping("/reset/message")
    @Operation(summary = "将消息设置为全部已读")
    public R<Void> resetMessage(@Parameter(name = "type", description = "类型 1-关注 2-关注动态 3-访问我的人") Integer type){
        Long userId = LoginHelper.getUserId();
        if(type == null){
            return R.ok();
        }
        if(type == 1){
            userUnreadFlagManager.resetStarKey(userId);
        }else if(type == 2){
            userUnreadFlagManager.resetStarDynamicKey(userId);
        }else if(type == 3){
            userUnreadFlagManager.resetVisibleKey(userId);
        }
        return R.ok();
    }

}
