<?php

namespace Planaday\Config\OptionGroups\Booking\Submission;

use Planaday\Config\OptionGroups\Booking\BookingOptions;
use Planaday\Config\OptionGroups\Booking\Submission\Mail\MailOptions;
use Planaday\Config\OptionGroups\Booking\Submission\Redirecting\RedirectOptions;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

/**
 * @implements ComponentRegistryShortCut<BookingSubmissionOptions>
 */
class BookingSubmissionOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Boeking Indien Instellingen';

	private const DESCRIPTION = 'Instellingen voor de acties na het indienen van een boeking';

	/** @var MailOptions */
	private $mail;

	/** @var RedirectOptions */
	private $redirect;

	public function __construct( string $index, array $data ) {
		$this->mail = new MailOptions( BookingSubmissionOptionsEnum::MAIL, $data[ BookingSubmissionOptionsEnum::MAIL ] ?? []);
		$this->redirect = new RedirectOptions( BookingSubmissionOptionsEnum::REDIRECT, $data[ BookingSubmissionOptionsEnum::REDIRECT ] ?? []);

		$layout = [
			$this->mail,
			$this->redirect
		];

		parent::__construct( $index, self::NAME, self::DESCRIPTION, $layout );
	}

	public function mail(): MailOptions {
		return $this->mail;
	}

	public function redirect(): RedirectOptions {
		return $this->redirect;
	}

	/**
	 * @inheritDoc
	 */
	public static function componentRegistryConstruct( ComponentRegistry $registry ) {
		return $registry->getComponent(BookingOptions::class)->submissionOptions();
	}
}