package com.yinlihupo.enlish.service.controller;

import com.yinlihupo.enlish.service.domain.dataobject.VocabularyBankDO;
import com.yinlihupo.enlish.service.model.vo.vocabulary.FindStudentWordDetailReqVO;
import com.yinlihupo.enlish.service.model.vo.vocabulary.FindStudentWordDetailRspVO;
import com.yinlihupo.enlish.service.model.vo.vocabulary.FindWordTitleReqVO;
import com.yinlihupo.enlish.service.model.vo.vocabulary.FindWordTitleRspVO;
import com.yinlihupo.enlish.service.service.VocabularyService;
import com.yinlihupo.framework.biz.operationlog.aspect.ApiOperationLog;
import com.yinlihupo.framework.common.response.Response;
import jakarta.annotation.Resource;
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 java.util.List;

@RequestMapping("/vocabulary/")
@RestController
public class VocabularyController {

    @Resource
    private VocabularyService vocabularyService;

    @PostMapping("/list")
    @ApiOperationLog(description = "查询单词名称")
    public Response<FindWordTitleRspVO> findWordTitle(@RequestBody FindWordTitleReqVO vo) {
        List<VocabularyBankDO> vocabularyBankDOListById = vocabularyService.findVocabularyBankDOListById(vo.getIds());
        FindWordTitleRspVO findWordTitleRspVO = FindWordTitleRspVO.builder()
                .wordTitles(vocabularyBankDOListById.stream().map(VocabularyBankDO::getWord).toList())
                .build();
        return Response.success(findWordTitleRspVO);
    }

    @PostMapping("student/detail")
    @ApiOperationLog(description = "查询学生单词详情")
    public Response<FindStudentWordDetailRspVO> findStudentWordDetail(@RequestBody FindStudentWordDetailReqVO vo) {
        return Response.success(vocabularyService.findStudentWordDetail(vo.getId()));
    }

}
