<?php
namespace SabaiApps\Directories\Component\Notification\Event;

use SabaiApps\Directories\Component\Entity\Type\IEntity;

class EntityEventMessageIterator implements \Iterator {

	protected $_keys, $_currentKey, $_entities, $_settings;

	public function __construct( array $entities, array $settings ) {
		$this->_entities = $entities;
		$this->_settings = $settings;
	}

	#[\ReturnTypeWillChange]
	public function next() {}

	#[\ReturnTypeWillChange]
	public function valid() {
		while ( ( null !== $key = array_shift( $this->_keys ) )
			&& $this->_isEntityValid( $this->_entities[ $key ] )
		) {
			$this->_currentKey = $key;
			return true;
		}
		return false;
	}

	#[\ReturnTypeWillChange]
	public function current() {
		$entity = $this->_entities[ $this->_currentKey ];
		return $this->_getEntityMessage( $entity ) + array( 'entity' => $entity );
	}

	#[\ReturnTypeWillChange]
	public function key() {
		return $this->_currentKey;
	}

	#[\ReturnTypeWillChange]
	public function rewind() {
		$this->_keys = array_keys( $this->_entities );
	}

	protected function _isEntityValid( IEntity $entity ) {
		return true;
	}

	protected function _getEntityMessage( IEntity $entity ) {
		return array();
	}
}
