|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel.DataAnnotations; |
| 4 | +using System.ComponentModel.DataAnnotations.Schema; |
| 5 | +using Newtonsoft.Json; |
| 6 | +using ProtoBuf; |
| 7 | + |
| 8 | +namespace Resgrid.Model |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// A system-wide feature flag definition with a global default. Per-department behavior is |
| 12 | + /// layered on top via <see cref="FeatureFlagOverride"/>, <see cref="FeatureFlagTargetingRule"/> |
| 13 | + /// and <see cref="FeatureFlagPrerequisite"/>. |
| 14 | + /// </summary> |
| 15 | + [Table("FeatureFlags")] |
| 16 | + [ProtoContract] |
| 17 | + public class FeatureFlag : IEntity |
| 18 | + { |
| 19 | + [Key] |
| 20 | + [Required] |
| 21 | + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] |
| 22 | + [ProtoMember(1)] |
| 23 | + public int FeatureFlagId { get; set; } |
| 24 | + |
| 25 | + /// <summary>Stable identifier referenced by code and clients (e.g. "new-dispatch-ui").</summary> |
| 26 | + [Required] |
| 27 | + [ProtoMember(2)] |
| 28 | + public string FlagKey { get; set; } |
| 29 | + |
| 30 | + [Required] |
| 31 | + [ProtoMember(3)] |
| 32 | + public string Name { get; set; } |
| 33 | + |
| 34 | + [ProtoMember(4)] |
| 35 | + public string Description { get; set; } |
| 36 | + |
| 37 | + [ProtoMember(5)] |
| 38 | + public string Category { get; set; } |
| 39 | + |
| 40 | + /// <summary>Comma-separated free-form tags for grouping/searching.</summary> |
| 41 | + [ProtoMember(6)] |
| 42 | + public string Tags { get; set; } |
| 43 | + |
| 44 | + /// <summary>Backing int for <see cref="FeatureFlagValueTypes"/>.</summary> |
| 45 | + [Required] |
| 46 | + [ProtoMember(7)] |
| 47 | + public int FlagType { get; set; } |
| 48 | + |
| 49 | + /// <summary>The global on/off default and application-wide kill switch.</summary> |
| 50 | + [Required] |
| 51 | + [ProtoMember(8)] |
| 52 | + public bool IsEnabledGlobally { get; set; } |
| 53 | + |
| 54 | + /// <summary>Value returned when the flag resolves "on" for multivariate flags.</summary> |
| 55 | + [ProtoMember(9)] |
| 56 | + public string DefaultValue { get; set; } |
| 57 | + |
| 58 | + /// <summary>Value returned when the flag resolves "off" for multivariate flags.</summary> |
| 59 | + [ProtoMember(10)] |
| 60 | + public string OffValue { get; set; } |
| 61 | + |
| 62 | + /// <summary>0-100 gradual rollout across departments when globally on; null = 100%.</summary> |
| 63 | + [ProtoMember(11)] |
| 64 | + public int? RolloutPercentage { get; set; } |
| 65 | + |
| 66 | + /// <summary>Optional minimum subscription plan id required for the flag to be on.</summary> |
| 67 | + [ProtoMember(12)] |
| 68 | + public int? MinimumPlanType { get; set; } |
| 69 | + |
| 70 | + /// <summary>Optional environment scope (backing int for SystemEnvironment); null = all.</summary> |
| 71 | + [ProtoMember(13)] |
| 72 | + public int? Environment { get; set; } |
| 73 | + |
| 74 | + [ProtoMember(14)] |
| 75 | + public DateTime? EnableOn { get; set; } |
| 76 | + |
| 77 | + [ProtoMember(15)] |
| 78 | + public DateTime? DisableOn { get; set; } |
| 79 | + |
| 80 | + [Required] |
| 81 | + [ProtoMember(16)] |
| 82 | + public bool IsArchived { get; set; } |
| 83 | + |
| 84 | + /// <summary>Permanent flags are excluded from stale-flag detection.</summary> |
| 85 | + [Required] |
| 86 | + [ProtoMember(17)] |
| 87 | + public bool IsPermanent { get; set; } |
| 88 | + |
| 89 | + [ProtoMember(18)] |
| 90 | + public DateTime? LastEvaluatedOn { get; set; } |
| 91 | + |
| 92 | + [Required] |
| 93 | + [ProtoMember(19)] |
| 94 | + public DateTime CreatedOn { get; set; } |
| 95 | + |
| 96 | + [ProtoMember(20)] |
| 97 | + public string CreatedByUserId { get; set; } |
| 98 | + |
| 99 | + [ProtoMember(21)] |
| 100 | + public DateTime? UpdatedOn { get; set; } |
| 101 | + |
| 102 | + [ProtoMember(22)] |
| 103 | + public string UpdatedByUserId { get; set; } |
| 104 | + |
| 105 | + [NotMapped] |
| 106 | + [JsonIgnore] |
| 107 | + public object IdValue |
| 108 | + { |
| 109 | + get { return FeatureFlagId; } |
| 110 | + set { FeatureFlagId = (int)value; } |
| 111 | + } |
| 112 | + |
| 113 | + [NotMapped] |
| 114 | + public string TableName => "FeatureFlags"; |
| 115 | + |
| 116 | + [NotMapped] |
| 117 | + public string IdName => "FeatureFlagId"; |
| 118 | + |
| 119 | + [NotMapped] |
| 120 | + public int IdType => 0; |
| 121 | + |
| 122 | + [NotMapped] |
| 123 | + public IEnumerable<string> IgnoredProperties => new string[] { "IdValue", "IdType", "TableName", "IdName" }; |
| 124 | + } |
| 125 | +} |
0 commit comments