using YBEE.EQM.Core;

namespace YBEE.EQM.Application;

/// <summary>
/// 监测教师管理服务
/// </summary>
[ApiDescriptionSettings(Name = "exam-teacher")]
[Route("exam/teacher")]
public class ExamTeacherAppService : IDynamicApiController
{
    private readonly IExamTeacherService _examTeacherService;
    public ExamTeacherAppService(IExamTeacherService examTeacherService)
    {
        _examTeacherService = examTeacherService;
    }

    #region 批量导入
    /// <summary>
    /// 上传监测教师批量导入文件
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [RequestSizeLimit(long.MaxValue)]
    [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
    public async Task<UploadExamDataOutput<UploadExamTeacherOutput>> Upload([FromForm] UploadExamDataInput input)
    {
        string fileExt = Path.GetExtension(input.File.FileName).ToLower();
        if (fileExt != ".xls" && fileExt != ".xlsx")
        {
            throw Oops.Oh(ErrorCode.E1010);
        }

        string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
        using FileStream fs = File.Create(filePath);
        await input.File.CopyToAsync(fs);
        await fs.FlushAsync();
        fs.Close();

        var ret = await _examTeacherService.Upload(filePath, input.ExamPlanId);
        return ret;
    }
    /// <summary>
    /// 批量导入监测教师
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Import(ImportExamTeacherInput input)
    {
        await _examTeacherService.Import(input);
    }
    #endregion

    #region 创建编辑
    /// <summary>
    /// 添加监测教师
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Add(AddExamTeacherInput input)
    {
        await _examTeacherService.Add(input);
    }
    /// <summary>
    /// 更新监测教师
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Update(UpdateExamTeacherInput input)
    {
        await _examTeacherService.Update(input);
    }
    /// <summary>
    /// 删除监测教师
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Del(BaseId input)
    {
        await _examTeacherService.Del(input);
    }
    /// <summary>
    /// 清空监测教师
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Clear(ClearExamTeacherInput input)
    {
        await _examTeacherService.Clear(input);
    }
    #endregion

    #region 查询统计
    /// <summary>
    /// 分页查询监测教师列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<PageResult<ExamTeacherOutput>> QueryPageList(ExamTeacherPageInput input)
    {
        return await _examTeacherService.QueryPageList(input);
    }
    #endregion
}
