using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Tornado3_2026Election.Domain;

public sealed class PreElectionHistoryCatalog
{
    public PreElectionHistoryMetadata Metadata { get; init; } = new();

    public IReadOnlyList<PreElectionHistoryRecord> Records { get; init; } = [];
}

public sealed class PreElectionHistoryMetadata
{
    public string Version { get; init; } = string.Empty;

    public string GeneratedAt { get; init; } = string.Empty;

    public IReadOnlyList<string> CoverageNotes { get; init; } = [];

    public IReadOnlyList<PreElectionHistorySourceReference> Sources { get; init; } = [];
}

public sealed class PreElectionHistorySourceReference
{
    public string Title { get; init; } = string.Empty;

    public string Url { get; init; } = string.Empty;
}

public sealed class PreElectionHistoryRecord
{
    public string ElectionType { get; init; } = string.Empty;

    public string Key { get; init; } = string.Empty;

    public string RegionKey { get; init; } = string.Empty;

    public string RegionName { get; init; } = string.Empty;

    public string DistrictName { get; init; } = string.Empty;

    public string DisplayName { get; init; } = string.Empty;

    public IReadOnlyList<PreElectionHistoricalTurnoutEntry> TurnoutHistory { get; init; } = [];

    public IReadOnlyList<PreElectionHistoricalWinnerEntry> WinnerHistory { get; init; } = [];
}

public sealed class PreElectionHistoricalTurnoutEntry
{
    public int ElectionOrder { get; init; }

    public int Year { get; init; }

    public int Electors { get; init; }

    public int Votes { get; init; }

    public double TurnoutRate { get; init; }

    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? SourceUrl { get; init; }
}

public sealed class PreElectionHistoricalWinnerEntry
{
    public int ElectionOrder { get; init; }

    public int Year { get; init; }

    public string Name { get; init; } = string.Empty;

    public string Party { get; init; } = string.Empty;

    public string ColorParty { get; init; } = string.Empty;

    public string Note { get; init; } = string.Empty;

    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
    public string? SourceUrl { get; init; }
}
