using System;
using System.Collections.Generic;

namespace StellaOps.Feedser.Source.Vndr.Adobe.Configuration;

public sealed class AdobeOptions
{
    public const string HttpClientName = "source-vndr-adobe";

    public Uri IndexUri { get; set; } = new("https://helpx.adobe.com/security/security-bulletin.html");

    public List<Uri> AdditionalIndexUris { get; } = new();

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

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

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

    public void Validate()
    {
        if (IndexUri is null || !IndexUri.IsAbsoluteUri)
        {
            throw new ArgumentException("IndexUri must be an absolute URI.", nameof(IndexUri));
        }

        foreach (var uri in AdditionalIndexUris)
        {
            if (uri is null || !uri.IsAbsoluteUri)
            {
                throw new ArgumentException("Additional index URIs must be absolute.", nameof(AdditionalIndexUris));
            }
        }

        if (InitialBackfill <= TimeSpan.Zero)
        {
            throw new ArgumentException("InitialBackfill must be positive.", nameof(InitialBackfill));
        }

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

        if (MaxEntriesPerFetch <= 0)
        {
            throw new ArgumentException("MaxEntriesPerFetch must be positive.", nameof(MaxEntriesPerFetch));
        }
    }
}
