package Test::ECS;
use strict;
use warnings;
use lib 't/libs';

use Test::ECS::Order;

our $test;

sub new {
	my $class = shift;
	$class = ref $class if ref $class;
	my %params = @_;
	
	# list of actions that need to happen or not happen
	my $actions = {
		invoicedOrder			=> 0,
		packagesHold			=> 0,
	};
	my $options = {
		paymentsFail			=> 0,
		paymentFraud			=> 0,
		orderStatus				=> 'Picked',
		invoiceOrder			=> 0,
		orderID						=> 5,
		products					=> [{
			productID	=> 4056,
			taxExempt	=> 0,
		}],
	};
	%params = (%$options, %params);
	$test = bless { options => \%params, 
					actions	=> $actions
				}, $class;
	return $test;
}

sub clear {
	undef $test
}

{
	package ECS::SQL;
	sub connect {
		bless { }, __PACKAGE__.'::ECS::SQL';
	}
}

{
	package ECS::Order;
	sub load {
		my ($class, $args) = @_;
		$args->{ _test } = $Test::ECS::test;
		$args->{POSinvoice} = $Test::ECS::test->{ options }{ invoiceOrder };
		$args->{status} =  $Test::ECS::test->{ options }{ orderStatus };
		$Test::ECS::test->{ args }{order} = bless $args, 'Test::ECS::Order';
		$Test::ECS::test->{args}{order};
	}
}

{
	package API::Warehouse;
	sub getStationPrinters {
		my ($p) = @_;
		$p->{ labelPrinter } = $Test::ECS::test->{options}{labelPrinter};
		$p->{ formsPrinter } = $Test::ECS::test->{options}{formsPrinter};
		return 1;
	}
}

{ 
	package API::Order;
	sub lock {
		return 1 unless $Test::ECS::test->{options}{lockFail};
	}
	sub mmLock {
		return 1 unless $Test::ECS::test->{options}{mmLockFail};
	}

}

{
	package API::Order::Cart;
	sub getIndividualProducts {
		my $products = $Test::ECS::test->{options}{products};
		return { $Test::ECS::test->{args}{order}{orderID} => $products };
	}
}

{
	package API::Order::Shipping;
	sub getCourier {}
  sub getService {}
  sub getWarehouseShipment {}
  sub getAvailableBoxes {}
}

{
	package API::Order::Shipping::Package;
	sub buildPackageProductDetails {}
	sub getAddressLabel {}
	sub shipPackages {
		$Test::ECS::test->{ options }{ orderStatus } = 'Shipped';
		$Test::ECS::test->{ args }{order}{ status } = 'Shipped';
		1;
	}
	sub addPurchasedNote {}
	sub savePackages {}
	sub holdPackages {
		$Test::ECS::_test->{actions}{packagesHold} = 1;
	}
}

{
	package API::Order::Shipping::Shipment;
  sub savePreviousShipment {}
}

{
	package ECS::Payment::GiftCard;
	sub pendActivateGiftCardsOnOrder {}
	sub activateGiftCardsOnOrder {}
	sub deliverElectronicGiftCards { 0 }
}


{
	package ECS::Shipping::Courier;
	sub isInternational {
		return $Test::ECS::test->{options}{orderIntl};
	}
}

{
	package API::Order::Payment;
	sub invoice {
		$Test::ECS::test->{actions}{invoicedOrder} = 1;
		return 1;
	}
}

{
	package ECS::Order::CartComponent;
	sub pushCartComponentShipped {}
}

{
	package ECS::EMail::Order;
	sub send { 1 }
}

BEGIN {
	# keep the real modules from being loaded
	$INC{ $_ } = __FILE__ for (
			"ECS/SQL.pm",
			"ECS/Order.pm",
			"API/Warehouse.pm",
			"API/Order.pm",
			"API/Order/Cart.pm",
			"API/Order/Shipping.pm",
			"API/Order/Shipping/Package.pm",
			"API/Order/Shipping/Shipment.pm",
			"ECS/Payment/GiftCard.pm",
			"ECS/Shipping/Courier.pm",
			"API/Order/Payment.pm",
			"ECS/Order/CartComponent.pm",
			"ECS/EMail/Order.pm",
		);
}


1;
