///
/// Copyright (c) 2016 Dropbox, Inc. All rights reserved.
///
/// Auto-generated by Stone, do not modify.
///

/// Arguments, results, and errors for the `Openid` namespace.

#import "DBOPENIDOpenIdError.h"
#import "DBStoneSerializers.h"
#import "DBStoneValidators.h"

#pragma mark - API Object

@implementation DBOPENIDOpenIdError

#pragma mark - Constructors

- (instancetype)initWithIncorrectOpenidScopes {
  self = [super init];
  if (self) {
    _tag = DBOPENIDOpenIdErrorIncorrectOpenidScopes;
  }
  return self;
}

- (instancetype)initWithOther {
  self = [super init];
  if (self) {
    _tag = DBOPENIDOpenIdErrorOther;
  }
  return self;
}

#pragma mark - Instance field accessors

#pragma mark - Tag state methods

- (BOOL)isIncorrectOpenidScopes {
  return _tag == DBOPENIDOpenIdErrorIncorrectOpenidScopes;
}

- (BOOL)isOther {
  return _tag == DBOPENIDOpenIdErrorOther;
}

- (NSString *)tagName {
  switch (_tag) {
  case DBOPENIDOpenIdErrorIncorrectOpenidScopes:
    return @"DBOPENIDOpenIdErrorIncorrectOpenidScopes";
  case DBOPENIDOpenIdErrorOther:
    return @"DBOPENIDOpenIdErrorOther";
  }

  @throw([NSException exceptionWithName:@"InvalidTag" reason:@"Tag has an unknown value." userInfo:nil]);
}

#pragma mark - Serialization methods

+ (nullable NSDictionary<NSString *, id> *)serialize:(id)instance {
  return [DBOPENIDOpenIdErrorSerializer serialize:instance];
}

+ (id)deserialize:(NSDictionary<NSString *, id> *)dict {
  return [DBOPENIDOpenIdErrorSerializer deserialize:dict];
}

#pragma mark - Debug Description method

- (NSString *)debugDescription {
  return [[DBOPENIDOpenIdErrorSerializer serialize:self] description];
}

#pragma mark - Copyable method

- (instancetype)copyWithZone:(NSZone *)zone {
#pragma unused(zone)
  /// object is immutable
  return self;
}

#pragma mark - Hash method

- (NSUInteger)hash {
  NSUInteger prime = 31;
  NSUInteger result = 1;

  switch (_tag) {
  case DBOPENIDOpenIdErrorIncorrectOpenidScopes:
    result = prime * result + [[self tagName] hash];
    break;
  case DBOPENIDOpenIdErrorOther:
    result = prime * result + [[self tagName] hash];
    break;
  }

  return prime * result;
}

#pragma mark - Equality method

- (BOOL)isEqual:(id)other {
  if (other == self) {
    return YES;
  }
  if (!other || ![other isKindOfClass:[self class]]) {
    return NO;
  }
  return [self isEqualToOpenIdError:other];
}

- (BOOL)isEqualToOpenIdError:(DBOPENIDOpenIdError *)anOpenIdError {
  if (self == anOpenIdError) {
    return YES;
  }
  if (self.tag != anOpenIdError.tag) {
    return NO;
  }
  switch (_tag) {
  case DBOPENIDOpenIdErrorIncorrectOpenidScopes:
    return [[self tagName] isEqual:[anOpenIdError tagName]];
  case DBOPENIDOpenIdErrorOther:
    return [[self tagName] isEqual:[anOpenIdError tagName]];
  }
  return YES;
}

@end

#pragma mark - Serializer Object

@implementation DBOPENIDOpenIdErrorSerializer

+ (NSDictionary<NSString *, id> *)serialize:(DBOPENIDOpenIdError *)valueObj {
  NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];

  if ([valueObj isIncorrectOpenidScopes]) {
    jsonDict[@".tag"] = @"incorrect_openid_scopes";
  } else if ([valueObj isOther]) {
    jsonDict[@".tag"] = @"other";
  } else {
    jsonDict[@".tag"] = @"other";
  }

  return jsonDict;
}

