<?php

namespace Planaday\Config\OptionGroups\General\Api;

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

class ApiOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Api';

	private const DESCRIPTION = 'Hier stelt u de koppeling met jouw Planaday omgeving in.';

	/** @var StringOption<null> */
	private $domain;

	/** @var StringOption<null> */
	private $apiKey;

	/** @var IntOption<int> */
	private $refreshIntervalCourses;

	/** @var IntOption<int> */
	private $refreshIntervalDayParts;

	/** @var IntOption<int> */
	private $refreshIntervalLocations;

	/** @var IntOption<int> */
	private $refreshSizeCourses;

	public function __construct( string $index, array $data ) {
		$this->refreshIntervalCourses = new IntOption(
			ApiOptionsEnum::REFRESH_INTERVAL_COURSES,
			'Verversingsinterval cursussen',
			"Vul hier in om de hoeveel uur de cursusen ververst moet worden, hoe lager de uren, hoe vaker er data opgehaald zal worden. <br>" .
			"Wij raden 12 uur aan.",
			$data[ ApiOptionsEnum::REFRESH_INTERVAL_COURSES ] ?? null,
			12
		);

		$this->refreshIntervalDayParts = new IntOption(
			ApiOptionsEnum::REFRESH_INTERVAL_DAY_PARTS,
			'Verversingsinterval dagdelen',
			"Vul hier in om de hoeveel uur de bekende dagdelen geupdate moet worden, hoe lager de uren, hoe vaker er data opgehaald zal worden. <br>" .
			"Wij raden 24 uur aan.",
			$data[ ApiOptionsEnum::REFRESH_INTERVAL_DAY_PARTS ] ?? null,
			24
		);

		$this->refreshIntervalLocations = new IntOption(
			ApiOptionsEnum::REFRESH_INTERVAL_LOCATIONS,
			'Verversingsinterval locaties',
			"Vul hier in om de hoeveel uur de bekende locaties geupdate moet worden, hoe lager de uren, hoe vaker er data opgehaald zal worden. <br>" .
			"Wij raden 24 uur aan.",
			$data[ ApiOptionsEnum::REFRESH_INTERVAL_LOCATIONS ] ?? null,
			24
		);

		$this->refreshSizeCourses = new IntOption(
			ApiOptionsEnum::REFRESH_SIZE_COURSES,
			'Inlaad Hoeveelheid',
			"Cursussen binnen zoveel maanden zullen worden ingeladen.<br>" .
			"Wij raden 12 maanden aan.",
			$data[ ApiOptionsEnum::REFRESH_SIZE_COURSES ] ?? null,
			12
		);

		$this->domain = new StringOption(
			ApiOptionsEnum::DOMAIN,
			'Adres van portal',
			'Deze vindt u in jouw Planaday bij beheer->koppelingen->publieke api',
			$data[ ApiOptionsEnum::DOMAIN ] ?? null,
			null
		);

		$this->apiKey = new StringOption(
			ApiOptionsEnum::API_KEY,
			'API key',
			'Deze genereert u zelf in jouw planaday bij beheer->koppelingen->publieke api',
			$data[ ApiOptionsEnum::API_KEY ] ?? null,
			null
		);

		$layout = [
			$this->domain,
			$this->apiKey,
			$this->refreshIntervalCourses,
			$this->refreshIntervalDayParts,
			$this->refreshIntervalLocations,
			$this->refreshSizeCourses
		];

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

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

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

	/**
	 * @return IntOption<int>
	 */
	public function refreshIntervalCourses(): IntOption {
		return $this->refreshIntervalCourses;
	}

	/**
	 * @return IntOption<int>
	 */
	public function refreshIntervalDayParts(): IntOption {
		return $this->refreshIntervalDayParts;
	}

	/**
	 * @return IntOption<int>
	 */
	public function refreshIntervalLocations(): IntOption {
		return $this->refreshIntervalLocations;
	}

	/**
	 * @return IntOption<int>
	 */
	public function refreshSizeCourses(): IntOption {
		return $this->refreshSizeCourses;
	}

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