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

namespace StellaOps.Excititor.Connectors.Ubuntu.CSAF.Configuration;

public sealed class UbuntuConnectorOptionsValidator : IVexConnectorOptionsValidator<UbuntuConnectorOptions>
{
    private readonly IFileSystem _fileSystem;

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

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

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