using CloudGaming.AppConfigModel;
using CloudGaming.Code.AppExtend;
using CloudGaming.Code.Game;

using HuanMeng.DotNetCore.Utility;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace CloudGaming.Web.Pages.Handle;

public class IndexModel : PageModel
{
    /// <summary>
    ///  
    /// </summary>
    private IServiceProvider ServiceProvider { get; set; }

    public IndexModel(IServiceProvider _serviceProvider)
    {
        ServiceProvider = _serviceProvider;
    }

    /// <summary>
    /// 游戏Id
    /// </summary>
    public string GameId { get; set; }
    /// <summary>
    /// 用户Id
    /// </summary>
    public int UserId { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public string IP { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string Sn { get; set; }
    /// <summary>
    /// app配置
    /// </summary>
    public AppConfig AppConfig { get; set; }
    public void OnGet(string identifier, int userId, string gameId)
    {
        Sn = Guid.NewGuid().ToString("N");
        this.GameId = gameId;
        this.UserId = userId;
        if (string.IsNullOrEmpty(identifier))
        {
            return;
        }
        if (identifier.ToLower() == "cloudgaming")
        {
            identifier = "default";
        }

        var app = AppConfigurationExtend.GetAppConfigIdentifier(identifier);
        if (app == null)
        {
            return;
        }
        var appConfig = ServiceProvider.GetRequiredService<AppConfig>();
        app.ToAppConfig(appConfig);
        this.AppConfig = appConfig;
        CloudGamingBase cloudGamingBase = new CloudGamingBase(ServiceProvider);
        IP = cloudGamingBase.HttpContextAccessor.HttpContext.GetClientIpAddress();
        //PlayGameBLL playGameBLL = new PlayGameBLL(ServiceProvider); 
    }
}
