using System.Text.Json.Serialization;
using OFACScraper.Helpers;

namespace OFACScraper.Models;

public class Publication
{
    [JsonPropertyName("id")]
    public required Guid Id { get; init; }

    [JsonPropertyName("text_id")]
    public required string TextId { get; init; }

    [JsonPropertyName("source")]
    public required string Source { get; init; }

    [JsonPropertyName("website_link")]
    public required string WebsiteLink { get; init; }

    [JsonPropertyName("title")]
    public required string Title { get; init; }

    [JsonPropertyName("date_published")]
    public required DateTimeOffset DatePublished { get; init; }

    [JsonPropertyName("date_accessed")]
    public required DateTimeOffset DateAccessed { get; set; }

    [JsonPropertyName("scraper_version")]
    public required int ScraperVersion { get; init; }

    [JsonPropertyName("deleted")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public bool? Deleted { get; set; }

    [JsonPropertyName("documents")]
    public List<PublicationDocument> Documents { get; init; } = [];

    [JsonPropertyName("tags")]
    public List<PublicationTag> Tags { get; init; } = [];
}

public record PublicationDocument
{
    [JsonPropertyName("id")]
    public required Guid Id { get; init; }

    [JsonPropertyName("name")]
    public required string Name { get; init; }

    [JsonPropertyName("is_attachment")]
    public bool IsAttachment { get; init; } = false;

    [JsonPropertyName("url")]
    public required string Url { get; init; }
}

public record PublicationTag
{
    [JsonPropertyName("slug")]
    public required string Slug { get; init; }

    [JsonPropertyName("text")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? Text { get; init; }

    [JsonPropertyName("date")]
    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    [JsonConverter(typeof(TagDateConverter))]
    public DateTimeOffset? Date { get; init; }
}

public static class PublicationSources
{
    public const string OfacCivilPenalty = "OFAC_CIVIL_PENALTY";
}

public static class ScraperConstants
{
    public const int ScraperVersion = 3;
}
