//
// Passport.m
// IvyMedia
//
// Created by haibara on 10/27/14.
//
//

#import "Passport.h"
#import "Lang.h"
#import "BeanUtils.h"
#import "CocoaUtils.h"
#import "Address.h"

@implementation Passport

- (id)copyWithZone:(NSZone *)zone {
	return [BeanUtils copyWithZone:zone origin:self];
}

#pragma mark - Property

- (NSString *)shortDescription {
	return self.distinguish_passport && self.is_us_citizen ? self.us_id_number : self.passport_number;
}

- (NSString *)fullName {
	NSMutableArray *array = [NSMutableArray array];
	if (self.distinguish_passport && self.is_us_citizen) {
		[array addObject:self.us_name];
		if (![StringUtils isEmpty:self.us_mid_name]) {
			[array addObject:self.us_mid_name];
		}
		if (![StringUtils isEmpty:self.us_last_name]) {
			[array addObject:self.us_last_name];
		}
	} else {
		[array addObject:self.name];
		if (![StringUtils isEmpty:self.mid_name]) {
			[array addObject:self.mid_name];
		}
		if (![StringUtils isEmpty:self.last_name]) {
			[array addObject:self.last_name];
		}
	}
	return [array componentsJoinedByString:@" "];
}

#pragma mark - Public

- (instancetype)initAsDistinguish {
	self = [super init];
	if (self) {
		self.distinguish_passport = YES;
		self.is_us_citizen = YES;
	}
	return self;
}

- (NSString *)innerXML {
	return [CocoaUtils xmlStringWithProperties:[BeanUtils describeAccessibleSimple:self]];
}

- (void)trim {
	if (self.distinguish_passport && self.is_us_citizen) {
		self.name = nil;
		self.mid_name = nil;
		self.last_name = nil;
		self.gender = nil;
		self.birth_date = nil;
		self.country = nil;
		self.passport_number = nil;
		self.expiration_date = nil;
		self.issue_date = nil;
		self.emergency_contact_person = nil;
		self.emergency_phone = nil;
	} else {
		self.us_name = nil;
		self.us_mid_name = nil;
		self.us_last_name = nil;
		self.us_gender = nil;
		self.us_id_type = nil;
		self.us_id_number = nil;
		self.us_expiration_date = nil;
		self.us_issue_date = nil;
		self.us_emergency_contact_person = nil;
		self.us_emergency_phone = nil;
	}
}

@end
