package com.kexue.skills.controller;

import com.kexue.skills.common.CommonResult;
import com.kexue.skills.entity.dto.SessionDto;
import com.kexue.skills.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Session管理控制器
 *
 * @author 王志维
 * @since 2026-03-12
 */
@RestController
@RequestMapping("api/session")
@Tag(name = "Session管理 Api")
@CrossOrigin(origins = "*")
public class SessionController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;

    /**
     * 创建或获取用户会话
     *
     * @param userId 包含用户ID的DTO对象
     * @return 会话信息，包含sessionId和isNew字段
     */
    @GetMapping("/createSession")
    @Operation(summary = "创建或获取会话", description = "根据用户ID创建或获取会话信息")
    public CommonResult<SessionDto> createSession(@RequestParam Long userId) {
        SessionDto sessionDto = sysUserService.createSession(userId);
        return CommonResult.success(sessionDto);
    }
}
