using Tornado3_2026Election.Common;

namespace Tornado3_2026Election.Domain;

public sealed class CutDebugSettings : ObservableObject
{
    private bool _isFeatureEnabled = true;
    private bool _isEnabled;
    private bool _applyTextValues = true;
    private bool _applyImageValues = true;
    private bool _applyVisibilityValues = true;
    private bool _applyVoteRateTextValues = true;
    private bool _applyVoteRateCounterValues = true;
    private bool _applyPartyBarStyleColors = true;
    private bool _applyPartyPlateStyleColors = true;
    private bool _applyVoteRateStyleColors = true;

    public bool IsFeatureEnabled
    {
        get => _isFeatureEnabled;
        set
        {
            if (SetProperty(ref _isFeatureEnabled, value))
            {
                OnPropertyChanged(nameof(IsEffectiveEnabled), nameof(Summary));
            }
        }
    }

    public bool IsEnabled
    {
        get => _isEnabled;
        set
        {
            if (SetProperty(ref _isEnabled, value))
            {
                OnPropertyChanged(nameof(IsEffectiveEnabled), nameof(Summary));
            }
        }
    }

    public bool IsEffectiveEnabled => IsFeatureEnabled && IsEnabled;

    public bool ApplyTextValues
    {
        get => _applyTextValues;
        set
        {
            if (SetProperty(ref _applyTextValues, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyImageValues
    {
        get => _applyImageValues;
        set
        {
            if (SetProperty(ref _applyImageValues, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyVisibilityValues
    {
        get => _applyVisibilityValues;
        set
        {
            if (SetProperty(ref _applyVisibilityValues, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyVoteRateTextValues
    {
        get => _applyVoteRateTextValues;
        set
        {
            if (SetProperty(ref _applyVoteRateTextValues, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyVoteRateCounterValues
    {
        get => _applyVoteRateCounterValues;
        set
        {
            if (SetProperty(ref _applyVoteRateCounterValues, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyPartyBarStyleColors
    {
        get => _applyPartyBarStyleColors;
        set
        {
            if (SetProperty(ref _applyPartyBarStyleColors, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyPartyPlateStyleColors
    {
        get => _applyPartyPlateStyleColors;
        set
        {
            if (SetProperty(ref _applyPartyPlateStyleColors, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public bool ApplyVoteRateStyleColors
    {
        get => _applyVoteRateStyleColors;
        set
        {
            if (SetProperty(ref _applyVoteRateStyleColors, value))
            {
                OnPropertyChanged(nameof(Summary));
            }
        }
    }

    public string Summary => !IsEnabled
        ? "디버그 OFF - 현재와 동일하게 전체 송출"
        : $"텍스트 {ToOnOff(ApplyTextValues)}, 이미지 {ToOnOff(ApplyImageValues)}, 표시/숨김 {ToOnOff(ApplyVisibilityValues)}, 득표율 텍스트 {ToOnOff(ApplyTextValues && ApplyVoteRateTextValues)}, 득표율 카운터 {ToOnOff(ApplyVoteRateCounterValues)}, 정당 바/막대 색상 {ToOnOff(ApplyPartyBarStyleColors)}, 정당 판/문자 색상 {ToOnOff(ApplyPartyPlateStyleColors)}, 득표율 색상 {ToOnOff(ApplyVoteRateStyleColors)}";

    public CutDebugSettingsSnapshot CreateSnapshot()
    {
        return new CutDebugSettingsSnapshot(
            IsEffectiveEnabled,
            ApplyTextValues,
            ApplyImageValues,
            ApplyVisibilityValues,
            ApplyVoteRateTextValues,
            ApplyVoteRateCounterValues,
            ApplyPartyBarStyleColors,
            ApplyPartyPlateStyleColors,
            ApplyVoteRateStyleColors);
    }

    private static string ToOnOff(bool value) => value ? "ON" : "OFF";
}

public readonly record struct CutDebugSettingsSnapshot(
    bool IsEnabled,
    bool ApplyTextValues,
    bool ApplyImageValues,
    bool ApplyVisibilityValues,
    bool ApplyVoteRateTextValues,
    bool ApplyVoteRateCounterValues,
    bool ApplyPartyBarStyleColors,
    bool ApplyPartyPlateStyleColors,
    bool ApplyVoteRateStyleColors);
