<?php

namespace Planaday\Config\OptionGroups\General\Price;

use Planaday\Config\OptionGroups\General\GeneralOptions;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Config\OptionTypes\BoolOption;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

class PriceOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Prijzen';

	private const DESCRIPTION = 'Instellingen voor prijzen';

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

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

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

	public function __construct( string $index, array $data ) {

		$this->includingTax = new BoolOption(
			PriceOptionsEnum::INCLUDING_TAX,
			"Inclusief BTW",
			"Moet de prijs inclusief BTW worden getoond?",
			$data[ PriceOptionsEnum::INCLUDING_TAX ] ?? null,
			true
		);

		$this->withTaxLabel = new BoolOption(
			PriceOptionsEnum::WITH_TAX_LABEL,
			"BTW label",
			"Moet er een label worden getoond voor de BTW?",
			$data[ PriceOptionsEnum::WITH_TAX_LABEL ] ?? null,
			true
		);

		$this->usePointsForDecimals = new BoolOption(
			PriceOptionsEnum::USE_POINT_FOR_DECIMALS,
			"Punt inplaats van komma",
			"Moet er een punt gebruikt worden bij prijzen inplaats van een komma?",
			$data[ PriceOptionsEnum::USE_POINT_FOR_DECIMALS ] ?? null,
			false
		);

		$layout = [
			$this->includingTax,
			$this->withTaxLabel,
			$this->usePointsForDecimals
		];

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

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

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

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

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