using System;

namespace StellaOps.Feedser.Source.CertFr.Configuration;

public sealed class CertFrOptions
{
    public const string HttpClientName = "cert-fr";

    public Uri FeedUri { get; set; } = new("https://www.cert.ssi.gouv.fr/feed/alertes/");

    public TimeSpan InitialBackfill { get; set; } = TimeSpan.FromDays(30);

    public TimeSpan WindowOverlap { get; set; } = TimeSpan.FromDays(2);

    public int MaxItemsPerFetch { get; set; } = 100;

    public TimeSpan RequestDelay { get; set; } = TimeSpan.Zero;

    public void Validate()
    {
        if (FeedUri is null || !FeedUri.IsAbsoluteUri)
        {
            throw new InvalidOperationException("Cert-FR FeedUri must be an absolute URI.");
        }

        if (InitialBackfill <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("InitialBackfill must be a positive duration.");
        }

        if (WindowOverlap < TimeSpan.Zero)
        {
            throw new InvalidOperationException("WindowOverlap cannot be negative.");
        }

        if (MaxItemsPerFetch <= 0)
        {
            throw new InvalidOperationException("MaxItemsPerFetch must be positive.");
        }

        if (RequestDelay < TimeSpan.Zero)
        {
            throw new InvalidOperationException("RequestDelay cannot be negative.");
        }
    }
}
