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

namespace Application.Features.Admin.Crypto.Board.UnlinkBoard
{
    public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
    {
        public async Task Handle(Command request, CancellationToken ct)
        {
            var board = await db.Board.FirstOrDefaultAsync(b => b.ID == request.BoardID, ct);

            if (board is null)
            {
                throw new KeyNotFoundException("게시판을 찾을 수 없습니다.");
            }

            board.CoinID = null;
            await db.SaveChangesAsync(ct);
        }
    }
}