/* 
 * This file is automaticaly generated, Please dont edit this file! 
 */
#include <headers.h> 





void headerManager_parse( headerManager * this, char * headerContent ) {

		array * headerRows	= char_split( headerContent, "\n");

		int headerCount		= array_length( headerRows );

		for (int i = 1; i < headerCount; ++i)
		{

			char * headerRow		= array_get( headerRows,  i );

			array * headerRowParts	= char_split( headerRow, ":");

			int headerRowPartsCount	= array_length( headerRowParts );


			if( headerRowPartsCount == 2 ) {

				char * headerName	= array_get( headerRowParts,  0 );

				char * headerValue	= array_get( headerRowParts,  1 );

				

				

				headerManager_add( this,  headerName, char_removeWhitespace( headerValue ) );

			}

		}

		printf("\n\n");

	}

void headerManager_display( headerManager * this ) {

		struct array * headerRows	= this->headers;

		int headerCount		= array_length( headerRows );

		for (int i = 0; i < headerCount; ++i)
		{
			struct header * headerInstance = array_get( headerRows,  i );

			printf("%-20s	%-30s \n", headerInstance->name, headerInstance->value);
			
		}

	}

void headerManager_add( headerManager * this, char * name,  char * value ) {

		header * headerInstance = header_newPointer();

		headerInstance->name 	= name;

		headerInstance->value	= value;

		array_add( this->headers,  headerInstance );

	}

void headerManager_set( headerManager * this, char * name,  char * value ) {

		struct header * headerInstance = headerManager_get( this,  name );

		if( headerInstance == NULL ) {

			headerManager_add( this,  name, value );

		} else {

			int headerIndex	= headerManager_getHeaderIndex( this,  name );

			array * headers = this->headers;


			header * headerInstance = array_get( headers,  headerIndex );

			headerInstance->value	= value;


		}

	}

int headerManager_getHeaderIndex( headerManager * this, char * name ) {

		array * headers = this->headers;

		int count = array_length( headers );

		for (int i = 0; i < count; ++i)
		{
			
			header * headerInstance = array_get( headers,  i );

			if( char_operator_compare( headerInstance->name ,  name) ) {

				return i;

			}

		}

		return -1;

	}

char * headerManager_getValue( headerManager * this, char * name ) {

		array * headers = this->headers;

		int count = array_length( headers );

		for (int i = 0; i < count; ++i)
		{
			
			header * headerInstance = array_get( headers,  i );

			if( char_operator_compare( headerInstance->name ,  name) ) {

				return headerInstance->value;

			}

		}

		return NULL;

	}

header * headerManager_get( headerManager * this, char * name ) {

		array * headers = this->headers;

		int count = array_length( headers );

		for (int i = 0; i < count; ++i)
		{
			
			header * headerInstance = array_get( headers,  i );

			if( char_operator_compare( headerInstance->name ,  name) ) {

				return headerInstance;

			}

		}

		return NULL;

	}

headerManager headerManager_new() {

	headerManager instance;

	instance.headers = array_newPointer();

	return instance;

}

headerManager * headerManager_newPointer() {

	struct headerManager * pointer = malloc( sizeof ( struct headerManager ) );

	pointer->headers = array_newPointer();

	return pointer;

}

