<?php

namespace Planaday\Config\OptionGroups\Booking\Form\Company\Invoice;

use Planaday\Config\OptionGroups\Booking\BookingOptions;
use Planaday\Config\OptionGroups\OptionCluster;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Config\OptionTypes\BoolOption;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

class InvoiceOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Financieel';

	private const DESCRIPTION = 'De financiële opties voor de boeking.';

	/** @var BoolOption<bool> */
	private $askForAddress;

	/** @var BoolOption<bool> */
	private $askForEmail;

	/** @var BoolOption<bool> */
	private $emailRequired;

	public function __construct( string $index, array $data ) {
		$this->askForAddress = new BoolOption(
			InvoiceOptionsEnum::ASK_FOR_ADDRESS,
			'Factuuradres vragen?',
			"Moet er een factuuradres gevraagd worden?",
			$data[ InvoiceOptionsEnum::ASK_FOR_ADDRESS ] ?? null,
			true
		);

		$this->askForEmail = new BoolOption(
			InvoiceOptionsEnum::ASK_FOR_EMAIL,
			'Factuur email vragen?',
			"Moet er een factuur email gevraagd worden?",
			$data[ InvoiceOptionsEnum::ASK_FOR_EMAIL ] ?? null,
		true
		);

		$this->emailRequired = new BoolOption(
			InvoiceOptionsEnum::EMAIL_REQUIRED,
			'Factuur email verplicht?',
			"Moet er een factuur email verplicht zijn?",
			$data[ InvoiceOptionsEnum::EMAIL_REQUIRED ] ?? null,
			false
		);

		$layout = [
			$this->askForAddress,
			new OptionCluster(
				'Factuur email',
				'Een emailadres voor facturatie kan gevraagt worden aan bedrijven.',
				[
					'Vragen' => $this->askForEmail,
					'Verplicht' => $this->emailRequired
				]
			)
		];

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

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

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

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

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