#include "./PhoneBook.hpp"
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>

PhoneBook::PhoneBook()
{
	Contact contact;
	this->len = 0;
	this->number = 0;
	for (size_t i = 0; i < 8; i++)
		this->contacts[i] = contact;
}

void	PhoneBook::add_contact(Contact &new_contact)
{
	this->contacts[this->number % 8] = new_contact;
	if (this->len < 8)
		this->len++;
	this->number++;
}


void PhoneBook::display_contacts()
{
	size_t				i;

	std::cout 
	<< "     index|"
	<< "first name|"
	<< "last name |"
	<< "nickname  |"
	<< "phone num.|"
	<< "darkest s."
	<< std::endl;

	for (i = 0; i < this->len; i++)
	{
		std::cout
		<< std::setw(10) << i
		<< "|"
		<< this->contacts[i].to_string_partial()
		<< std::endl;
	}
}

Contact* PhoneBook::search(int index)
{
	std::cout << this->len << " " << index << std::endl;
	if ((size_t) index >= this->len || index < 0)
		return (NULL);
	return (&this->contacts[index]);
}
