#import "BusStop.h"
#import "Lang.h"
#import "CocoaUtils.h"

@implementation BusStop

- (BOOL)isEqual:(id)object {
	if (self == object) {
		return YES;
	}
	if (![object isKindOfClass:self.class]) {
		return NO;
	}
	return self.hash == [object hash];
}

- (NSUInteger)hash {
	return self.reference != 0 ? self.reference : [super hash];
}

#pragma mark - Property

- (MapViewAnnotation *)wrappedAnnotation {
	MapViewAnnotation *annotation = [[MapViewAnnotation alloc] init];
	annotation.coordinate = CLLocationCoordinate2DMake(self.station.latitude, self.station.longitude);
	annotation.label = self.option_value;
	annotation.value = self.option_value;
	annotation.title = self.option_value;
	annotation.subtitle = self.address_desc;
	annotation.pinTintColor = [MKPinAnnotationView redPinColor];
	return annotation;
}

- (NSString *)ss_time {
	if (_ss_time) {
		return _ss_time;
	} else if (!self.is_arrival && self.ad_time) {
		return self.ad_time;
	} else if (self.is_arrival && self.rt_time) {
		return self.rt_time;
	} else if (self.time_value) {
		return [CocoaUtils localizedStringFromDate:[DateUtils parseDate:self.time_value parsePatterns:@"HH:mm", nil] template:@"hmma"];
	}
	return nil;
}

#pragma mark - Public

- (BOOL)checkAvailable:(NSString *)serviceDate {
	if (self.date_string) {
		return [self.date_string rangeOfString:serviceDate].location != NSNotFound;
	}
	return YES;
}

+ (NSArray *)toAnnotations:(NSArray *)stationList {
	return [stationList valueForKeyPath:@"wrappedAnnotation"];
}

@end
