using AyCode.Interfaces;
using AyCode.Interfaces.Entities;

namespace AyCode.Entities;

public static class AcModelDtoExtension
{
    public static TModelDto? ToModelDto<TModelDto, TEntity>(this TEntity entity) where TModelDto : class, IAcModelDtoBaseEmpty where TEntity : class, IEntity
        => Activator.CreateInstance(typeof(TModelDto), entity) as TModelDto;
    
    public static IEnumerable<TModelDto> ToModelDto<TModelDto, TEntity>(this IEnumerable<TEntity> entities) where TModelDto : class, IAcModelDtoBaseEmpty where TEntity : class, IEntity
        => entities.Select(entity => entity.ToModelDto<TModelDto, TEntity>())!;
}