@@ -26,9 +26,10 @@ namespace FirebaseAdmin.Auth
2626 /// </summary>
2727 public sealed class UserRecordArgs
2828 {
29- private static readonly object Unspecified = new object ( ) ;
30-
31- private object customClaims = Unspecified ;
29+ private Optional < string > displayName ;
30+ private Optional < string > photoUrl ;
31+ private Optional < string > phoneNumber ;
32+ private Optional < IReadOnlyDictionary < string , object > > customClaims ;
3233 private bool ? disabled = null ;
3334 private bool ? emailVerified = null ;
3435
@@ -45,12 +46,20 @@ public sealed class UserRecordArgs
4546 /// <summary>
4647 /// Gets or sets the phone number of the user.
4748 /// </summary>
48- public string PhoneNumber { get ; set ; }
49+ public string PhoneNumber
50+ {
51+ get => this . phoneNumber ? . Value ;
52+ set => this . phoneNumber = this . Wrap ( value ) ;
53+ }
4954
5055 /// <summary>
5156 /// Gets or sets the display name of the user account.
5257 /// </summary>
53- public string DisplayName { get ; set ; }
58+ public string DisplayName
59+ {
60+ get => this . displayName ? . Value ;
61+ set => this . displayName = this . Wrap ( value ) ;
62+ }
5463
5564 /// <summary>
5665 /// Gets or sets a value indicating whether the user email address has been verified or not.
@@ -64,7 +73,11 @@ public bool EmailVerified
6473 /// <summary>
6574 /// Gets or sets the photo URL of the user.
6675 /// </summary>
67- public string PhotoUrl { get ; set ; }
76+ public string PhotoUrl
77+ {
78+ get => this . photoUrl ? . Value ;
79+ set => this . photoUrl = this . Wrap ( value ) ;
80+ }
6881
6982 /// <summary>
7083 /// Gets or sets a value indicating whether the user account should be disabled by default or not.
@@ -82,8 +95,8 @@ public bool Disabled
8295
8396 internal IReadOnlyDictionary < string , object > CustomClaims
8497 {
85- get => this . GetIfSpecified < Dictionary < string , object > > ( this . customClaims ) ;
86- set => this . customClaims = value ;
98+ get => this . customClaims ? . Value ;
99+ set => this . customClaims = this . Wrap ( value ) ;
87100 }
88101
89102 internal CreateUserRequest ToCreateUserRequest ( )
@@ -212,14 +225,9 @@ private static string CheckCustomClaims(IReadOnlyDictionary<string, object> clai
212225 return customClaimsString ;
213226 }
214227
215- private T GetIfSpecified < T > ( object value )
228+ private Optional < T > Wrap < T > ( T value )
216229 {
217- if ( value == Unspecified )
218- {
219- return default ( T ) ;
220- }
221-
222- return ( T ) value ;
230+ return new Optional < T > ( value ) ;
223231 }
224232
225233 internal sealed class CreateUserRequest
@@ -266,17 +274,118 @@ internal sealed class UpdateUserRequest
266274 internal UpdateUserRequest ( UserRecordArgs args )
267275 {
268276 this . Uid = CheckUid ( args . Uid , required : true ) ;
269- if ( args . customClaims != Unspecified )
277+ if ( args . customClaims != null )
278+ {
279+ this . CustomClaims = CheckCustomClaims ( args . customClaims . Value ) ;
280+ }
281+
282+ this . Disabled = args . disabled ;
283+ this . Email = CheckEmail ( args . Email ) ;
284+ this . EmailVerified = args . emailVerified ;
285+ this . Password = CheckPassword ( args . Password ) ;
286+
287+ if ( args . displayName != null )
270288 {
271- this . CustomClaims = CheckCustomClaims ( args . CustomClaims ) ;
289+ var displayName = args . displayName . Value ;
290+ if ( displayName == null )
291+ {
292+ this . AddDeleteAttribute ( "DISPLAY_NAME" ) ;
293+ }
294+ else
295+ {
296+ this . DisplayName = displayName ;
297+ }
298+ }
299+
300+ if ( args . photoUrl != null )
301+ {
302+ var photoUrl = args . photoUrl . Value ;
303+ if ( photoUrl == null )
304+ {
305+ this . AddDeleteAttribute ( "PHOTO_URL" ) ;
306+ }
307+ else
308+ {
309+ this . PhotoUrl = CheckPhotoUrl ( photoUrl ) ;
310+ }
311+ }
312+
313+ if ( args . phoneNumber != null )
314+ {
315+ var phoneNumber = args . phoneNumber . Value ;
316+ if ( phoneNumber == null )
317+ {
318+ this . AddDeleteProvider ( "phone" ) ;
319+ }
320+ else
321+ {
322+ this . PhoneNumber = CheckPhoneNumber ( phoneNumber ) ;
323+ }
272324 }
273325 }
274326
327+ [ JsonProperty ( "customAttributes" ) ]
328+ public string CustomClaims { get ; set ; }
329+
330+ [ JsonProperty ( "deleteAttribute" ) ]
331+ public IList < string > DeleteAttribute { get ; set ; }
332+
333+ [ JsonProperty ( "deleteProvider" ) ]
334+ public IList < string > DeleteProvider { get ; set ; }
335+
336+ [ JsonProperty ( "disableUser" ) ]
337+ public bool ? Disabled { get ; set ; }
338+
339+ [ JsonProperty ( "displayName" ) ]
340+ public string DisplayName { get ; set ; }
341+
342+ [ JsonProperty ( "email" ) ]
343+ public string Email { get ; set ; }
344+
345+ [ JsonProperty ( "emailVerified" ) ]
346+ public bool ? EmailVerified { get ; set ; }
347+
348+ [ JsonProperty ( "password" ) ]
349+ public string Password { get ; set ; }
350+
351+ [ JsonProperty ( "phoneNumber" ) ]
352+ public string PhoneNumber { get ; set ; }
353+
354+ [ JsonProperty ( "photoUrl" ) ]
355+ public string PhotoUrl { get ; set ; }
356+
275357 [ JsonProperty ( "localId" ) ]
276358 public string Uid { get ; set ; }
277359
278- [ JsonProperty ( "customAttributes" ) ]
279- public string CustomClaims { get ; set ; }
360+ private void AddDeleteAttribute ( string attribute )
361+ {
362+ if ( this . DeleteAttribute == null )
363+ {
364+ this . DeleteAttribute = new List < string > ( ) ;
365+ }
366+
367+ this . DeleteAttribute . Add ( attribute ) ;
368+ }
369+
370+ private void AddDeleteProvider ( string provider )
371+ {
372+ if ( this . DeleteProvider == null )
373+ {
374+ this . DeleteProvider = new List < string > ( ) ;
375+ }
376+
377+ this . DeleteProvider . Add ( provider ) ;
378+ }
379+ }
380+
381+ internal class Optional < T >
382+ {
383+ internal Optional ( T value )
384+ {
385+ this . Value = value ;
386+ }
387+
388+ internal T Value { get ; private set ; }
280389 }
281390 }
282391}
0 commit comments