//
//  InterceptionManager.m
//  Project
//
//  Created by Vae on 2019/2/13.
//

#import "InterceptionManager.h"
#import "BaseInterception.h"

@interface InterceptionManager()
@property(nonatomic, strong) NSMutableArray * interceptionArray;

@end

@implementation InterceptionManager

+ (instancetype)sharedManager {
	static dispatch_once_t onceToken;
	static InterceptionManager *manager;
	dispatch_once(&onceToken, ^{
		manager = [[self alloc] init];
	});
	return manager;
}

-(NSMutableArray *)interceptionArray{
	if (!_interceptionArray) {
		_interceptionArray = [NSMutableArray array];
		if (NSClassFromString(@"BusInterception")) {
			BaseInterception *busInterception = [[NSClassFromString(@"BusInterception") alloc] init];
			[_interceptionArray addObject:busInterception];
		}
		if (NSClassFromString(@"TourInterception")) {
			BaseInterception *tourinterception = [[NSClassFromString(@"TourInterception") alloc] init];
			[_interceptionArray addObject:tourinterception];
		}
		if (NSClassFromString(@"HotelInterception")) {
			BaseInterception *hotelIntercetion = [[NSClassFromString(@"HotelInterception") alloc] init];
			[_interceptionArray addObject:hotelIntercetion];
		}
	}
	return _interceptionArray;
}


-(BOOL )handleUrlString:(NSString *)urlString{
	BOOL isHandle = NO;
	for (BaseInterception *interception in self.interceptionArray) {
		isHandle = 	[interception handleUrl:[NSURL URLWithString:urlString]];
		if (isHandle) {
			break;
		}
	}
	return isHandle;
}

@end
