using AIStudio.Tools.DocumentSegments.Html;
using AIStudio.Tools.DocumentSegments.Latex;
using AIStudio.Tools.DocumentSegments.PowerPoint;
using AIStudio.Tools.DocumentSegments.Word;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust;
namespace AIStudio.Tools.DocumentSegments;
///
/// The kinds of documents whose text a model works on segment by segment.
///
public static class DocumentSegmentFormats
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(DocumentSegmentFormats).Namespace, nameof(DocumentSegmentFormats));
private static readonly IReadOnlyList FORMATS =
[
new WordSegmentFormat(),
new PowerPointSegmentFormat(),
new MarkdownSegmentFormat(),
new HtmlSegmentFormat(),
new LatexSegmentFormat(),
];
///
/// The kinds of files of all formats, as one entry of a file dialog.
///
///
/// Taken from the formats, so that a new format appears in the dialog without a list of its own.
///
public static FileTypeFilter AllKinds => FileTypeFilter.Parent(TB("Document"), [.. FORMATS.Select(format => format.FileType)]);
///
/// Finds the format of a document by its extension.
///
/// The document.
/// The format, or null when no format reads documents of this kind.
public static IDocumentSegmentFormat? For(string path)
{
var extension = Path.GetExtension(path);
return FORMATS.FirstOrDefault(format => FileTypes.IsAllowedExtension(extension, format.FileType));
}
}