<?php

namespace Planaday\Config\OptionGroups\General;

use Planaday\Config\OptionGroups\General\Api\ApiOptions;
use Planaday\Config\OptionGroups\General\Debug\DebugOptions;
use Planaday\Config\OptionGroups\General\Price\PriceOptions;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Platform\PlatformAbstraction\DataHandler;

class GeneralOptions extends OptionGroup {
	private const NAME = 'General Options';
	public const INDEX = '-general-options';

	/** @var ApiOptions */
	private $apiOptions;

	/** @var DebugOptions */
	private $debugOptions;

	/** @var PriceOptions */
	private $priceOptions;

	public function __construct( DataHandler $dataHandler ) {
		$data     = $dataHandler->getOption( self::INDEX );

		$this->apiOptions = new ApiOptions(
			GeneralOptionsEnum::API_SETTINGS,
				$data[ GeneralOptionsEnum::API_SETTINGS ] ?? []
		);

		$this->debugOptions = new DebugOptions(
			GeneralOptionsEnum::DEBUG,
			$data[GeneralOptionsEnum::DEBUG] ?? []
		);

		$this->priceOptions = new PriceOptions(
			GeneralOptionsEnum::PRICE_OPTIONS,
			$data[GeneralOptionsEnum::PRICE_OPTIONS] ?? []
		);

		$layout = [
			$this->apiOptions,
			$this->priceOptions,
			$this->debugOptions,
		];

		parent::__construct( self::INDEX, self::NAME, '', $layout );
	}

	public function apiOptions(): ApiOptions {
		return $this->apiOptions;
	}

	public function debugOptions(): DebugOptions {
		return $this->debugOptions;
	}

	public function priceOptions(): PriceOptions {
		return $this->priceOptions;
	}
}