using System.Collections.Concurrent;
using Hc900Crawler.Core.Application.Feedforward;

namespace Hc900Crawler.Infrastructure.Control;

/// <summary>측류 스트림별 추종 상태 인메모리 저장소(싱글턴).</summary>
public sealed class FfTrackingStore : IFfTrackingStore
{
    private readonly ConcurrentDictionary<(int, string), FfTrackingState> _states = new();

    public void Set(FfTrackingState state) => _states[(state.ColumnId, state.StreamKey)] = state;

    public bool IsEnabled(int columnId, string streamKey)
        => _states.TryGetValue((columnId, streamKey), out var s) && s.Enabled;

    public FfTrackingState? Get(int columnId, string streamKey)
        => _states.TryGetValue((columnId, streamKey), out var s) ? s : null;

    public IReadOnlyCollection<FfTrackingState> GetAll() => _states.Values.ToArray();
}
