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

namespace Application.Features.Admin.Channel.List.Update;

public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
{
    public async Task Handle(Command request, CancellationToken ct)
    {
        var channel = await db.Channel.FirstOrDefaultAsync(c => c.ID == request.ID, ct);
        if (channel is null)
        {
            throw new Exception("채널을 찾을 수 없습니다.");
        }

        channel.Update(
            request.Name,
            request.Handle,
            request.YouTubeUrl,
            request.PlatformFeeRate,
            request.IsVerified,
            request.IsActive
        );

        await db.SaveChangesAsync(ct);
    }
}