<?php

namespace Planaday\Config\Internal;

use Planaday\Config\BasicEnumMappedSetting;
use Planaday\Config\EnumMappedSettings;
use Planaday\Config\GlobalSetting;
use Planaday\Config\SettingsLoader;
use Planaday\Platform\PlatformAbstraction\LocalizationController;
use Planaday\Utility\DependencyInjection\Attributes\Scoped;

#[Scoped]
class InternalSettings implements EnumMappedSettings, GlobalSetting {
	use BasicEnumMappedSetting;
	protected int $lastRefreshLocation = 0;
	protected int $lastRefreshDayPart = 0;
	protected int $lastRefreshCourse = 0;
	protected string $globalCss = '/* Voeg hier jouw eigen CSS toe */';
	protected ?string $lastSelectedApi = null;
	protected ?int $startKnownTimeSlot = null;
	protected ?int $endKnownTimeSlot = null;


	public function __construct(
		protected SettingsLoader $settingsDatabase,
		protected LocalizationController $translator
	) {
		$this->settingsDatabase->reloadData( $this, InternalOptionsEnum::class);
	}

	public function getTitle(): string {
		return $this->translator->translate('Interne Instellingen');
	}

	public function getEnumMapping(): array {
		return [
			"values" => [
				InternalOptionsEnum::LAST_COURSE_REFRESH->value => &$this->lastRefreshCourse,
				InternalOptionsEnum::LAST_DAY_PART_REFRESH->value => &$this->lastRefreshDayPart,
				InternalOptionsEnum::LAST_LOCATION_REFRESH->value => &$this->lastRefreshLocation,
				InternalOptionsEnum::LAST_SELECTED_API->value => &$this->lastSelectedApi,
				InternalOptionsEnum::GLOBAL_CSS->value => &$this->globalCss,
				InternalOptionsEnum::START_KNOWN_TIME_SLOT->value => &$this->startKnownTimeSlot,
				InternalOptionsEnum::END_KNOWN_TIME_SLOT->value => &$this->endKnownTimeSlot,
			],
			"subGroups" => [],
			"subGroupAliases" => []
		];
	}

	public static function getIndex(): string {
		return '-internal-options';
	}

	public function save(): void {
		$this->settingsDatabase->saveData($this);
	}

	public function getLastRefreshLocation(): int {
		return $this->lastRefreshLocation;
	}

	public function setLastRefreshLocation( int $lastRefreshLocation ): void {
		$this->lastRefreshLocation = $lastRefreshLocation;
		$this->save();
	}

	public function getLastRefreshDayPart(): int {
		return $this->lastRefreshDayPart;
	}

	public function setLastRefreshDayPart( int $lastRefreshDayPart ): void {
		$this->lastRefreshDayPart = $lastRefreshDayPart;
		$this->save();
	}

	public function getLastRefreshCourse(): int {
		return $this->lastRefreshCourse;
	}

	public function setLastRefreshCourse( int $lastRefreshCourse ): void {
		$this->lastRefreshCourse = $lastRefreshCourse;
		$this->save();
	}

	public function getGlobalCss(): string {
		return $this->globalCss;
	}

	public function setGlobalCss( string $globalCss ): void {
		$this->globalCss = $globalCss;
		$this->save();
	}

	public function getLastSelectedApi(): ?string {
		return $this->lastSelectedApi;
	}

	public function setLastSelectedApi( ?string $lastSelectedApi ): void {
		$this->lastSelectedApi = $lastSelectedApi;
		$this->save();
	}

	public function getStartKnownTimeSlot(): ?int {
		return $this->startKnownTimeSlot;
	}

	public function setStartKnownTimeSlot( ?int $startKnownTimeSlot ): void {
		$this->startKnownTimeSlot = $startKnownTimeSlot;
		$this->save();
	}

	public function getEndKnownTimeSlot(): ?int {
		return $this->endKnownTimeSlot;
	}

	public function setEndKnownTimeSlot( ?int $endKnownTimeSlot ): void {
		$this->endKnownTimeSlot = $endKnownTimeSlot;
		$this->save();
	}
}