using Fantasy;
using Fantasy.Async;
using NB.Common;

namespace NB.Game;

public static class CacheHandler
{
    /// <summary>
    /// 查询玩家基础信息
    /// </summary>
    /// <param name="scene"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public static async FTask<List<RoleSimpleInfo>> GetPlayerBasicCacheInfos(Scene scene, List<long> id)
    {
        var gameSceneConfig = SceneConfigHelper.GetConfig(SceneType.Game);
        var gameRouteId = gameSceneConfig.RouteId;
        //连接到游戏中心服
        var gameResponse = (G2S_GetPlayerBasicInfoResponse)await scene.NetworkMessagingComponent.CallInnerRoute(
            gameRouteId, new S2G_GetPlayerBasicInfoRequest()
            {
                IdList = id
            });

        if (gameResponse.ErrorCode != 0)
        {
            return new List<RoleSimpleInfo>();
        }

        return gameResponse.RoleList;
    }

    /// <summary>
    /// 获取玩家基础信息
    /// </summary>
    /// <param name="scene"></param>
    /// <param name="id"></param>
    /// <returns></returns>
    public static async FTask<RoleSimpleInfo?> GetPlayerBasicCacheInfo(Scene scene, long id)
    {
        var list = await GetPlayerBasicCacheInfos(scene, [id]);
        if (list.Count > 0)
        {
            return list[0];
        }

        return null;
    }
}