using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using StellaOps.Excititor.Connectors.Abstractions;

namespace StellaOps.Excititor.Connectors.OCI.OpenVEX.Attest.Configuration;

public sealed class OciOpenVexAttestationConnectorOptionsValidator : IVexConnectorOptionsValidator<OciOpenVexAttestationConnectorOptions>
{
    private readonly IFileSystem _fileSystem;

    public OciOpenVexAttestationConnectorOptionsValidator(IFileSystem fileSystem)
    {
        _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
    }

    public void Validate(
        VexConnectorDescriptor descriptor,
        OciOpenVexAttestationConnectorOptions options,
        IList<string> errors)
    {
        ArgumentNullException.ThrowIfNull(descriptor);
        ArgumentNullException.ThrowIfNull(options);
        ArgumentNullException.ThrowIfNull(errors);

        try
        {
            options.Validate(_fileSystem);
        }
        catch (Exception ex)
        {
            errors.Add(ex.Message);
        }
    }
}
