<?php

namespace Zenoph\Notify\Collections;

use Zenoph\Notify\Store\MessageDestination;

class MessageDestinationsList implements \Iterator {
    private ObjectStorage $_store;

    public function __construct() {
        $this->_store = new ObjectStorage();
    }

    public function add($item): void {
        if (is_null($item) || !$item instanceof MessageDestination)
            throw new \Exception('Invalid reference for adding message destinations collection item.');

        // Add to list
        $this->_store->attach($item);
    }

    public function &getItems(): array {
        return $this->_store->getItems();
    }

    public function getCount(): int {
        return $this->_store->getCount();
    }

    // Implementing Iterator methods with correct return types
    public function current(): mixed {
        return $this->_store->current();
    }

    public function next(): void {
        $this->_store->next();
    }

    public function key(): mixed {
        return $this->_store->key();
    }

    public function rewind(): void {
        $this->_store->rewind();
    }

    public function valid(): bool {
        return $this->_store->valid();
    }
}
