//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class chatbox_hook_Member extends _HOOK_CLASS_
{
	/* !Registration/Validation */
	
	/**
	 * Call after completed registration to send email for validation if required or flag for admin validation
	 *
	 * @param	bool		$noEmailValidationRequired	If the user's email is implicitly trusted (for example, provided by a third party), set this to TRUE to bypass email validation
	 * @param	bool		$doNotDelete				If TRUE, the account will not be deleted in the normal cleanup of unvalidated accounts. Used for accounts created in Commerce checkout.
	 * @param	array|NULL	$postBeforeRegister			The row from core_post_before_registering if applicable
	 * @return	void
	 */
	public function postRegistration( $noEmailValidationRequired = FALSE, $doNotDelete = FALSE, $postBeforeRegister = NULL, $refUrl = NULL )
	{
		try
		{
			if( !$this->real_name OR $this->name === $this->language()->get('guest') )
			{
				return parent::postRegistration( $noEmailValidationRequired, $doNotDelete );
			}
			if( \IPS\Settings::i()->reg_auth_type == 'none' OR \IPS\Request::i()->do == 'complete' )
			{
				\IPS\chatbox\Rooms\Room::newRegNotify( $this );
			}
			return parent::postRegistration( $noEmailValidationRequired, $doNotDelete, $postBeforeRegister, $refUrl );
		}
		catch ( \Error | \RuntimeException $e )
		{
			if ( method_exists( get_parent_class(), __FUNCTION__ ) )
			{
				return \call_user_func_array( 'parent::' . __FUNCTION__, \func_get_args() );
			}
			else
			{
				throw $e;
			}
		}
	}
	
	/**
	 * User has done something which could earn Points / Badges
	 *
	 * @param	string	$app				Application key for the action being performed
	 * @param	string	$extension			Extension key for the action being performed
	 * @param	?mixed	$extra				Any additional information to be passed along to the extension (e.g. if a post is being made: the post object)
	 * @param	?\IPS\DateTime	$date		Optional DateTime object to be used as the date the achievement was earned
	 * @return	void
	 */
	public function achievementAction( string $app, string $extension, $extra = NULL, $date = NULL )
	{
		try
		{
			if ( $app == 'chatbox' )
			{
				return;
			}
			
			parent::achievementAction( $app, $extension, $extra, $date );
		}
		catch ( \Error | \RuntimeException $e )
		{
			if ( method_exists( get_parent_class(), __FUNCTION__ ) )
			{
				return \call_user_func_array( 'parent::' . __FUNCTION__, \func_get_args() );
			}
			else
			{
				throw $e;
			}
		}
	}
}
