//
//  MemberObject.m
//  LifeLog
//
//  Created by nvtu on 8/18/17.
//  Copyright © 2017 PhongNV. All rights reserved.
//

#import "MemberObject.h"
#import "Utilities.h"

@implementation MemberObject

-(id) initWithData : (NSDictionary *) dict {
    if([dict objectForKey:@"user_id"] != nil) {
        self.userID = [dict[@"user_id"] intValue];
    }
    if([dict objectForKey:@"gender"] != nil) {
        self.gender = [dict[@"gender"] intValue];
    }
    if([dict objectForKey:@"username"] != nil) {
        self.userName = dict[@"username"];
    }
    if([dict objectForKey:@"nickname"] != nil) {
        self.nickName = dict[@"nickname"];
    }
    if([dict objectForKey:@"profile_image"] != nil) {
        self.avatar = dict[@"profile_image"];
    }
    if([dict objectForKey:@"birthday"] != nil) {
        NSString *dateString = dict[@"birthday"];
        self.birthDay = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd"];
    }
    else {
        self.birthDay = [NSDate date];
    }
    if([dict objectForKey:@"join_date"] != nil) {
        NSString *dateString = dict[@"join_date"];
        self.joinDate = [Utilities dateFromString:dateString withFormat:@"yyyy-MM-dd HH:mm:ss"];
    }
    else {
        self.joinDate = [NSDate date];
    }
    return self;
}

@end
