using System.ComponentModel;
using System.Linq.Expressions;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Settings;
namespace StabilityMatrix.Core.Services;
public interface ISettingsManager
{
bool IsPortableMode { get; }
string LibraryDir { get; }
bool IsLibraryDirSet { get; }
string DatabasePath { get; }
string ModelsDirectory { get; }
string DownloadsDirectory { get; }
DirectoryPath TagsDirectory { get; }
Settings Settings { get; }
///
/// Event fired when the library directory is changed
///
event EventHandler? LibraryDirChanged;
///
/// Event fired when a property of Settings is changed
///
event EventHandler? SettingsPropertyChanged;
///
/// Register a handler that fires once when LibraryDir is first set.
/// Will fire instantly if it is already set.
///
void RegisterOnLibraryDirSet(Action handler);
///
/// Event fired when Settings are loaded from disk
///
event EventHandler? Loaded;
///
/// Return a SettingsTransaction that can be used to modify Settings
/// Saves on Dispose.
///
SettingsTransaction BeginTransaction();
///
/// Execute a function that modifies Settings
/// Commits changes after the function returns.
///
/// Function accepting Settings to modify
void Transaction(Action func, bool ignoreMissingLibraryDir = false);
///
/// Modify a settings property by expression and commit changes.
/// This will notify listeners of SettingsPropertyChanged.
///
void Transaction(Expression> expression, TValue value);
///
/// Register a source observable object and property to be relayed to Settings
///
void RelayPropertyFor(
T source,
Expression> sourceProperty,
Expression> settingsProperty,
bool setInitial = false) where T : INotifyPropertyChanged;
///
/// Register an Action to be called on change of the settings property.
///
void RegisterPropertyChangedHandler(
Expression> settingsProperty,
Action onPropertyChanged);
///
/// Attempts to locate and set the library path
/// Return true if found, false otherwise
///
/// Force reload even if library is already set
bool TryFindLibrary(bool forceReload = false);
///
/// Save a new library path to %APPDATA%/StabilityMatrix/library.json
///
void SetLibraryPath(string path);
///
/// Enable and create settings files for portable mode
/// Creates the ./Data directory and the `.sm-portable` marker file
///
void SetPortableMode();
///
/// Iterable of installed packages using the old absolute path format.
/// Can be called with Any() to check if the user needs to migrate.
///
IEnumerable GetOldInstalledPackages();
Guid GetOldActivePackageId();
void AddPathExtension(string pathExtension);
string GetPathExtensionsAsString();
///
/// Insert path extensions to the front of the PATH environment variable
///
void InsertPathExtensions();
void UpdatePackageVersionNumber(Guid id, string? newVersion);
void SetLastUpdateCheck(InstalledPackage package);
List GetLaunchArgs(Guid packageId);
void SaveLaunchArgs(Guid packageId, List launchArgs);
string? GetActivePackageHost();
string? GetActivePackagePort();
void SetSharedFolderCategoryVisible(SharedFolderType type, bool visible);
bool IsSharedFolderCategoryVisible(SharedFolderType type);
bool IsEulaAccepted();
void SetEulaAccepted();
void IndexCheckpoints();
}