using AyCode.Core.Interfaces;
using AyCode.Database.DbContexts;
using AyCode.Database.DbSets.Users;
using AyCode.Entities;
using AyCode.Interfaces;
using AyCode.Interfaces.Entities;
using Microsoft.EntityFrameworkCore;

namespace AyCode.Database.Extensions;

public static class AcDbModelDtoExtension
{
    public static TModelDto? GetModelDtoById<TModelDto, TEntity>(this AcDbContextBase ctx, Guid id) where TModelDto : class, IAcModelDtoBase where TEntity : class, IEntity
        => ctx.Set<TEntity>().Find(id)?.ToModelDto<TModelDto, TEntity>();

    public static IEnumerable<TModelDto> GetAllModelDto<TModelDto, TEntity>(this AcDbContextBase ctx) where TModelDto : class, IAcModelDtoBase where TEntity : class, IEntity
        => ctx.Set<TEntity>().ToModelDto<TModelDto, TEntity>();
}