1414//-----------------------------------------------------------------------------
1515
1616using NoFrixion . MoneyMoov . Attributes ;
17+ using NoFrixion . MoneyMoov . Enums ;
1718using System . ComponentModel . DataAnnotations ;
1819
1920namespace NoFrixion . MoneyMoov . Models ;
@@ -51,16 +52,26 @@ public WebhookResourceTypesEnum Type
5152 /// </summary>
5253 public List < WebhookResourceTypesEnum > ResourceTypes { get ; set ; } = new List < WebhookResourceTypesEnum > ( ) ;
5354
54- [ Required ]
55+ /// <summary>
56+ /// The destination URL for the webhook.
57+ /// Required for webhook notifications.
58+ /// </summary>
5559 public string ? DestinationUrl { get ; set ; }
5660
5761 public bool Retry { get ; set ; } = true ;
5862
59- [ Required ]
63+ /// <summary>
64+ /// The secret key required to authenticate webhook notifications.
65+ /// Required for webhook notifications.
66+ /// </summary>
6067 public string ? Secret { get ; set ; }
6168
6269 public bool IsActive { get ; set ; } = true ;
6370
71+ /// <summary>
72+ /// The recipient email address(es) for notifications. Multiple addresses can be separated by a comma, semicolon, or space.
73+ /// Reruired for email notifications.
74+ /// </summary>
6475 [ EmailAddressMultiple ( ErrorMessage = "One or more of the email addresses are invalid. Addresses can be separated by a comma, semi-colon or space." ) ]
6576 public string ? EmailAddress { get ; set ; }
6677
@@ -70,6 +81,12 @@ public WebhookResourceTypesEnum Type
7081 [ EmailAddressMultiple ( ErrorMessage = "One or more of the email addresses are invalid. Addresses can be separated by a comma, semi-colon or space." ) ]
7182 public string ? FailedNotificationEmailAddress { get ; set ; }
7283
84+ /// <summary>
85+ /// The type of notification that will be sent.
86+ /// </summary>
87+ [ Required ]
88+ public NotificationMethodTypesEnum NotificationMethod { get ; set ; }
89+
7390 public IEnumerable < ValidationResult > Validate ( ValidationContext validationContext )
7491 {
7592 if ( Secret ? . Length > SECRET_MAX_LENGTH )
@@ -86,6 +103,23 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
86103 {
87104 yield return new ValidationResult ( "Cannot create a webhook with a resource type of none." ) ;
88105 }
106+
107+ if ( NotificationMethod is NotificationMethodTypesEnum . None )
108+ {
109+ yield return new ValidationResult ( "Cannot create a webhook with a notification method type of none." ) ;
110+ }
111+
112+ if ( NotificationMethod is NotificationMethodTypesEnum . Email
113+ && string . IsNullOrWhiteSpace ( EmailAddress ) )
114+ {
115+ yield return new ValidationResult ( "Email address is required for email notification method." ) ;
116+ }
117+
118+ if ( NotificationMethod is NotificationMethodTypesEnum . Webhook
119+ && ( string . IsNullOrWhiteSpace ( DestinationUrl ) || string . IsNullOrWhiteSpace ( Secret ) ) )
120+ {
121+ yield return new ValidationResult ( "Destination URL and Secret are required for webhook notification method." ) ;
122+ }
89123 }
90124
91125 public Dictionary < string , string > ToDictionary ( )
@@ -99,7 +133,8 @@ public Dictionary<string, string> ToDictionary()
99133 { nameof ( Secret ) , Secret ?? string . Empty } ,
100134 { nameof ( IsActive ) , IsActive . ToString ( ) } ,
101135 { nameof ( EmailAddress ) , EmailAddress ?? string . Empty } ,
102- { nameof ( FailedNotificationEmailAddress ) , FailedNotificationEmailAddress ?? string . Empty }
136+ { nameof ( FailedNotificationEmailAddress ) , FailedNotificationEmailAddress ?? string . Empty } ,
137+ { nameof ( NotificationMethod ) , NotificationMethod . ToString ( ) }
103138 } ;
104139
105140 if ( ResourceTypes ? . Count ( ) > 0 )
0 commit comments