using System;
using System.Collections.Generic;
using System.Linq;

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

public sealed class OracleOptions
{
    public const string HttpClientName = "vndr-oracle";

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

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

    public TimeSpan RequestDelay { get; set; } = TimeSpan.FromSeconds(1);

    public void Validate()
    {
        if (AdvisoryUris.Count == 0 && CalendarUris.Count == 0)
        {
            throw new InvalidOperationException("Oracle connector requires at least one advisory or calendar URI.");
        }

        if (AdvisoryUris.Any(uri => uri is null || !uri.IsAbsoluteUri))
        {
            throw new InvalidOperationException("All Oracle AdvisoryUris must be absolute URIs.");
        }

        if (CalendarUris.Any(uri => uri is null || !uri.IsAbsoluteUri))
        {
            throw new InvalidOperationException("All Oracle CalendarUris must be absolute URIs.");
        }

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