<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Arr;
use Tests\TestCase;
use App\Models\Product;
use App\Models\Service;

class ProductAdslTest extends TestCase
{
	public function testTraffic()
	{
		/*
		// Test ADSL/NBN Traffic Calculations
		$traffic = [
			'base_down_peak'=>50,
			'base_up_peak'=>50,
			'base_down_offpeak'=>20,
			'base_up_offpeak'=>20,
		];

		// A:Unlimited
		$o = factory(Service::class)->states('month')->make();
		$o->setRelation('product',factory(Product::class)->states('broadband-unlimit')->make());
		$x=$o->product->type->allowance($traffic);
		$this->assertEquals(0,count($x),'A:Traffic is unlimited');

		// ** Extra Traffic Charged **
		// B:140GB All Traffic Counted (uploads and download - no peak periods)
		$o = factory(Service::class)->states('month')->make();
		$o->setRelation('product',factory(Product::class)->states('broadband-140/0/0/0')->make());
		$x = $o->product->type->allowance($traffic);
		$this->assertEquals(1,count($x),'B:Traffic is 140GB');
		$this->assertArrayHasKey('base_down_peak',$x,'B:Traffic has base_down_peak key for 140GB');
		$this->assertEquals(0,Arr::get($x,'base_down_peak'),'B:Traffic base_down_peak equals 140GB');

		// C:70GB Download - Uploads Not Counted
		$o = factory(Service::class)->states('month')->make();
		$o->setRelation('product',factory(Product::class)->states('broadband-70/-/0/-')->make());
		$x=$o->product->type->allowance($traffic);
		$this->assertEquals(1,count($x),'C:Traffic is 70GB');
		$this->assertArrayHasKey('base_down_peak',$x,'C:Traffic has base_down_peak key for 70GB');
		$this->assertEquals(0,Arr::get($x,'base_down_peak'),'C:Traffic base_down_peak equals 70GB');

		// D:100GB Peak / 40GB OffPeak - No Free Uploads
		$o = factory(Service::class)->states('month')->make();
		$o->setRelation('product',factory(Product::class)->states('broadband-100/0/40/0')->make());
		$x=$o->product->type->allowance($traffic);
		$this->assertEquals(2,count($x),'D:Traffic is 140/40GB');
		$this->assertArrayHasKey('base_down_peak',$x,'D:Traffic has base_down_peak key for 100GB');
		$this->assertArrayHasKey('base_down_offpeak',$x,'D:Traffic has base_down_offpeak key for 40GB');
		$this->assertEquals(0,Arr::get($x,'base_down_peak'),'D:Traffic base_down_peak equals 100GB');
		$this->assertEquals(0,Arr::get($x,'base_down_offpeak'),'D:Traffic base_down_offpeak equals 40GB');

		// 50GB Peak / 20GB OffPeak - Uploads Not Counted
		$o = factory(Service::class)->states('month')->make();
		$o->setRelation('product',factory(Product::class)->states('broadband-50/-/20/-')->make());
		$x=$o->product->type->allowance($traffic);
		$this->assertEquals(2,count($x),'E:Traffic is 50/20GB');
		$this->assertArrayHasKey('base_down_peak',$x,'E:Traffic has base_down_peak key for 50GB');
		$this->assertArrayHasKey('base_down_offpeak',$x,'E:Traffic has base_down_offpeak key for 20GB');
		$this->assertEquals(0,Arr::get($x,'base_down_peak'),'E:Traffic base_down_peak equals 50GB');
		$this->assertEquals(0,Arr::get($x,'base_down_offpeak'),'E:Traffic base_down_offpeak equals 20GB');

		// ** Extra Traffic NOT Charged - Service Shaped **
		// 100GB All Traffic (uploads and download - no peak periods)

		// 100GB Download - Uploads Not Counted

		// 100GB Peak / 200GB OffPeak - No Free Uploads

		// 100GB Peak / 200GB OffPeak - Uploads Not Counted
		*/
	}
}