<?php

declare(strict_types=1);

/*
 * This file is part of alox bundle for Contao.
 *
 * (c) Benjamin Roth
 *
 * @license commercial
 */

namespace vossmedien\AloxBundle\Model;

use \DateTime;

class StellenModel implements \ArrayAccess, \Countable, \IteratorAggregate
{
    /**
     * @var int
     */
    private int $TotalItems;

    /**
     * @var DateTime
     */
    private DateTime $LastUpdateTime;

    /**
     * @var array
     */
    private array $Items;

    public function __get($name)
    {
        if (isset($this->{$name}) && method_exists($this,'get'.$name))
        {
            return $this->{'get'.$name}();
        }
    }


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

    public function getLastUpdateTime(): DateTime
    {
        return $this->LastUpdateTime;
    }

    public function getTotalItems(): int
    {
        return $this->TotalItems;
    }

    public function setItems(array $items): void
    {
        $this->Items = $items;
    }

    public function setLastUpdateTime(string $updateTime): void
    {
        $this->LastUpdateTime = new DateTime($updateTime);
    }

    public function setTotalItems(int $total): void
    {
        $this->TotalItems = $total;
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->Items);
    }

    public function offsetExists($offset)
    {
        return isset($this->Items[$offset]);
    }

    public function offsetGet($offset)
    {
        return $this->Items[$offset];
    }

    public function offsetSet($offset, $value)
    {
        throw new \RuntimeException('This collection is immutable');
    }

    public function offsetUnset($offset)
    {
        throw new \RuntimeException('This collection is immutable');
    }

    public function count()
    {
        return \count($this->Items);
    }
}