<?php

namespace Planaday\Config\OptionGroups\Booking\Form;

use Planaday\Config\OptionGroups\Booking\BookingOptions;
use Planaday\Config\OptionGroups\Booking\Form\Address\AddressOptions;
use Planaday\Config\OptionGroups\Booking\Form\Company\CompanyOptions;
use Planaday\Config\OptionGroups\Booking\Form\Materials\MaterialsOptions;
use Planaday\Config\OptionGroups\Booking\Form\Student\StudentOptions;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Config\OptionTypes\BoolOption;
use Planaday\Config\OptionTypes\StringOption;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

class BookingFormOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Boekingsformulier Instellingen';
	private const DESCRIPTION = 'De instellingen voor het boekingsformulier.';

	/** @var StudentOptions  */
	private $student;

	/** @var CompanyOptions  */
	private $company;

	/** @var AddressOptions  */
	private $address;

	/** @var MaterialsOptions */
	private $materials;

	/** @var StringOption<string> */
	private $bookingFormTitle;

	/** @var BoolOption<bool> */
	private $askApiAttributes;
	/**
	 * @var BoolOption
	 */
	private $startedCourseBookable;

	public function __construct( string $index, array $data ) {
		$this->student = new StudentOptions( BookingFormOptionsEnum::STUDENT, $data[ BookingFormOptionsEnum::STUDENT ] ?? []);
		$this->company = new CompanyOptions( BookingFormOptionsEnum::COMPANY, $data[ BookingFormOptionsEnum::COMPANY ] ?? []);
		$this->address = new AddressOptions( BookingFormOptionsEnum::ADDRESS, $data[ BookingFormOptionsEnum::ADDRESS ] ?? []);
		$this->materials = new MaterialsOptions( BookingFormOptionsEnum::MATERIALS, $data[ BookingFormOptionsEnum::MATERIALS ] ?? []);

		$this->bookingFormTitle = new StringOption(
			BookingFormOptionsEnum::BOOKING_FORM_TITLE,
			'Titel boeking formulier',
			'De titel van het boeking formulier.',
			$data[ BookingFormOptionsEnum::BOOKING_FORM_TITLE ] ?? null,
			'Cursus boeken en meteen zelf boeken'
		);


		$this->askApiAttributes = new BoolOption(
			BookingFormOptionsEnum::ASK_API_ATTRIBUTES,
			'API attributen vragen?',
			"Moeten de api attributen gevraagd worden?",
			$data[ BookingFormOptionsEnum::ASK_API_ATTRIBUTES ] ?? null,
			false
		);

		$this->startedCourseBookable = new BoolOption(
			BookingFormOptionsEnum::STARTED_COURSE_BOOKABLE,
			'Gestarte cursus boekbaar',
			"Kan nog inschrijven op een cursus die al gestart is?",
			$data[ BookingFormOptionsEnum::STARTED_COURSE_BOOKABLE ] ?? null,
			false
		);

		$layout = [
			$this->bookingFormTitle,
			$this->startedCourseBookable,
			$this->address,
			$this->student,
			$this->company,
			$this->materials,
			$this->askApiAttributes
		];

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

	/**
	 * @return StringOption<string>
	 */
	public function bookingFormTitle(): StringOption {
		return $this->bookingFormTitle;
	}

	/**
	 * @return AddressOptions
	 */
	public function address(): AddressOptions {
		return $this->address;
	}

	/**
	 * @return StudentOptions
	 */
	public function student(): StudentOptions {
		return $this->student;
	}

	/**
	 * @return CompanyOptions
	 */
	public function company(): CompanyOptions {
		return $this->company;
	}

	/**
	 * @return MaterialsOptions
	 */
	public function materials(): MaterialsOptions {
		return $this->materials;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askApiAttributes(): BoolOption {
		return $this->askApiAttributes;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function startedCourseBookable(): BoolOption {
		return $this->startedCourseBookable;
	}

	public static function componentRegistryConstruct( ComponentRegistry $registry ) {
		return $registry->getComponent(BookingOptions::class)->formOptions();
	}
}