package com.usky.ai.controller.web;

import com.usky.ai.mapper.AiQuestionMapper;
import com.usky.ai.domain.AiQuestion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/questions")
public class AiQuestionController {

    @Autowired
    private AiQuestionMapper aiQuestionMapper;

    // 查询所有数据
    @GetMapping("/all")
    public List<AiQuestion> getAllQuestions() {
        return aiQuestionMapper.findAll();
    }

    // 根据 userId 查询数据
    @GetMapping("/user/{userId}")
    public List<AiQuestion> getQuestionsByUserId(@PathVariable Long userId) {
        return aiQuestionMapper.findByUserId(userId);
    }

    // 根据 id 删除数据
    @DeleteMapping("/deleted/{id}")
    public String deleteQuestion(@PathVariable Long id) {
        aiQuestionMapper.deleteById(id);
        return "Question with id " + id + " deleted successfully.";
    }

    // 根据 sessionId 查询数据
    @GetMapping("/session/{sessionId}")
    public List<AiQuestion> getQuestionsBySessionId(@PathVariable String sessionId) {
        return aiQuestionMapper.findBySessionId(sessionId);
    }
}
