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

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

public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response?>
{
    public async Task<Response?> Handle(Query request, CancellationToken ct)
    {
        return await db.Channel
            .AsNoTracking()
            .Include(c => c.Member)
            .Where(c => c.ID == request.ID)
            .Select(c => new Response
            {
                ID = c.ID,
                MemberID = c.MemberID,
                MemberEmail = c.Member.Email,
                MemberName = c.Member.Name,
                MemberSID = c.Member.SID,
                SID = c.SID,
                Name = c.Name,
                Handle = c.Handle,
                YouTubeUrl = c.YouTubeUrl,
                PlatformFeeRate = c.PlatformFeeRate,
                IsVerified = c.IsVerified,
                IsActive = c.IsActive,
                UpdatedAt = c.UpdatedAt,
                CreatedAt = c.CreatedAt
            })
            .FirstOrDefaultAsync(ct);
    }
}