using System.Text.Json.Serialization;

namespace StellaOps.Feedser.Source.Acsc.Internal;

internal sealed record AcscFeedDto(
    [property: JsonPropertyName("feedSlug")] string FeedSlug,
    [property: JsonPropertyName("feedTitle")] string? FeedTitle,
    [property: JsonPropertyName("feedLink")] string? FeedLink,
    [property: JsonPropertyName("feedUpdated")] DateTimeOffset? FeedUpdated,
    [property: JsonPropertyName("parsedAt")] DateTimeOffset ParsedAt,
    [property: JsonPropertyName("entries")] IReadOnlyList<AcscEntryDto> Entries)
{
    public static AcscFeedDto Empty { get; } = new(
        FeedSlug: string.Empty,
        FeedTitle: null,
        FeedLink: null,
        FeedUpdated: null,
        ParsedAt: DateTimeOffset.UnixEpoch,
        Entries: Array.Empty<AcscEntryDto>());
}

internal sealed record AcscEntryDto(
    [property: JsonPropertyName("entryId")] string EntryId,
    [property: JsonPropertyName("title")] string Title,
    [property: JsonPropertyName("link")] string? Link,
    [property: JsonPropertyName("feedSlug")] string FeedSlug,
    [property: JsonPropertyName("published")] DateTimeOffset? Published,
    [property: JsonPropertyName("updated")] DateTimeOffset? Updated,
    [property: JsonPropertyName("summary")] string Summary,
    [property: JsonPropertyName("contentHtml")] string ContentHtml,
    [property: JsonPropertyName("contentText")] string ContentText,
    [property: JsonPropertyName("references")] IReadOnlyList<AcscReferenceDto> References,
    [property: JsonPropertyName("aliases")] IReadOnlyList<string> Aliases,
    [property: JsonPropertyName("fields")] IReadOnlyDictionary<string, string> Fields)
{
    public static AcscEntryDto Empty { get; } = new(
        EntryId: string.Empty,
        Title: string.Empty,
        Link: null,
        FeedSlug: string.Empty,
        Published: null,
        Updated: null,
        Summary: string.Empty,
        ContentHtml: string.Empty,
        ContentText: string.Empty,
        References: Array.Empty<AcscReferenceDto>(),
        Aliases: Array.Empty<string>(),
        Fields: new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase));
}

internal sealed record AcscReferenceDto(
    [property: JsonPropertyName("title")] string Title,
    [property: JsonPropertyName("url")] string Url)
{
    public static AcscReferenceDto Empty { get; } = new(
        Title: string.Empty,
        Url: string.Empty);
}
