using StellaOps.Feedser.Storage.Mongo.Documents;

namespace StellaOps.Feedser.Source.Acsc.Internal;

internal readonly record struct AcscDocumentMetadata(string FeedSlug, string FetchMode)
{
    public static AcscDocumentMetadata FromDocument(DocumentRecord document)
    {
        if (document.Metadata is null)
        {
            return new AcscDocumentMetadata(string.Empty, string.Empty);
        }

        document.Metadata.TryGetValue("acsc.feed.slug", out var slug);
        document.Metadata.TryGetValue("acsc.fetch.mode", out var mode);
        return new AcscDocumentMetadata(
            string.IsNullOrWhiteSpace(slug) ? string.Empty : slug.Trim(),
            string.IsNullOrWhiteSpace(mode) ? string.Empty : mode.Trim());
    }
}