+ (DBOPENIDOpenIdError *)deserialize:(NSDictionary<NSString *, id> *)valueDict {
  NSString *tag = valueDict[@".tag"];

  if ([tag isEqualToString:@"incorrect_openid_scopes"]) {
    return [[DBOPENIDOpenIdError alloc] initWithIncorrectOpenidScopes];
  } else if ([tag isEqualToString:@"other"]) {
    return [[DBOPENIDOpenIdError alloc] initWithOther];
  } else {
    return [[DBOPENIDOpenIdError alloc] initWithOther];
  }
}

@end

#import "DBOPENIDUserInfoArgs.h"
#import "DBStoneSerializers.h"
#import "DBStoneValidators.h"

#pragma mark - API Object

@implementation DBOPENIDUserInfoArgs

#pragma mark - Constructors

- (instancetype)initDefault {

  self = [super init];
  if (self) {
  }
  return self;
}

#pragma mark - Serialization methods

+ (nullable NSDictionary<NSString *, id> *)serialize:(id)instance {
  return [DBOPENIDUserInfoArgsSerializer serialize:instance];
}

+ (id)deserialize:(NSDictionary<NSString *, id> *)dict {
  return [DBOPENIDUserInfoArgsSerializer deserialize:dict];
}

#pragma mark - Debug Description method

- (NSString *)debugDescription {
  return [[DBOPENIDUserInfoArgsSerializer serialize:self] description];
}

#pragma mark - Copyable method

- (instancetype)copyWithZone:(NSZone *)zone {
#pragma unused(zone)
  /// object is immutable
  return self;
}

#pragma mark - Hash method

- (NSUInteger)hash {
  NSUInteger prime = 31;
  NSUInteger result = 1;

  return prime * result;
}

#pragma mark - Equality method

- (BOOL)isEqual:(id)other {
  if (other == self) {
    return YES;
  }
  if (!other || ![other isKindOfClass:[self class]]) {
    return NO;
  }
  return [self isEqualToUserInfoArgs:other];
}

- (BOOL)isEqualToUserInfoArgs:(DBOPENIDUserInfoArgs *)anUserInfoArgs {
  if (self == anUserInfoArgs) {
    return YES;
  }
  return YES;
}

@end

#pragma mark - Serializer Object

@implementation DBOPENIDUserInfoArgsSerializer

+ (NSDictionary<NSString *, id> *)serialize:(DBOPENIDUserInfoArgs *)valueObj {
#pragma unused(valueObj)
  NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];

  return jsonDict;
}

+ (DBOPENIDUserInfoArgs *)deserialize:(NSDictionary<NSString *, id> *)valueDict {
#pragma unused(valueDict)

  return [[DBOPENIDUserInfoArgs alloc] initDefault];
}

@end

#import "DBOPENIDOpenIdError.h"
#import "DBOPENIDUserInfoError.h"
#import "DBStoneSerializers.h"
#import "DBStoneValidators.h"

#pragma mark - API Object

@implementation DBOPENIDUserInfoError

@synthesize openidError = _openidError;

#pragma mark - Constructors

- (instancetype)initWithOpenidError:(DBOPENIDOpenIdError *)openidError {
  self = [super init];
  if (self) {
    _tag = DBOPENIDUserInfoErrorOpenidError;
    _openidError = openidError;
  }
  return self;
}

- (instancetype)initWithOther {
  self = [super init];
  if (self) {
    _tag = DBOPENIDUserInfoErrorOther;
  }
  return self;
}

#pragma mark - Instance field accessors

- (DBOPENIDOpenIdError *)openidError {
  if (![self isOpenidError]) {
    [NSException raise:@"IllegalStateException"
                format:@"Invalid tag: required DBOPENIDUserInfoErrorOpenidError, but was %@.", [self tagName]];
  }
  return _openidError;
}

#pragma mark - Tag state methods

- (BOOL)isOpenidError {
  return _tag == DBOPENIDUserInfoErrorOpenidError;
}

- (BOOL)isOther {
  return _tag == DBOPENIDUserInfoErrorOther;
}

- (NSString *)tagName {
  switch (_tag) {
  case DBOPENIDUserInfoErrorOpenidError:
    return @"DBOPENIDUserInfoErrorOpenidError";
  case DBOPENIDUserInfoErrorOther:
    return @"DBOPENIDUserInfoErrorOther";
  }

  @throw([NSException exceptionWithName:@"InvalidTag" reason:@"Tag has an unknown value." userInfo:nil]);
}

