<?php

namespace KupShop\AutomationConfiguratorBundle\Configurator\Interfaces\Config;

class TriggerConfig
{
    /**
     * @var string
     */
    protected $name;

    /**
     * @var TriggerField[]
     */
    protected $fields;

    /**
     * TriggerConfig constructor.
     *
     * @param $fields TriggerField[]
     */
    public function __construct(string $name, $fields = null)
    {
        $this->name = $name;
        $this->fields = $fields ?? [];
    }

    /**
     * @param $field TriggerField
     */
    public function addField($field)
    {
        $this->fields[$field->getName()] = $field;
    }

    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return TriggerField[]
     */
    public function getFields(): array
    {
        return $this->fields;
    }

    public function getField($name): ?TriggerField
    {
        return $this->fields[$name] ?? null;
    }
}
