//
//  MyUser+DictRepresentation.m
//  react-native-rainbow-module
//
//  Created by Doha Tubaileh on 07/08/2022.
//

#import "MyUser+DictRepresentation.h"
#import "Contact+DictRepresentation.h"

@implementation MyUser (DictRepresentation)

- (NSDictionary *) myUserDictionaryRepresentation {
    NSLog(@"[%@] %@",[self class], NSStringFromSelector(_cmd));
    NSMutableDictionary *myUserDict = [[NSMutableDictionary alloc] init];
    [myUserDict setValue:self.contact.contactDictionaryRepresentation forKey:@"contact"];
    BOOL isNomadicModeActivated = self.nomadicStatus.activated;
    [myUserDict setValue:[NSNumber numberWithBool: isNomadicModeActivated] forKey:@"nomadic"];
    [myUserDict setValue:[self getMyUserNomadicPhoneNumber] forKey:@"nomadicNumber"];
    [myUserDict setValue:self.getServicePlan forKey:@"servicePlane"];
    [myUserDict setValue:self.contact.language forKey:@"language"];
    [myUserDict setValue:[NSNumber numberWithBool: self.isAllowedToChangePresence] forKey:@"isAllowedToChangePresence"];
    [myUserDict setValue:[NSNumber numberWithBool: self.isAllowedToModifyProfileInfo] forKey:@"isAllowedToModifyProfileInfo"];
    [myUserDict setValue:self.customData forKey:@"customData"];
    
    return myUserDict;
}

-(PhoneNumber *) getMyUserNomadicPhoneNumber {
    NSLog(@"[Telephony] getMyUserDeviceNumber");
    PhoneNumber *myUserWorkMobile = [self.contact getPhoneNumberOfType:PhoneNumberTypeWork withDeviceType:PhoneNumberDeviceTypeMobile];
    PhoneNumber *myUserPersonalMobile = [self.contact getPhoneNumberOfType:PhoneNumberTypeHome withDeviceType:PhoneNumberDeviceTypeMobile];
    
    if (myUserWorkMobile) {
        return myUserWorkMobile;
    }
    else if (myUserPersonalMobile) {
        return myUserPersonalMobile;
    }
    
    return nil;
}


@end