#pragma mark - Serialization methods

+ (nullable NSDictionary<NSString *, id> *)serialize:(id)instance {
  return [DBOPENIDUserInfoErrorSerializer serialize:instance];
}

+ (id)deserialize:(NSDictionary<NSString *, id> *)dict {
  return [DBOPENIDUserInfoErrorSerializer deserialize:dict];
}

#pragma mark - Debug Description method

- (NSString *)debugDescription {
  return [[DBOPENIDUserInfoErrorSerializer serialize:self] description];
}

#pragma mark - Copyable method

- (instancetype)copyWithZone:(NSZone *)zone {
#pragma unused(zone)
  /// object is immutable
  return self;
}

#pragma mark - Hash method

- (NSUInteger)hash {
  NSUInteger prime = 31;
  NSUInteger result = 1;

  switch (_tag) {
  case DBOPENIDUserInfoErrorOpenidError:
    result = prime * result + [self.openidError hash];
    break;
  case DBOPENIDUserInfoErrorOther:
    result = prime * result + [[self tagName] hash];
    break;
  }

  return prime * result;
}

#pragma mark - Equality method

- (BOOL)isEqual:(id)other {
  if (other == self) {
    return YES;
  }
  if (!other || ![other isKindOfClass:[self class]]) {
    return NO;
  }
  return [self isEqualToUserInfoError:other];
}

- (BOOL)isEqualToUserInfoError:(DBOPENIDUserInfoError *)anUserInfoError {
  if (self == anUserInfoError) {
    return YES;
  }
  if (self.tag != anUserInfoError.tag) {
    return NO;
  }
  switch (_tag) {
  case DBOPENIDUserInfoErrorOpenidError:
    return [self.openidError isEqual:anUserInfoError.openidError];
  case DBOPENIDUserInfoErrorOther:
    return [[self tagName] isEqual:[anUserInfoError tagName]];
  }
  return YES;
}

@end

#pragma mark - Serializer Object

@implementation DBOPENIDUserInfoErrorSerializer

+ (NSDictionary<NSString *, id> *)serialize:(DBOPENIDUserInfoError *)valueObj {
  NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];

  if ([valueObj isOpenidError]) {
    jsonDict[@"openid_error"] = [[DBOPENIDOpenIdErrorSerializer serialize:valueObj.openidError] mutableCopy];
    jsonDict[@".tag"] = @"openid_error";
  } else if ([valueObj isOther]) {
    jsonDict[@".tag"] = @"other";
  } else {
    jsonDict[@".tag"] = @"other";
  }

  return jsonDict;
}

+ (DBOPENIDUserInfoError *)deserialize:(NSDictionary<NSString *, id> *)valueDict {
  NSString *tag = valueDict[@".tag"];

  if ([tag isEqualToString:@"openid_error"]) {
    DBOPENIDOpenIdError *openidError = [DBOPENIDOpenIdErrorSerializer deserialize:valueDict[@"openid_error"]];
    return [[DBOPENIDUserInfoError alloc] initWithOpenidError:openidError];
  } else if ([tag isEqualToString:@"other"]) {
    return [[DBOPENIDUserInfoError alloc] initWithOther];
  } else {
    return [[DBOPENIDUserInfoError alloc] initWithOther];
  }
}

@end

#import "DBOPENIDUserInfoResult.h"
#import "DBStoneSerializers.h"
#import "DBStoneValidators.h"

#pragma mark - API Object

@implementation DBOPENIDUserInfoResult

#pragma mark - Constructors

- (instancetype)initWithFamilyName:(NSString *)familyName
                         givenName:(NSString *)givenName
                             email:(NSString *)email
                     emailVerified:(NSNumber *)emailVerified
                               iss:(NSString *)iss
                               sub:(NSString *)sub {

  self = [super init];
  if (self) {
    _familyName = familyName;
    _givenName = givenName;
    _email = email;
    _emailVerified = emailVerified;
    _iss = iss ?: @"";
    _sub = sub ?: @"";
  }
  return self;
}

