package ink.wgink.module.instantmessage.controller.app;

import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.instantmessage.service.IWebSocketClientService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: WebSocketClientAppController
 * @Description: WebSocket客户端
 * @Author: wanggeng
 * @Date: 2021/9/12 4:15 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "websocket客户端")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/websocket/client")
public class WebSocketClientAppController {

    @Autowired
    private IWebSocketClientService webSocketClientService;

    @ApiOperation(value = "登录", notes = "登录接口，返回userId(sessionId)")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("login/{clientName}")
    public SuccessResultData<String> login(@RequestHeader("token") String token, @PathVariable("clientName") String clientName) {
        System.out.println(">>>> token：" + token);
        String sessionId = webSocketClientService.login(token, clientName);
        return new SuccessResultData<>(sessionId);
    }

}
