using CounterStrikeSharp.API.Core;
using FabiusTimer.Configs;
using FabiusTimer.Models;
using FabiusTimerApi.Enums;
using FabiusTimerApi.Models;

namespace FabiusTimer.Managers;

public class MapManager
{
    private readonly Plugin _plugin;
    private readonly Database _database;
    private readonly ZonesManager _zonesManager;
    private readonly ZoneInstance _zoneInstance;
    private readonly Config<StyleConfig> _styleConfig;

    private Dictionary<Route, Dictionary<Style, List<Record>>> TotalRecords { get; } = new();
    private Dictionary<Route, Dictionary<Style, Record>> WorldRecords { get; } = new();

    public MapManager(Plugin plugin, Database database, EventManager eventManager, ZonesManager zonesManager,
        ZoneInstance zoneInstance, Config<StyleConfig> styleConfig)
    {
        _plugin = plugin;
        _database = database;
        _zonesManager = zonesManager;
        _zoneInstance = zoneInstance;
        _styleConfig = styleConfig;

        eventManager.RegisterEvent<EventRoundStart>(EventRoundStart);
        eventManager.RegisterListener<Listeners.OnMapStart>(OnMapStart);
    }

    private HookResult EventRoundStart(EventRoundStart @event, GameEventInfo info)
    {
        foreach (var zone in _zoneInstance)
        {
            foreach (var positions in zone.Value)
            {
                _zonesManager.DrawWireframe(positions, zone.Key.Item1, zone.Key.Item2);
            }
        }

        return HookResult.Continue;
    }

    private void OnMapStart(string map)
    {
        _zoneInstance.Clear();
        Task.Run(() => OnMapStartAsync(map));
    }

    private async Task OnMapStartAsync(string map)
    {
        await _zoneInstance.LoadZonesAsync(map);
        
        var records = await _database.GetAllRecordsAsync(map);
        if (records == null) return;

        TotalRecords.Clear();
        foreach (var record in records)
        {
            var style = _styleConfig.Value.GetStyle(record.Style);
            if (style is null) continue;

            if (!TotalRecords.TryGetValue(record.Route, out var routeRecords))
            {
                routeRecords = new Dictionary<Style, List<Record>>();
                TotalRecords[record.Route] = routeRecords;
            }

            if (!routeRecords.TryGetValue(style, out var recordsList))
            {
                recordsList = new List<Record>();
                routeRecords[style] = recordsList;
            }

            recordsList.Add(record);
        }

        WorldRecords.Clear();
        foreach (var route in TotalRecords)
        {
            foreach (var stylePair in route.Value)
            {
                var bestRecord = stylePair.Value.OrderBy(r => r.Time).FirstOrDefault();
                if (bestRecord != null)
                {
                    if (!WorldRecords.TryGetValue(route.Key, out var styleRecords))
                    {
                        styleRecords = new Dictionary<Style, Record>();
                        WorldRecords[route.Key] = styleRecords;
                    }

                    styleRecords[stylePair.Key] = bestRecord;
                }
            }
        }
    }

    public int GetTotalRecordCount(Style? style, Route route)
    {
        if (style is null) return 0;
        if (TotalRecords.TryGetValue(route, out var routeRecords) && routeRecords.TryGetValue(style, out var records))
        {
            return records.Count;
        }

        return 0;
    }

    public Record? GetWorldRecord(Style? style, Route route)
    {
        if (style is null) return null;
        if (WorldRecords.TryGetValue(route, out var routeRecords) && routeRecords.TryGetValue(style, out var record))
        {
            return record;
        }

        return null;
    }
}

добавь метод для получения позиции игрока

можно принимать string steamId и сверять со стим айди в Record