<?php
namespace Medienreaktor\Products\Domain\Model;

/***
 *
 * This file is part of the "Products" Extension for TYPO3 CMS.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 *  (c) 2017 Daniel Kestler &lt;daniel.kestler@medienreaktor&gt;, medienreaktor GmbH
 *
 ***/

/**
 * PropertyGroup
 */
class PropertyGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
    /**
     * name
     *
     * @var string
     */
    protected $name = '';

    /**
     * properties
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Medienreaktor\Products\Domain\Model\Property>
     */
    #[\TYPO3\CMS\Extbase\Annotation\ORM\Cascade(['value' => 'remove'])]
    protected $properties = null;

    /**
     * __construct
     */
    public function __construct()
    {
        //Do not remove the next line: It would break the functionality
        $this->initStorageObjects();
    }

    /**
     * Initializes all ObjectStorage properties
     * Do not modify this method!
     * It will be rewritten on each save in the extension builder
     * You may modify the constructor of this class instead
     *
     * @return void
     */
    protected function initStorageObjects()
    {
        $this->properties = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
    }

    /**
     * Returns the name
     *
     * @return string $name
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the name
     *
     * @param string $name
     * @return void
     */
    public function setName($name): void
    {
        $this->name = $name;
    }

    /**
     * Adds a Property
     *
     * @param \Medienreaktor\Products\Domain\Model\Property $property
     * @return void
     */
    public function addProperty(\Medienreaktor\Products\Domain\Model\Property $property): void
    {
        $this->properties->attach($property);
    }

    /**
     * Removes a Property
     *
     * @param \Medienreaktor\Products\Domain\Model\Property $propertyToRemove The Property to be removed
     * @return void
     */
    public function removeProperty(\Medienreaktor\Products\Domain\Model\Property $propertyToRemove): void
    {
        $this->properties->detach($propertyToRemove);
    }

    /**
     * Returns the properties
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Medienreaktor\Products\Domain\Model\Property> $properties
     */
    public function getProperties()
    {
        return $this->properties;
    }

    /**
     * Sets the properties
     *
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Medienreaktor\Products\Domain\Model\Property> $properties
     * @return void
     */
    public function setProperties(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $properties): void
    {
        $this->properties = $properties;
    }
}
