using System;
using System.Collections.Generic;
using System.Linq;
using Jellyfin.Data.Enums;
namespace ConfusedPolarBear.Plugin.IntroSkipper.Data;
///
/// Represents the state of an episode regarding analysis and blacklist status.
///
public class EpisodeState
{
private readonly Dictionary _states = [];
///
/// Initializes a new instance of the class.
///
public EpisodeState() =>
Array.ForEach(Enum.GetValues(), mode => _states[mode] = default);
///
/// Checks if the specified analysis mode has been analyzed.
///
/// The analysis mode to check.
/// True if the mode has been analyzed, false otherwise.
public bool IsAnalyzed(MediaSegmentType mode) => _states[mode].Analyzed;
///
/// Checks if the specified analysis mode has been blacklisted.
///
/// The analysis mode to check.
/// True if the mode has been blacklisted, false otherwise.
public bool IsBlacklisted(MediaSegmentType mode) => _states[mode].Blacklisted;
///
/// Sets the analyzed state for the specified analysis mode.
///
/// The analysis mode to set.
/// The analyzed state to set.
public void SetAnalyzed(MediaSegmentType mode, bool value) =>
_states[mode] = (value, _states[mode].Blacklisted);
///
/// Sets the blacklisted state for the specified analysis mode.
///
/// The analysis mode to set.
/// The blacklisted state to set.
public void SetBlacklisted(MediaSegmentType mode, bool value) =>
_states[mode] = (_states[mode].Analyzed, value);
///
/// Resets all states to their default values.
///
public void ResetStates() =>
Array.ForEach(Enum.GetValues(), mode => _states[mode] = default);
///
/// Gets all modes that have been analyzed.
///
/// An IEnumerable of analyzed MediaSegmentTypes.
public IEnumerable GetAnalyzedModes() =>
_states.Where(kvp => kvp.Value.Analyzed).Select(kvp => kvp.Key);
///
/// Gets all modes that have been blacklisted.
///
/// An IEnumerable of blacklisted MediaSegmentTypes.
public IEnumerable GetBlacklistedModes() =>
_states.Where(kvp => kvp.Value.Blacklisted).Select(kvp => kvp.Key);
}