- (instancetype)initDefault {
  return [self initWithFamilyName:nil givenName:nil email:nil emailVerified:nil iss:nil sub:nil];
}

#pragma mark - Serialization methods

+ (nullable NSDictionary<NSString *, id> *)serialize:(id)instance {
  return [DBOPENIDUserInfoResultSerializer serialize:instance];
}

+ (id)deserialize:(NSDictionary<NSString *, id> *)dict {
  return [DBOPENIDUserInfoResultSerializer deserialize:dict];
}

#pragma mark - Debug Description method

- (NSString *)debugDescription {
  return [[DBOPENIDUserInfoResultSerializer serialize:self] description];
}

#pragma mark - Copyable method

- (instancetype)copyWithZone:(NSZone *)zone {
#pragma unused(zone)
  /// object is immutable
  return self;
}

#pragma mark - Hash method

- (NSUInteger)hash {
  NSUInteger prime = 31;
  NSUInteger result = 1;

  if (self.familyName != nil) {
    result = prime * result + [self.familyName hash];
  }
  if (self.givenName != nil) {
    result = prime * result + [self.givenName hash];
  }
  if (self.email != nil) {
    result = prime * result + [self.email hash];
  }
  if (self.emailVerified != nil) {
    result = prime * result + [self.emailVerified hash];
  }
  result = prime * result + [self.iss hash];
  result = prime * result + [self.sub hash];

  return prime * result;
}

#pragma mark - Equality method

- (BOOL)isEqual:(id)other {
  if (other == self) {
    return YES;
  }
  if (!other || ![other isKindOfClass:[self class]]) {
    return NO;
  }
  return [self isEqualToUserInfoResult:other];
}

- (BOOL)isEqualToUserInfoResult:(DBOPENIDUserInfoResult *)anUserInfoResult {
  if (self == anUserInfoResult) {
    return YES;
  }
  if (self.familyName) {
    if (![self.familyName isEqual:anUserInfoResult.familyName]) {
      return NO;
    }
  }
  if (self.givenName) {
    if (![self.givenName isEqual:anUserInfoResult.givenName]) {
      return NO;
    }
  }
  if (self.email) {
    if (![self.email isEqual:anUserInfoResult.email]) {
      return NO;
    }
  }
  if (self.emailVerified) {
    if (![self.emailVerified isEqual:anUserInfoResult.emailVerified]) {
      return NO;
    }
  }
  if (![self.iss isEqual:anUserInfoResult.iss]) {
    return NO;
  }
  if (![self.sub isEqual:anUserInfoResult.sub]) {
    return NO;
  }
  return YES;
}

@end

#pragma mark - Serializer Object

@implementation DBOPENIDUserInfoResultSerializer

+ (NSDictionary<NSString *, id> *)serialize:(DBOPENIDUserInfoResult *)valueObj {
  NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];

  if (valueObj.familyName) {
    jsonDict[@"family_name"] = valueObj.familyName;
  }
  if (valueObj.givenName) {
    jsonDict[@"given_name"] = valueObj.givenName;
  }
  if (valueObj.email) {
    jsonDict[@"email"] = valueObj.email;
  }
  if (valueObj.emailVerified) {
    jsonDict[@"email_verified"] = valueObj.emailVerified;
  }
  jsonDict[@"iss"] = valueObj.iss;
  jsonDict[@"sub"] = valueObj.sub;

  return jsonDict;
}

+ (DBOPENIDUserInfoResult *)deserialize:(NSDictionary<NSString *, id> *)valueDict {
  NSString *familyName = valueDict[@"family_name"] ?: nil;
  NSString *givenName = valueDict[@"given_name"] ?: nil;
  NSString *email = valueDict[@"email"] ?: nil;
  NSNumber *emailVerified = valueDict[@"email_verified"] ?: nil;
  NSString *iss = valueDict[@"iss"] ?: @"";
  NSString *sub = valueDict[@"sub"] ?: @"";

  return [[DBOPENIDUserInfoResult alloc] initWithFamilyName:familyName
                                                  givenName:givenName
                                                      email:email
                                              emailVerified:emailVerified
                                                        iss:iss
                                                        sub:sub];
}

@end
