using YBEE.EQM.Core;

namespace YBEE.EQM.Application;

/// <summary>
/// 学制管理服务
/// </summary>
public class EducationStageYearsService : IEducationStageYearsService, ITransient
{
    private readonly IRepository<EducationStageYears> _rep;
    public EducationStageYearsService(IRepository<EducationStageYears> rep)
    {
        _rep = rep;
    }

    /// <summary>
    /// 根据学段获取学制
    /// </summary>
    /// <param name="educationStage"></param>
    /// <returns></returns>
    public async Task<EducationStageYearsOutput> GetByEducationStage(EducationStage educationStage)
    {
        var item = await _rep.DetachedEntities.FirstOrDefaultAsync(t => t.EducationStage == educationStage);
        return item.Adapt<EducationStageYearsOutput>();
    }
    /// <summary>
    /// 获取学制列表
    /// </summary>
    /// <returns></returns>
    public async Task<List<EducationStageYearsOutput>> GetAllList()
    {
        var items = await _rep.DetachedEntities.ProjectToType<EducationStageYearsOutput>().ToListAsync();
        return items;
    }
    /// <summary>
    /// 获取学制字典
    /// </summary>
    /// <returns></returns>
    public async Task<Dictionary<EducationStage, EducationStageYearsOutput>> GetAllDictionary()
    {
        var items = await GetAllList();
        return items.ToDictionary(t => t.EducationStage);
    }
}
