package com.app.controller.platform;

import com.app.dto.PageResult;
import com.app.dto.Result;
import com.app.dto.SearchDto;
import com.app.dto.platform.SearchOnlineDto;
import com.app.service.platform.auth.OnlineAccountService;
import com.app.service.platform.dto.AccountDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.annotation.Resource;
import javax.validation.Valid;

/**
 * 在线用户

 */
@Api(tags = "在线用户")
@Slf4j
@RestController("OnlineAccountController")
@RequestMapping("/platform/online")
public class OnlineAccountController {

    @Resource
    private OnlineAccountService onlineAccountService;

    /**
     * 查询【在线用户】列表
     *
     */
    @ApiOperation(value = "查询[在线用户]列表")
    @PostMapping("/page")
    public ResponseEntity<PageResult<AccountDto>> page(@Valid @RequestBody SearchOnlineDto dto) {
        return new ResponseEntity(new Result<>().ok(onlineAccountService.page(dto)), HttpStatus.OK);
    }

    /**
     * 踢【在线用户】下线
     *
     */
    @ApiOperation(value = "踢【在线用户】下线")
    @PostMapping("/kickOffline")
    public ResponseEntity<Result> kickOffLine(@Valid @RequestBody SearchDto dto) {
        onlineAccountService.kickOffLine(dto.getId());
        return new ResponseEntity(new Result<>().ok(), HttpStatus.OK);
    }
}
