using System.Text.Json.Serialization; namespace AIStudio.Tools; // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable ClassNeverInstantiated.Global public sealed class ContentStreamErrorDetails { [JsonPropertyName("code")] public string? Code { get; init; } [JsonPropertyName("message")] public string? Message { get; init; } /// /// The page the failure belongs to, when the failure affects a single page only. /// [JsonPropertyName("page_number")] public int? PageNumber { get; init; } /// /// The format the runtime identified by looking at the content, e.g. when it contradicts the /// file extension. /// [JsonPropertyName("detected_format")] public string? DetectedFormat { get; init; } /// /// Gets the parsed error code. /// /// /// Codes this version does not know map to /// instead of failing the deserialization. A failed deserialization would turn the reported /// error back into empty file content, which is exactly what we want to avoid here. /// [JsonIgnore] public FileExtractionErrorCode ParsedCode => Enum.TryParse(this.Code, ignoreCase: true, out var parsedCode) ? parsedCode : FileExtractionErrorCode.UNKNOWN; /// /// Gets a value indicating whether this failure affects one part of the file only, while the /// remaining content is still usable. /// [JsonIgnore] public bool IsPartialFailure => this.ParsedCode is FileExtractionErrorCode.PAGE_EXTRACTION_FAILED; /// /// Gets a value indicating whether this is a notice rather than a failure. /// /// /// A notice tells the user something worth knowing about the file, while the content itself /// was read completely. It must therefore never degrade the outcome of an extraction. /// [JsonIgnore] public bool IsNotice => this.ParsedCode is FileExtractionErrorCode.EXTENSION_MISMATCH; }