#pragma once
#include <cstdio>
#include <iostream>
#include "uXgtcBurst.h"
#include "Olt.h"
#include "main.h"
#include "Simulator.h"

int main(int argc, char* argv[], char *envp[])
{
	int x = 0;
	int16_t timeEnd = 1;
	int16_t pocetOnu = 5;
	int16_t dbaAlgoritmus = 1;
	uint16_t rychlostDatovehoToku = 16;

	while ((++argv)[0])
	{
		if (argv[0][0] == '-')
		{
			switch (argv[0][1]) {

			default:
				printf("Neznama volba -%c\n\n", argv[0][1]);
			case 'h':
				printf("Napoveda:\n -h ... Napoveda\n -t ... Cas simulace v sekundach\n -n ... Pocet ONU jednotek \n -d ... DBA algoritmus \n \t 0 ... Staticke pridelelni sirky pasma \n \t 1 ... HYRA dba algoritmus \n \t 2 ... MaxMin dba algoritmus \n \t 3 ... GIANT dba algoritmus \n -z ... zatizeni site v kB/s generovane jednou ONU jednotkou \n");
				
				return 0;
				break;
			case 't':
				x = atoi(argv[1]);
				if (x < 1)
				{
					std::cout << "Byla zadana hodnota: " << x << ". Musi byt zadana hodnota vetsi nez 0.\n";
				}
				else
					timeEnd = x;
				break;
			case 'n':
				x = atoi(argv[1]);
				if (x < 1)
				{
					std::cout << "Byla zadana hodnota: " << x << ". Musi byt zadana hodnota vetsi nez 0.\n";
				}
				else
					pocetOnu = x;
				break;
			case 'd':
				x = atoi(argv[1]);
				if (x < 0 || x > 3)
				{
					std::cout << "Byla zadana hodnota: " << x << ". Musi byt zadana hodnota v rozmezi 0 - 3.\n";
					return 0;
				}
				else
					dbaAlgoritmus = x;
				break;
			case 'z':
				x = atoi(argv[1]);
				if (x < 0 || x > 1000000)
				{
					std::cout << "Byla zadana hodnota: " << x << ". Musi byt zadana hodnota v rozmezi 0 - 1000000.\n";
				}
				else
					rychlostDatovehoToku = x;
				break;
			}
		}

	}	
	std::cout << "Aplikace spustena" << std::endl;
	std::cout << "Cas simulace: " << timeEnd << std::endl;
	std::cout << "Kazda ONU jednotka generuje upstream zatizeni site o velikosti: " << rychlostDatovehoToku << " kB/s" << std::endl;
	
	std::vector<Onu> Onus;
	uint16_t pocetAllocId = 4; 
	Olt olt = Olt(dbaAlgoritmus, pocetOnu, pocetAllocId);
	for (int16_t i = 0; i < pocetOnu; i++)
	{
		Onu onu = Onu(i, pocetAllocId, rychlostDatovehoToku);
		Onus.push_back(onu);
	}
	std::cout << pocetOnu << " ONU jednotek pripojeno k siti." << std::endl;

	if(dbaAlgoritmus==(uint16_t)0)
		std::cout << "Bylo zvoleno staticke prideleni sirky pasma." << std::endl;
	else if (dbaAlgoritmus == (uint16_t)1)
		std::cout << "Byl zvolen HYRA dba algoritmus." << std::endl;
	else if (dbaAlgoritmus == (uint16_t)2)
		std::cout << "Byl zvolen MaxMin dba algoritmus." << std::endl;
	else if (dbaAlgoritmus == (uint16_t)3)
		std::cout << "Byl zvolen GIANT dba algoritmus." << std::endl;

	std::cout << "Sit vytvorena" << std::endl;
	std::cout << "Simulace spustena" << std::endl << std::endl;

	Simulator simulator = Simulator(olt, Onus, timeEnd);
    return 0;
}