package com.agileboot.system.monitor.controller;

import com.agileboot.common.core.core.R;
import com.agileboot.common.mybatis.core.page.PageR;
import com.agileboot.system.monitor.service.ISysMonitorService;
import com.agileboot.system.monitor.vo.OnlineUserVO;
import com.agileboot.system.monitor.vo.RedisCacheInfoVO;
import com.agileboot.system.monitor.vo.ServerInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缓存监控
 */
@RestController
@RequestMapping("/monitor")
@RequiredArgsConstructor
public class MonitorController {

    private final ISysMonitorService sysMonitorService;

    /**
     * Redis信息
     */
    @GetMapping("/cacheInfo")
    public R<RedisCacheInfoVO> getRedisCacheInfo() {
        RedisCacheInfoVO redisCacheInfo = sysMonitorService.getRedisCacheInfo();
        return R.ok(redisCacheInfo);
    }


    /**
     * 服务器信息
     */
    @GetMapping("/serverInfo")
    public R<ServerInfo> getServerInfo() {
        ServerInfo serverInfo = sysMonitorService.getServerInfo();
        return R.ok(serverInfo);
    }

    /**
     * 获取在线用户列表
     *
     * @param ipAddress ip地址
     * @param username  用户名
     * @return 分页处理后的在线用户信息
     */
    @GetMapping("/onlineUsers")
    public PageR<OnlineUserVO> onlineUsers(@RequestParam(name = "ipAddress", required = false) String ipAddress, @RequestParam(name = "username", required = false) String username) {
        List<OnlineUserVO> onlineUserList = sysMonitorService.getOnlineUserList(username, ipAddress);
        return new PageR<>(onlineUserList);
    }

    /**
     * 强退用户
     */
    @DeleteMapping("/onlineUser/{tokenId}")
    public R<Void> logoutOnlineUser(@PathVariable String tokenId) {

        return R.ok();
    }
}
