using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using StellaOps.Excititor.Connectors.Abstractions;

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

public sealed class CiscoConnectorOptionsValidator : IVexConnectorOptionsValidator<CiscoConnectorOptions>
{
    public void Validate(VexConnectorDescriptor descriptor, CiscoConnectorOptions options, IList<string> errors)
    {
        ArgumentNullException.ThrowIfNull(descriptor);
        ArgumentNullException.ThrowIfNull(options);
        ArgumentNullException.ThrowIfNull(errors);

        var validationResults = new List<ValidationResult>();
        if (!Validator.TryValidateObject(options, new ValidationContext(options), validationResults, validateAllProperties: true))
        {
            foreach (var result in validationResults)
            {
                errors.Add(result.ErrorMessage ?? "Cisco connector options validation failed.");
            }
        }
    }
}
