using DramaLing.Api.Services;
using DramaLing.Api.Contracts.Services.Core;
using Microsoft.AspNetCore.Mvc;
namespace DramaLing.Api.Controllers;
///
/// 選項詞彙庫服務測試控制器 (僅用於開發測試)
///
[Route("api/test/[controller]")]
public class OptionsVocabularyTestController : BaseController
{
private readonly IOptionsVocabularyService _optionsVocabularyService;
public OptionsVocabularyTestController(
IOptionsVocabularyService optionsVocabularyService,
ILogger logger) : base(logger)
{
_optionsVocabularyService = optionsVocabularyService;
}
///
/// 測試智能干擾選項生成
///
[HttpGet("generate-distractors")]
public async Task TestGenerateDistractors(
[FromQuery] string targetWord = "beautiful",
[FromQuery] string cefrLevel = "B1",
[FromQuery] string partOfSpeech = "adjective",
[FromQuery] int count = 3)
{
try
{
var distractors = await _optionsVocabularyService.GenerateDistractorsAsync(
targetWord, cefrLevel, partOfSpeech, count);
return Ok(new
{
success = true,
targetWord,
cefrLevel,
partOfSpeech,
requestedCount = count,
actualCount = distractors.Count,
distractors
});
}
catch (Exception ex)
{
_logger.LogError(ex, "測試生成干擾選項失敗");
return StatusCode(500, new { success = false, error = ex.Message });
}
}
///
/// 測試詞彙庫充足性檢查
///
[HttpGet("check-sufficiency")]
public async Task TestVocabularySufficiency(
[FromQuery] string cefrLevel = "B1",
[FromQuery] string partOfSpeech = "adjective")
{
try
{
var hasSufficient = await _optionsVocabularyService.HasSufficientVocabularyAsync(
cefrLevel, partOfSpeech);
return Ok(new
{
success = true,
cefrLevel,
partOfSpeech,
hasSufficientVocabulary = hasSufficient
});
}
catch (Exception ex)
{
_logger.LogError(ex, "測試詞彙庫充足性檢查失敗");
return StatusCode(500, new { success = false, error = ex.Message });
}
}
///
/// 測試帶詳細資訊的干擾選項生成
///
[HttpGet("generate-distractors-detailed")]
public async Task TestGenerateDistractorsWithDetails(
[FromQuery] string targetWord = "beautiful",
[FromQuery] string cefrLevel = "B1",
[FromQuery] string partOfSpeech = "adjective",
[FromQuery] int count = 3)
{
try
{
var distractorsWithDetails = await _optionsVocabularyService.GenerateDistractorsWithDetailsAsync(
targetWord, cefrLevel, partOfSpeech, count);
var result = distractorsWithDetails.Select(d => new
{
d.Word,
d.CEFRLevel,
d.PartOfSpeech,
d.WordLength,
d.IsActive
}).ToList();
return Ok(new
{
success = true,
targetWord,
cefrLevel,
partOfSpeech,
requestedCount = count,
actualCount = result.Count,
distractors = result
});
}
catch (Exception ex)
{
_logger.LogError(ex, "測試生成詳細干擾選項失敗");
return StatusCode(500, new { success = false, error = ex.Message });
}
}
///
/// 測試多種詞性的詞彙庫覆蓋率
///
[HttpGet("coverage-test")]
public async Task TestVocabularyCoverage()
{
try
{
var testCases = new[]
{
new { CEFR = "A1", PartOfSpeech = "noun" },
new { CEFR = "A1", PartOfSpeech = "verb" },
new { CEFR = "A1", PartOfSpeech = "adjective" },
new { CEFR = "B1", PartOfSpeech = "noun" },
new { CEFR = "B1", PartOfSpeech = "verb" },
new { CEFR = "B1", PartOfSpeech = "adjective" },
new { CEFR = "B2", PartOfSpeech = "noun" },
new { CEFR = "C1", PartOfSpeech = "noun" }
};
var results = new List