using Febe.Core.Library; using Febe.Web.Connection; namespace Febe.App; /// The problems found at start-up; fixed for the life of the process (fixing one needs a restart). public sealed class StartupProblems(IReadOnlyList problems) : IConfigurationProblems { public IReadOnlyList Current { get; } = problems; } /// Checks shared by both shells (spec §8.2): the Data folder is local and writable. public static class DataFolderProblems { public const string DataNotWritable = "dati-non-scrivibili"; public const string DataOnNetwork = "dati-in-rete"; /// The problem with the Data folder, or null when it is fine. public static ConfigurationProblem? Check(string dataFolder, DataFolderCheck? check = null) { if ((check ?? new DataFolderCheck()).Check(dataFolder) is not { } data) { return null; } return new ConfigurationProblem( data.Kind == DataFolderProblemKind.NetworkPath ? DataOnNetwork : DataNotWritable, data.Title, data.Explanation, data.Remedy); } } /// /// The link to Instagram while a configuration problem keeps the browser from starting: always «browser non /// disponibile», and every command refused with the problem (the configuration gate refuses them earlier anyway). /// public sealed class ProblemConnectionService(IReadOnlyList problems) : IConnectionService { public Task GetStatusAsync(CancellationToken ct) => Task.FromResult(new ConnectionStatus(ConnectionState.BrowserUnavailable, null, null, false, null)); public Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct) => throw Refused(); public Task FinishAsync(CancellationToken ct) => throw Refused(); public Task CancelAsync(CancellationToken ct) => Task.CompletedTask; public Task DisconnectAsync(CancellationToken ct) => throw Refused(); private Febe.Web.Api.BadRequestException Refused() => new($"{(problems.Count > 0 ? problems[0].Title : "Configurazione da sistemare")}: il browser di Febe non è partito."); }