namespace ytLive.Services.Audio;

/// <summary>
/// Supplies the live-mix gain values (mic + loopback) as Func seams for
/// <see cref="AudioMixer"/>, sourced from the VM's volume/mute state. Read live
/// on every mix tick so slider drags and mutes take effect immediately on the
/// stream. Mute and zero volume can never disagree: 0 always reads as muted.
/// </summary>
public sealed class AudioGainProvider
{
    private readonly Func<bool> _micMuted;
    private readonly Func<double> _micVolume;
    private readonly Func<bool> _gameMuted;
    private readonly Func<double> _gameVolume;

    public AudioGainProvider(
        Func<bool> micMuted,
        Func<double> micVolume,
        Func<bool> gameMuted,
        Func<double> gameVolume)
    {
        _micMuted = micMuted;
        _micVolume = micVolume;
        _gameMuted = gameMuted;
        _gameVolume = gameVolume;
    }

    /// <summary>Mic gain for the live mix (0 = muted).</summary>
    public double MicGain() => _micMuted() ? 0 : _micVolume();

    /// <summary>Loopback (desktop/game) gain for the live mix (0 = muted).</summary>
    public double LoopbackGain() => _gameMuted() ? 0 : _gameVolume();
}
