<?php

namespace AsyncAws\S3\ValueObject;

/**
 * A container for specifying the notification configuration of the bucket. If this element is empty, notifications are
 * turned off for the bucket.
 */
final class NotificationConfiguration
{
    /**
     * The topic to which notifications are sent and the events for which notifications are generated.
     *
     * @var TopicConfiguration[]|null
     */
    private $topicConfigurations;

    /**
     * The Amazon Simple Queue Service queues to publish messages to and the events for which to publish messages.
     *
     * @var QueueConfiguration[]|null
     */
    private $queueConfigurations;

    /**
     * Describes the Lambda functions to invoke and the events for which to invoke them.
     *
     * @var LambdaFunctionConfiguration[]|null
     */
    private $lambdaFunctionConfigurations;

    /**
     * Enables delivery of events to Amazon EventBridge.
     *
     * @var EventBridgeConfiguration|null
     */
    private $eventBridgeConfiguration;

    /**
     * @param array{
     *   TopicConfigurations?: array<TopicConfiguration|array>|null,
     *   QueueConfigurations?: array<QueueConfiguration|array>|null,
     *   LambdaFunctionConfigurations?: array<LambdaFunctionConfiguration|array>|null,
     *   EventBridgeConfiguration?: EventBridgeConfiguration|array|null,
     * } $input
     */
    public function __construct(array $input)
    {
        $this->topicConfigurations = isset($input['TopicConfigurations']) ? array_map([TopicConfiguration::class, 'create'], $input['TopicConfigurations']) : null;
        $this->queueConfigurations = isset($input['QueueConfigurations']) ? array_map([QueueConfiguration::class, 'create'], $input['QueueConfigurations']) : null;
        $this->lambdaFunctionConfigurations = isset($input['LambdaFunctionConfigurations']) ? array_map([LambdaFunctionConfiguration::class, 'create'], $input['LambdaFunctionConfigurations']) : null;
        $this->eventBridgeConfiguration = isset($input['EventBridgeConfiguration']) ? EventBridgeConfiguration::create($input['EventBridgeConfiguration']) : null;
    }

    /**
     * @param array{
     *   TopicConfigurations?: array<TopicConfiguration|array>|null,
     *   QueueConfigurations?: array<QueueConfiguration|array>|null,
     *   LambdaFunctionConfigurations?: array<LambdaFunctionConfiguration|array>|null,
     *   EventBridgeConfiguration?: EventBridgeConfiguration|array|null,
     * }|NotificationConfiguration $input
     */
    public static function create($input): self
    {
        return $input instanceof self ? $input : new self($input);
    }

    public function getEventBridgeConfiguration(): ?EventBridgeConfiguration
    {
        return $this->eventBridgeConfiguration;
    }

    /**
     * @return LambdaFunctionConfiguration[]
     */
    public function getLambdaFunctionConfigurations(): array
    {
        return $this->lambdaFunctionConfigurations ?? [];
    }

    /**
     * @return QueueConfiguration[]
     */
    public function getQueueConfigurations(): array
    {
        return $this->queueConfigurations ?? [];
    }

    /**
     * @return TopicConfiguration[]
     */
    public function getTopicConfigurations(): array
    {
        return $this->topicConfigurations ?? [];
    }

    /**
     * @internal
     */
    public function requestBody(\DOMElement $node, \DOMDocument $document): void
    {
        if (null !== $v = $this->topicConfigurations) {
            foreach ($v as $item) {
                $node->appendChild($child = $document->createElement('TopicConfiguration'));

                $item->requestBody($child, $document);
            }
        }
        if (null !== $v = $this->queueConfigurations) {
            foreach ($v as $item) {
                $node->appendChild($child = $document->createElement('QueueConfiguration'));

                $item->requestBody($child, $document);
            }
        }
        if (null !== $v = $this->lambdaFunctionConfigurations) {
            foreach ($v as $item) {
                $node->appendChild($child = $document->createElement('CloudFunctionConfiguration'));

                $item->requestBody($child, $document);
            }
        }
        if (null !== $v = $this->eventBridgeConfiguration) {
            $node->appendChild($child = $document->createElement('EventBridgeConfiguration'));

            $v->requestBody($child, $document);
        }
    }
}
