namespace Netina.Repository.Handlers.Faqs;

public class GetFaqQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper)
    : IRequestHandler<GetFaqQuery, BaseFaq>
{
    public async Task<BaseFaq> Handle(GetFaqQuery request, CancellationToken cancellationToken)
    {
        if (request.Id is not null)
        {
            var ent = await martenRepositoryWrapper.SetRepository<BaseFaq>()
                .GetEntityAsync(request.Id.Value, cancellationToken);
            if (ent == null)
                return new BaseFaq();
            return ent;
        }else if (request.Slug != null)
        {
            var htmlSlug = request.Slug;
            var ent = await martenRepositoryWrapper.SetRepository<BaseFaq>()
                .GetEntityAsync(f=>f.Slug == htmlSlug, cancellationToken);
            if (ent == null)
                return new BaseFaq();
            return ent;

        }
        return new BaseFaq();
    }
}