using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudGaming.Code.Game;

/// <summary>
/// 玩游戏服务
/// </summary>
/// <param name="serviceProvider"></param>
public class PlayGameService(IServiceProvider serviceProvider) : IHostedService
{
    PlayGameProcessor? playGameProcessor = null;
    public Task StartAsync(CancellationToken cancellationToken)
    {
        AppConfigurationExtend.AppConfigs.Select(it => it.Value).Where(it => it.DomainName != "default").ToList();
        //throw new NotImplementedException();
        playGameProcessor = new PlayGameProcessor(serviceProvider) { };
        playGameProcessor.Run();
        return Task.CompletedTask;
    }

    public Task StopAsync(CancellationToken cancellationToken)
    {
        if (playGameProcessor != null)
        {
            playGameProcessor.Stop();
            playGameProcessor.Dispose();
        }
        return Task.CompletedTask;
    }
}
