|
| 1 | +using System.Text.Json.Serialization; |
| 2 | + |
| 3 | +namespace FluentCommand.Import; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Represents the definition and configuration of a field for import operations. |
| 7 | +/// </summary> |
| 8 | +public class FieldDefinition |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Gets or sets the display name of the field, used for UI or reporting purposes. |
| 12 | + /// </summary> |
| 13 | + [JsonPropertyName("displayName")] |
| 14 | + public string? DisplayName { get; set; } |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Gets or sets the unique name of the field. |
| 18 | + /// </summary> |
| 19 | + [JsonPropertyName("name")] |
| 20 | + public string Name { get; set; } = null!; |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Gets or sets the data type of the field. |
| 24 | + /// </summary> |
| 25 | + [JsonPropertyName("dataType")] |
| 26 | + [JsonConverter(typeof(Converters.TypeJsonConverter))] |
| 27 | + public Type? DataType { get; set; } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Gets or sets a value indicating whether this field is a key field. |
| 31 | + /// </summary> |
| 32 | + /// <value> |
| 33 | + /// <c>true</c> if this field is a key; otherwise, <c>false</c>. |
| 34 | + /// </value> |
| 35 | + [JsonPropertyName("isKey")] |
| 36 | + public bool IsKey { get; set; } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// Gets or sets a value indicating whether this field can be inserted during import. The default is <c>true</c>. |
| 40 | + /// </summary> |
| 41 | + /// <value> |
| 42 | + /// <c>true</c> if this field can be inserted; otherwise, <c>false</c>. |
| 43 | + /// </value> |
| 44 | + [JsonPropertyName("canInsert")] |
| 45 | + public bool CanInsert { get; set; } = true; |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Gets or sets a value indicating whether this field can be updated during import. The default is <c>true</c>. |
| 49 | + /// </summary> |
| 50 | + /// <value> |
| 51 | + /// <c>true</c> if this field can be updated; otherwise, <c>false</c>. |
| 52 | + /// </value> |
| 53 | + [JsonPropertyName("canUpdate")] |
| 54 | + public bool CanUpdate { get; set; } = true; |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Gets or sets a value indicating whether this field can be mapped by users during import configuration. The default is <c>true</c>. |
| 58 | + /// </summary> |
| 59 | + /// <value> |
| 60 | + /// <c>true</c> if this field can be mapped; otherwise, <c>false</c>. |
| 61 | + /// </value> |
| 62 | + [JsonPropertyName("canMap")] |
| 63 | + public bool CanMap { get; set; } = true; |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Gets or sets a value indicating whether this field is required for import. |
| 67 | + /// </summary> |
| 68 | + /// <value> |
| 69 | + /// <c>true</c> if the field is required; otherwise, <c>false</c>. |
| 70 | + /// </value> |
| 71 | + [JsonPropertyName("isRequired")] |
| 72 | + public bool IsRequired { get; set; } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Gets or sets the default value behavior for the field during import. |
| 76 | + /// </summary> |
| 77 | + /// <value> |
| 78 | + /// The <see cref="FieldDefault"/> option specifying how the default value is determined. |
| 79 | + /// </value> |
| 80 | + [JsonPropertyName("default")] |
| 81 | + public FieldDefault? Default { get; set; } |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// Gets or sets the static default value for the field, used when <see cref="Default"/> is set to <see cref="FieldDefault.Static"/>. |
| 85 | + /// </summary> |
| 86 | + /// <value> |
| 87 | + /// The static default value for the field. |
| 88 | + /// </value> |
| 89 | + [JsonPropertyName("defaultValue")] |
| 90 | + public object? DefaultValue { get; set; } |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Gets or sets the type of the field translator, used to transform or convert field values during import. |
| 94 | + /// </summary> |
| 95 | + /// <value> |
| 96 | + /// The <see cref="Type"/> of the field translator. |
| 97 | + /// </value> |
| 98 | + [JsonPropertyName("translator")] |
| 99 | + [JsonConverter(typeof(Converters.TypeJsonConverter))] |
| 100 | + public Type? Translator { get; set; } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Gets or sets the list of match expressions used for mapping or validation. |
| 104 | + /// </summary> |
| 105 | + /// <value> |
| 106 | + /// A list of string expressions for matching or validation. |
| 107 | + /// </value> |
| 108 | + [JsonPropertyName("expressions")] |
| 109 | + public List<string> Expressions { get; set; } = []; |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Returns a string that represents the current <see cref="FieldDefinition"/> instance. |
| 113 | + /// </summary> |
| 114 | + /// <returns> |
| 115 | + /// A <see cref="string"/> that contains the display name, field name, and data type. |
| 116 | + /// </returns> |
| 117 | + public override string ToString() |
| 118 | + { |
| 119 | + return $"Display: {DisplayName}, Name: {Name}, DataType: {DataType?.Name}"; |
| 120 | + } |
| 121 | +} |
0 commit comments