using Application.Abstractions.Messaging;
using Application.Abstractions.Data;
using Microsoft.EntityFrameworkCore;

namespace Application.Features.Admin.Forum.Board.Get;

public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
{
    public async Task<Response> Handle(Query request, CancellationToken ct)
    {
        var item = await db.Board.AsNoTracking().FirstOrDefaultAsync(x => x.ID == request.ID, ct);
        if (item is null)
        {
            throw new KeyNotFoundException("게시판을 찾을 수 없습니다.");
        }

        return new Response(
            item.ID,
            item.BoardGroupID,
            item.Code,
            item.Name,
            item.Order,
            item.IsSearch,
            item.IsActive,
            item.UpdatedAt,
            item.CreatedAt
        );
    }
}