|  |  | 1 |  | using Newtonsoft.Json.Linq; | 
|  |  | 2 |  | using ValidateLib.ErrorsAndWarnings.Errors; | 
|  |  | 3 |  | using ValidateLib.ErrorsAndWarnings.Warnings; | 
|  |  | 4 |  | using ValidateLib.Metadata.Descriptors.Interfaces; | 
|  |  | 5 |  | using ValidateLib.Metadata.Parsers; | 
|  |  | 6 |  | using ValidateLib.Metadata.Properties; | 
|  |  | 7 |  | using ValidateLib.Metadata.PropertyParsers; | 
|  |  | 8 |  | using ValidateLib.Metadata.PropertyParsers.ForeignKey; | 
|  |  | 9 |  |  | 
|  |  | 10 |  | namespace ValidateLib.Metadata.Descriptors | 
|  |  | 11 |  | { | 
|  |  | 12 |  |     public class ForeignKeyDescriptor : DescriptorBase, INormalize, Interfaces.IParsable<ForeignKeyDescriptor>, IRequire | 
|  |  | 13 |  |     { | 
|  | 1 | 14 |  |         public ColumnReferenceProperty? columnReference { get; set; } | 
|  | 1 | 15 |  |         public ObjectProperty<ReferenceDescriptor>? reference { get; set; } | 
|  |  | 16 |  |         public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) | 
|  |  | 17 |  |         { | 
|  | 1 | 18 |  |             List<Warning> errors = new List<Warning>(); | 
|  | 1 | 19 |  |             if (token.Type != JTokenType.Object) return errors; | 
|  | 1 | 20 |  |             foreach (JProperty jProperty in token) | 
|  |  | 21 |  |             { | 
|  | 1 | 22 |  |                 var results = NormalizeProperty(jProperty, context); | 
|  | 1 | 23 |  |                 errors.AddRange(results); | 
|  |  | 24 |  |             } | 
|  | 1 | 25 |  |             return errors; | 
|  |  | 26 |  |         } | 
|  |  | 27 |  |  | 
|  |  | 28 |  |         static public List<Warning> NormalizeProperty(JProperty property, Context context) | 
|  |  | 29 |  |         { | 
|  | 1 | 30 |  |             List<Warning> errors = new List<Warning>(); | 
|  | 1 | 31 |  |             if (CommonProperty.IsCommonProperty(property.Name)) return CommonProperty.Normalize(property.Value, context, | 
|  | 1 | 32 |  |             else if (property.Name == "columnReference") return errors; | 
|  | 1 | 33 |  |             else if (property.Name == "reference") | 
|  | 1 | 34 |  |                 return ObjectProperty<ReferenceDescriptor>.Normalize(property.Value, context, property); | 
|  |  | 35 |  |             else | 
|  |  | 36 |  |             { | 
|  | 0 | 37 |  |                 errors.Add(WarningFactory.GetUnknownPropertyWarning(property)); | 
|  | 0 | 38 |  |                 return errors; | 
|  |  | 39 |  |             } | 
|  |  | 40 |  |  | 
|  |  | 41 |  |         } | 
|  |  | 42 |  |  | 
|  | 1 | 43 |  |         public static IParser<ForeignKeyDescriptor> GetParser(List<Warning> warnings, ForeignKeyDescriptor? descriptor = | 
|  |  | 44 |  |  | 
|  |  | 45 |  |  | 
|  |  | 46 |  |         public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) | 
|  |  | 47 |  |         { | 
|  | 1 | 48 |  |             switch (property.Name) | 
|  |  | 49 |  |             { | 
|  |  | 50 |  |                 case "columnReference": | 
|  | 1 | 51 |  |                     return new ColumnReferencePropertyParser(warnings, this); | 
|  |  | 52 |  |                 case "reference": | 
|  | 1 | 53 |  |                     return new ReferencePropertyParser(warnings, this); | 
|  |  | 54 |  |                 default: | 
|  | 1 | 55 |  |                     return null; | 
|  |  | 56 |  |             } | 
|  |  | 57 |  |         } | 
|  |  | 58 |  |  | 
|  |  | 59 |  |         public List<Warning> CheckRequiredPropertiesPresent() | 
|  |  | 60 |  |         { | 
|  | 1 | 61 |  |             if (reference is null) ErrorFactory.ThrowRequiredPropertyMissingError("reference", nameof(ForeignKeyDescript | 
|  | 1 | 62 |  |             if (columnReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("columnReference", nameof(Foreig | 
|  | 1 | 63 |  |             return new List<Warning>(); | 
|  |  | 64 |  |         } | 
|  |  | 65 |  |     } | 
|  |  | 66 |  | } |