using System.Diagnostics.CodeAnalysis;

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

public sealed class VmwareOptions
{
    public const string HttpClientName = "source.vmware";

    public Uri IndexUri { get; set; } = new("https://example.invalid/vmsa/index.json", UriKind.Absolute);

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

    public TimeSpan ModifiedTolerance { get; set; } = TimeSpan.FromHours(2);

    public int MaxAdvisoriesPerFetch { get; set; } = 50;

    public TimeSpan RequestDelay { get; set; } = TimeSpan.FromMilliseconds(250);

    public TimeSpan HttpTimeout { get; set; } = TimeSpan.FromMinutes(2);

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

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

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

        if (MaxAdvisoriesPerFetch <= 0)
        {
            throw new InvalidOperationException("Max advisories per fetch must be greater than zero.");
        }

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

        if (HttpTimeout <= TimeSpan.Zero)
        {
            throw new InvalidOperationException("HTTP timeout must be positive.");
        }
    }
}
