//
// ShopCarts.m
// GoToBus
//
// Created by iphone development on 7/19/14.
//
//

#import "ShopCarts.h"
#import <BlocksKit/BlocksKit.h>
#import "User.h"
#import "PerlWS.h"
#import "Vars.h"

@implementation ShopCarts

- (instancetype)init {
	if (self = [super init]) {
		[self empty];
	}
	return self;
}

#pragma mark - Property

- (NSString *)currency_code {
	return self.bookGoods.paymentInfo.currency_code;
}

- (BOOL)rmb_selected {
	return [self.currency_code isEqualToString:@"cny"];
}

- (void)setRmb_selected:(BOOL)rmb_selected {
	self.bookGoods.paymentInfo.currency_code = rmb_selected ? @"cny" : @"usd";
}

- (BOOL)hasBusHotelPackage {
	BOOL hasBus = [self.entries bk_any:^BOOL (CartEntry *obj) {
		return obj.product.is_bus;
	}];
	BOOL hasHotel = [self.entries bk_any:^BOOL (CartEntry *obj) {
		return obj.product.is_hotel;
	}];
	return hasBus && hasHotel;
}

#pragma mark - Public

- (void)empty {
	self.adultNum = 0;
	self.childNum = 0;
	self.roomBasedCountDatas = nil;
	self.entries = [NSMutableArray array];
	if (NSClassFromString(@"BookBus")) {
		self.bookGoods = [[NSClassFromString(@"BookBus") alloc] init];
	} else if (NSClassFromString(@"BookTour")) {
		self.bookGoods = [[NSClassFromString(@"BookTour") alloc] init];
	}
	self.rmb_selected = [Vars is_cn_website];
}

- (void)clearPreSale {
	self.bookGoods.couponCode = nil;
	self.bookGoods.paymentInfo.payment_type = self.rmb_selected ? 12 : 2;
	self.bookGoods.paymentInfo.credit_card = [[CreditCard alloc] init];
	self.bookGoods.paymentInfo.paypal_payment = [[_PaypalPayment alloc] init];
	self.bookGoods.paymentInfo.wechatpay_payment = [[_WechatpayPayment alloc] init];
	self.bookGoods.paymentInfo.alipay_payment = [[_AlipayPayment alloc] init];
	self.bookGoods.paymentInfo.unionpay_payment = [[_UnionpayPayment alloc] init];
}

#pragma mark - Private

@end
