using System.Collections.ObjectModel;
using System.ComponentModel;
using GalaxyBudsClient.Model.Constants;
using ReactiveUI;

namespace GalaxyBudsClient.Model.Config;

/*
 * TODO: Workaround for the lack of support for source generator chaining
 *
 * We are still using the deprecated ReactiveUI.Fody package here.
 * The newer source generator solution will conflict with the System.Text.Json source generator.
 * Source generators cannot see code generated by other source generators, therefore the partial classes generated by
 * ReactiveUI.SourceGenerators will not be visible to the System.Text.Json source generator.
 * JSON serialization will fail. The JSON source generator is needed for AOT compilation support (Android).
 */


public class TouchAction : ReactiveObject
{
    [ReactiveUI.Fody.Helpers.Reactive] public CustomActions Action { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public string Parameter { set; get; } = string.Empty;
}

public class Device : ReactiveObject
{
    [ReactiveUI.Fody.Helpers.Reactive] public Models Model { set; get; } = Models.NULL;
    [ReactiveUI.Fody.Helpers.Reactive] public string MacAddress { set; get; } = string.Empty;
    [ReactiveUI.Fody.Helpers.Reactive] public string Name { set; get; } = string.Empty;
    [ReactiveUI.Fody.Helpers.Reactive] public DeviceIds? DeviceColor { set; get; }
}
    
/*
 * Properties annotated with [ReadOnly] should not be re-assigned after initialization.
 * They cannot be marked as init-only because the JSON source generator doesn't support it.
 */
public class SettingsData : ReactiveObject
{
    /* Appearance */
    [ReactiveUI.Fody.Helpers.Reactive] public Themes Theme { set; get; } = Settings.DefaultTheme;
    [ReactiveUI.Fody.Helpers.Reactive] public uint AccentColor { set; get; } = Avalonia.Media.Colors.Orange.ToUInt32();
    [ReactiveUI.Fody.Helpers.Reactive] public int BlurStrength { set; get; } = 144;
    [ReactiveUI.Fody.Helpers.Reactive] public Locales Locale { set; get; } = Locales.en;
    [ReactiveUI.Fody.Helpers.Reactive] public TemperatureUnits TemperatureUnit { set; get; } = TemperatureUnits.Celsius;
    [ReactiveUI.Fody.Helpers.Reactive] public bool RealisticEarbudImages { set; get; } = true;
    [ReactiveUI.Fody.Helpers.Reactive] public bool ShowSidebar { set; get; } = Settings.DefaultShowSidebar;
    [ReactiveUI.Fody.Helpers.Reactive] public DeviceIds? ColorOverride { set; get; }
    
    /* Connections */
    [ReactiveUI.Fody.Helpers.Reactive] public bool UseBluetoothWinRt { set; get; } = true;
    [ReadOnly(true)] public ObservableCollection<Device> Devices { set; get; } = [];
    [ReactiveUI.Fody.Helpers.Reactive] public string? LastDeviceMac { set; get; }

    
    /* Touch actions */
    [ReadOnly(true)] public TouchAction CustomActionLeft { set; get; } = new();
    [ReadOnly(true)] public TouchAction CustomActionRight { set; get; } = new();

    /* Tray icon */
    [ReactiveUI.Fody.Helpers.Reactive] public bool MinimizeToTray { set; get; } = true;
    [ReactiveUI.Fody.Helpers.Reactive] public DynamicTrayIconModes DynamicTrayIconMode { set; get; }

    /* Connection popup */
    [ReactiveUI.Fody.Helpers.Reactive] public bool PopupEnabled { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public bool PopupCompact { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public PopupPlacement PopupPlacement { set; get; } = PopupPlacement.BottomRight;
    
    /* Hotkey actions */
    [ReadOnly(true)] public ObservableCollection<Hotkey> Hotkeys { set; get; } = [];
    
    /* Crowdsourcing */
    [ReactiveUI.Fody.Helpers.Reactive] public bool ExperimentsDisabled { set; get; }
    [ReadOnly(true)] public ObservableCollection<long> ExperimentsFinishedIds { set; get; } = [];
    [ReactiveUI.Fody.Helpers.Reactive] public bool DisableCrashReporting { set; get; }
    
    /* Developer */
    [ReactiveUI.Fody.Helpers.Reactive] public bool OpenDevToolsOnStartup { set; get; }
    
    /* Battery stats */
    [ReactiveUI.Fody.Helpers.Reactive] public bool CollectBatteryHistory { set; get; } = true;

    /* Other */
    [ReactiveUI.Fody.Helpers.Reactive] public bool FirmwareWarningAccepted { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public Event BixbyRemapEvent { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public bool ResumePlaybackOnSensor { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public bool PausePlaybackOnSensor { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public bool IsUsageReportHintHidden { set; get; }
    [ReactiveUI.Fody.Helpers.Reactive] public bool IsBatteryHistoryHintHidden { set; get; }
}
