using System;
using System.Diagnostics.CodeAnalysis;

namespace StellaOps.Feedser.Source.Kev.Configuration;

public sealed class KevOptions
{
    public static string HttpClientName => "source.kev";

    /// <summary>
    /// Official CISA Known Exploited Vulnerabilities JSON feed.
    /// </summary>
    public Uri FeedUri { get; set; } = new("https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json", UriKind.Absolute);

    /// <summary>
    /// Timeout applied to KEV feed requests.
    /// </summary>
    public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);

    [MemberNotNull(nameof(FeedUri))]
    public void Validate()
    {
        if (FeedUri is null || !FeedUri.IsAbsoluteUri)
        {
            throw new InvalidOperationException("FeedUri must be an absolute URI.");
        }

        if (RequestTimeout <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("RequestTimeout must be greater than zero.");
        }
    }
}
