namespace YBEE.EQM.Application;

/// <summary>
/// 统计报表之分数段报表服务
/// </summary>
[ApiDescriptionSettings(Name = "exam-reporting-avg-range")]
[Route("exam/reporting/avg/range")]
public class ExamReportingAvgRangeAppService : IDynamicApiController
{
    private readonly IExamReportingAvgRangeService _examReportingAvgRangeService;

    public ExamReportingAvgRangeAppService(IExamReportingAvgRangeService examReportingAvgRangeService)
    {
        _examReportingAvgRangeService = examReportingAvgRangeService;
    }

    /// <summary>
    /// 导出表格
    /// </summary>
    /// <param name="examPlanId">监测计划ID</param>
    /// <returns></returns>
    [AllowAnonymous]
    public async Task<IActionResult> Export([FromQuery][Required] int examPlanId)
    {
        var (fileName, fileBytes) = await _examReportingAvgRangeService.Export(examPlanId);
        return new FileContentResult(fileBytes, "application/octet-stream")
        {
            FileDownloadName = fileName,
        };
    }
}
