using System;
using System.Collections.Generic;
using NodePipeline.Abstractions.Interfaces.Nodes;
// ReSharper disable ConvertToPrimaryConstructor
namespace NodePipeline.Engine.CodeGeneration.Abstractions.Models;
public sealed class NodeFieldDescriptor
{
public NodeFieldDescriptor(string propertyName, string fieldName, string valueType, bool isNullableValueType,
bool isValueReferenceType, bool isValueEnum, FieldDirection direction, NodeFieldMetaData? metaData)
{
PropertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
FieldName = fieldName ?? throw new ArgumentNullException(nameof(fieldName));
ValueType = valueType ?? throw new ArgumentNullException(nameof(valueType));
IsNullableValueType = isNullableValueType;
IsValueReferenceType = isValueReferenceType;
IsValueEnum = isValueEnum;
Direction = direction;
Metadata = metaData;
}
///
/// C# property name
///
public string PropertyName { get; }
///
/// Node field name (used by mentioning in pipeline configuration)
///
public string FieldName { get; }
///
/// Underlying value type
///
public string ValueType { get; }
public bool IsNullableValueType { get; }
public bool IsValueReferenceType { get; }
public bool IsValueEnum { get; }
///
/// Node field direction
///
public FieldDirection Direction { get; }
///
/// node field metadata
///
public NodeFieldMetaData? Metadata { get; }
///
/// Node field metadata
///
public class NodeFieldMetaData
{
private readonly HashSet _customValidators = [];
public NodeFieldMetaData(bool isRequired, bool disallowNullableOutput = false,
IEnumerable? customValidators = null,
object? defaultValue = null, bool canDefaultValueBeInitialized = false, decimal? numberMinBound = null,
decimal? numberMaxBound = null, int? stringMinLength = null, int? stringMaxLength = null)
{
IsRequired = isRequired;
DefaultValue = defaultValue;
CanDefaultValueBeInitialized = canDefaultValueBeInitialized;
NumberMinBound = numberMinBound;
NumberMaxBound = numberMaxBound;
StringMinLength = stringMinLength;
StringMaxLength = stringMaxLength;
DisallowNullableOutput = disallowNullableOutput;
if (customValidators == null) return;
foreach (var validatorType in customValidators) _customValidators.Add(validatorType);
}
public IReadOnlyCollection CustomValidators => _customValidators;
public object? DefaultValue { get; }
public bool CanDefaultValueBeInitialized { get; }
public bool IsRequired { get; }
///
/// It is suitable for ports only
///
public bool DisallowNullableOutput { get; }
public decimal? NumberMinBound { get; }
public decimal? NumberMaxBound { get; }
public int? StringMinLength { get; }
public int? StringMaxLength { get; }
}
}