using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Contracts;
using Tiku.Api.Security;
using Tiku.Application.Learning;
using Tiku.Application.Security;

namespace Tiku.Api.Controllers;

[ApiController]
[Tags("学生端-学习")]
[Authorize(Policy = TikuPolicies.CurrentTenantMember)]
[RequireSaasFeature(SaasFeatureCatalog.Practice)]
[Produces("application/json")]
[Route("api/student/learning")]
public sealed class AnsweringController(
    IAnsweringService service,
    LearningActorResolver actorResolver) : ControllerBase
{
    [HttpPost("answers")]
    [EndpointSummary("提交题目答案")]
    [ProducesResponseType<AnswerRecordItem>(StatusCodes.Status200OK)]
    [ProducesResponseType<ProblemDetails>(StatusCodes.Status401Unauthorized)]
    [ProducesResponseType<ProblemDetails>(StatusCodes.Status403Forbidden)]
    [ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
    public async Task<ActionResult<AnswerRecordItem>> SubmitAnswer(
        SubmitAnswerDto request,
        CancellationToken cancellationToken)
    {
        return Ok(await service.SubmitAnswerAsync(
            actorResolver.Resolve(),
            request.ToCommand(),
            cancellationToken));
    }
}
