using System.Diagnostics.CodeAnalysis; using System.Text; namespace Febe.Core.Collection.Search; /// What the profile search is doing for the wanted text (issue #37). The interface shows it in Italian. public enum SearchState { /// Nothing wanted (empty box, dialog closed). Idle, /// The text is not one Febe types on the site (several names, too short, other characters): local suggestions only. LocalOnly, /// Waiting for the page: a collection step holds it, or the search spacing. Waiting, /// Febe is typing on the site or waiting for its answer. Searching, /// The site answered with profiles. Ready, /// The site answered with no profile. Empty, /// No answer of the site came for this text (it may have answered from its own memory). NoAnswer, /// Alberto is using Febe's browser: the search on the site waits. NotPossible, /// Outside the active window Febe does not open the site. OutsideWindow, /// The breaker is open (spec §7.6), or the search's own budget is used up. Stopped, /// The browser or the engine is not up. Unavailable, /// The map of the site lacks the search targets, or the readers lack the search answer (H11). NotConfigured, /// The text holds a character Febe never types (a control character). Refused, /// A step went wrong; the next text tries again. Failed, } /// Closed list of how one search step ended: diagnostics count these names, never a text (issue #37). public enum SearchOutcome { Ready, Empty, NoAnswer, Cached, Refused, Stopped, NotConfigured, NotConnected, OutsideWindow, TargetMissing, FocusLost, KeysNotReceived, PageNotLoaded, BrowserNotResponding, Interrupted, NotPossible, Denied, } /// /// One profile the search found or knows. Never printed with its values: the record prints only counts and flags. /// /// Order in the site's answer, from 0. /// The site's identifier of the profile. /// User name, lowercase. /// Full name, when the site gives one. /// Verified mark, when the site says. /// Key of the photo in Febe's memory cache (32 hex characters), when it is there. /// True once the photo is in the cache. public sealed record SearchHit(int Position, string InstagramId, string Username, string? DisplayName, bool? IsVerified, string? PhotoKey, bool PhotoReady) { private bool PrintMembers(StringBuilder builder) { builder.Append($"Position = {Position}, HasDisplayName = {DisplayName is not null}, IsVerified = {IsVerified}, PhotoReady = {PhotoReady}"); return true; } } /// /// What the search shows now. is the random id of the window that wrote the text last; /// is the text Febe typed (or would type), as the interface labels results «per "testo"». /// public sealed record SearchView(long Version, string Owner, string Text, SearchState State, string? Message, IReadOnlyList Hits, DateTimeOffset? RetryAfter) { public static SearchView Initial { get; } = new(0, string.Empty, string.Empty, SearchState.Idle, null, [], null); private bool PrintMembers(StringBuilder builder) { builder.Append($"Version = {Version}, State = {State}, Hits = {Hits.Count}, TextLength = {Text.Length}"); return true; } } /// /// The profile search as the interface sees it (issue #37): one wanted text at a time (the last window that writes /// wins), the latest view for polling, and the photos of the results from Febe's memory. /// public interface IProfileSearch { /// Sets the wanted text of window and returns at once. SearchView Update(string client, string text); /// The latest view. SearchView Current { get; } /// The dialog of window closed; ignored when another window wrote last. void End(string client); /// The last result seen with this user name (for adding it with its identifier), server side only. SearchHit? Known(string username); /// A photo of the memory cache by its key. bool TryOpenPhoto(string key, [NotNullWhen(true)] out Stream? stream); }