using CMSMicroservice.Protobuf.Protos.User;
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;

namespace FrontOffice.Main.Pages.Profile;

public partial class Hub
{
    [Inject] private UserContract.UserContractClient UserContract { get; set; } = default!;

    private GetUserResponse _userProfile = new();

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (firstRender)
        {
            await LoadUserProfile();
        }
    }

    private async Task LoadUserProfile()
    {
        try
        {
            _userProfile = await UserContract.GetUserAsync(request: new());
        }
        catch
        {
            _userProfile = new GetUserResponse();
        }
        StateHasChanged();
    }
}
