using Microsoft.AspNetCore.Components;

using Front.Program.Models;
using Front.Program.Services;

namespace Front;

public partial class App : ComponentBase
{
    [Inject] private APIService API { get; set; } = default!;
    [Inject] private CookieService Cookie { get; set; } = default!;
    
    
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var cookie = await Cookie.GetCookieAsync("Web_AM_Connect_Key");

            // 값 없으면 API 호출
            if (string.IsNullOrEmpty(cookie))
            {
                var response = await API.GetJsonAsync<APIHeader, AppHeader>(
                    "/api/v1/in/app",
                    new AppHeader() 
                    {
                        type = "W",
                        specific = "Web_Connect",
                        project = "AcaMate"
                    });
                if (!string.IsNullOrEmpty(response.data.header))
                {
                    await Cookie.SetCookieAsync("Web_AM_Connect_Key", response.data.header);
                }
            }
        }
    }
}