using SharedKernel.Extensions;
using Application.Abstractions.Messaging;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Admin.Pages.Channel.List
{
    public class ViewModel(IMediator mediator) : PageModel
    {
        public int ID { get; set; }
        public int MemberID { get; set; }
        public string? MemberInfo { get; set; }
        public string SID { get; set; } = default!;
        public string Name { get; set; } = default!;
        public string? Handle { get; set; }
        public string YouTubeUrl { get; set; } = default!;
        public decimal PlatformFeeRate { get; set; }
        public bool IsVerified { get; set; }
        public bool IsActive { get; set; }
        public string? UpdatedAt { get; set; }
        public string CreatedAt { get; set; } = default!;

        public async Task OnGetAsync(int id, CancellationToken ct)
        {
            var result = await mediator.Send(new GetChannel.Query(id), ct);
            if (result is null)
            {
                return;
            }

            ID = result.ID;
            MemberID = result.MemberID;
            MemberInfo = $"[{result.MemberID}] {result.MemberEmail}, {result.MemberName ?? result.MemberSID ?? "-"}";
            SID = result.SID;
            Name = result.Name;
            Handle = result.Handle;
            YouTubeUrl = result.YouTubeUrl;
            PlatformFeeRate = result.PlatformFeeRate;
            IsVerified = result.IsVerified;
            IsActive = result.IsActive;
            UpdatedAt = result.UpdatedAt.GetDateAt();
            CreatedAt = result.CreatedAt.GetDateAt();
        }
    }
}