namespace Tiobon.Core.Api.Controllers;

/// <summary>
/// 考试记录(Controller)
/// </summary>
[Route("api/[controller]")]
[ApiController, GlobalActionFilter]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)]
public class Ghre_ExamRecordController : BaseController<IGhre_ExamRecordServices, Ghre_ExamRecord, Ghre_ExamRecordDto, InsertGhre_ExamRecordInput, EditGhre_ExamRecordInput>
{
    public Ghre_ExamRecordController(IGhre_ExamRecordServices service) : base(service)
    {
    }


    #region 根据条件查询数据
    /// <summary>
    /// 根据条件查询数据
    /// </summary>
    /// <param name="examId">examId</param>
    /// <param name="body">条件</param>
    /// <returns></returns>
    [HttpPost, Route("QueryList/{examId}")]
    public async Task<ServicePageResult<Ghre_ExamRecordDto>> Query(string examId, [FromBody] QueryBody body)
    {
        return await _service.Query(examId, body);
    }

    #endregion

    [HttpPost("ModifyAdjustScore/{examRecordId}")]
    public async Task<ServiceResult> ModifyAdjustScore(string examRecordId, [FromBody] EditGhre_ExamRecordInput edit)
    {
        return await _service.ModifyAdjustScore(examRecordId, edit);
    }

    /// <summary>
    /// 获取考试记录明细扩展接口
    /// </summary>
    /// <param name="examRecordId"></param>
    /// <returns></returns>
    [HttpPost("QueryExtend/{examRecordId}")]
    public async Task<ServiceResult<Ghre_ExamRecordExtend>> ExtendAsync(long examRecordId)
    {
        return await _service.ExtendAsync(examRecordId);
    }

    /// <summary>
    /// 提交评语接口
    /// </summary>
    /// <param name="extend"></param>
    /// <param name="examRecordId"></param>
    /// <returns></returns>
    [HttpPost("Comment/{examRecordId}")]
    public async Task<ServiceResult> CommentAsync([FromBody] Ghre_ExamRecordExtend extend, long examRecordId)
    {
        return await _service.CommentAsync(extend, examRecordId);
    }


    /// <summary>
    /// 获取考试信息
    /// </summary>
    /// <param name="id">学习记录ID/考试记录ID</param> 
    /// <returns></returns>
    [HttpPost("QueryExam/{id}")]
    public async Task<ServiceResult<QueryExam>> QueryExamAsync(long id)
    {
        return await _service.QueryExamAsync(id);
    }

    /// <summary>
    /// 开始考试
    /// </summary> 
    /// <param name="examRecordId"></param>
    /// <returns></returns>
    [HttpPost("StartExam/{examRecordId}")]
    public async Task<ServiceResult> StartExamAsync(long examRecordId)
    {
        return await _service.StartExamAsync(examRecordId);
    }

    /// <summary>
    /// 重新考试
    /// </summary> 
    /// <param name="examRecordId"></param>
    /// <returns></returns>
    [HttpPost("RetakeExam/{examRecordId}")]
    public async Task<ServiceResult> RetakeExamAsync(long examRecordId)
    {
        return await _service.RetakeExamAsync(examRecordId);
    }


    /// <summary>
    /// 答题
    /// </summary> 
    /// <param name="studyRecordId">学习记录ID</param>
    /// <param name="answers"></param>
    /// <returns></returns>
    [HttpPost("AnswerExam/{studyRecordId}")]
    public async Task<ServiceResult> AnswerExamAsync(long studyRecordId, [FromBody] List<DefaultGhre_ExamPaperPreview> answers)
    {
        return await _service.AnswerExamAsync(answers, studyRecordId);
    }
}