using Application.Abstractions.Messaging;
﻿using Application.Abstractions.Data;

namespace Application.Features.Admin.Document.Get
{
    public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response?>
    {
        public async Task<Response?> Handle(Query request, CancellationToken ct)
        {
            var document = await db.Document.FindAsync(request.ID, ct);
            if (document is null)
            {
                return null;
            }

            return new Response
            {
                ID = document.ID,
                Code = document.Code,
                Subject = document.Subject,
                Content = document.Content,
                IsActive = document.IsActive,
                UpdatedAt = document.UpdatedAt,
                CreatedAt = document.CreatedAt
            };
        }
    }
}