/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ClapTrap.cpp                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: bchanot <bchanot@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/12/18 13:30:29 by bchanot           #+#    #+#             */
/*   Updated: 2025/12/18 14:49:15 by bchanot          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ClapTrap.hpp"
#include <limits>

/*
** ------------------------------- CONSTRUCTOR --------------------------------
*/

ClapTrap::ClapTrap() : _name("Default"), _hitPoints(10), _energyPoints(10), _attackDamage(0)
{
	std::cout << "ClapTrap " << this->_name << " has been created" << std::endl;
}

ClapTrap::ClapTrap( std::string const & name) : _name(name), _hitPoints(10), _energyPoints(10), _attackDamage(0)
{
	std::cout << "ClapTrap " << this->_name << " has been created" << std::endl;
}

ClapTrap::ClapTrap( ClapTrap const & src ) : _name(src._name), _hitPoints(src._hitPoints), _energyPoints(src._energyPoints), _attackDamage(src._attackDamage)
{
	std::cout << "Copy of ClapTrap " << this->_name << " has been created" << std::endl;
}


/*
** -------------------------------- DESTRUCTOR --------------------------------
*/

ClapTrap::~ClapTrap()
{
	std::cout << "ClapTrap " << this->_name << " has been destroyed !" << std::endl;
}


/*
** --------------------------------- OVERLOAD ---------------------------------
*/

ClapTrap &				ClapTrap::operator=( ClapTrap const & rhs )
{
	(void)rhs;
	//if ( this != &rhs )
	//{
		//this->_value = rhs.getValue();
	//}
	return *this;
}

std::ostream &			operator<<( std::ostream & o, ClapTrap const & i )
{
	(void)i;
	//o << "Value = " << i.getValue();
	return o;
}


/*
** --------------------------------- METHODS ----------------------------------
*/

void					ClapTrap::attack(const std::string& target) {
	if (this->_hitPoints > 0) {
		if (this->_energyPoints > 0) {
			this->_energyPoints--;
			std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage !" << std::endl;
		} else
			std::cout << "ClapTrap " << this->_name << " Doesn't have enough energy to attack !" << std::endl;
	} else 
		std::cout << "ClapTrap " << this->_name << " is dead.. How could he attack ?" << std::endl;
}

void					ClapTrap::takeDamage(unsigned int amount) {
	if (this->_hitPoints > 0) {
		if (this->_hitPoints < amount) {
			this->_hitPoints = 0;
			std::cout << this->_name << " is taking " << amount << " damage.. Causing his death ! he is now 0 HP..." << std::endl;
		} else {
			this->_hitPoints -= amount;
			std::cout << this->_name << " is taking " << amount << " damage. He got now " << this->_hitPoints << " HP" << std::endl;
		}
	} else
		std::cout << this->_name << " is 0 HP, already dead. Cannot attack a dead ClapTrap. Do we .. ?" << std::endl;
}

void					ClapTrap::beRepaired(unsigned int amount) {
	if (this->_hitPoints > 0) {
		if (this->_energyPoints > 0) {
			if (this->_hitPoints + amount > std::numeric_limits<short unsigned int>::max()) 
				this->_hitPoints = std::numeric_limits<short unsigned int>::max();
			else
				this->_hitPoints += amount;
			this->_energyPoints--;
			std::cout << this->_name << " is getting repaired about " << amount << " HP. Getting now " << this->_hitPoints << " HP." << std::endl;
		} else
			std::cout << "ClapTrap " << this->_name << " Doesn't have enought energy..." << std::endl;
	} else
		std::cout << this->_name << " is 0 HP, it mean DEAD. so, he cannot do anything more..." << std::endl;
}

/*
** --------------------------------- ACCESSOR ---------------------------------
*/


/* ************************************************************************** */