<?php

namespace Planaday\Config\OptionTypes;

/**
 * @extends IntOption<int>
 */
class RadioOption extends IntOption {

	/** @var string[] */
	private $mapping;

	function getType(): string {
		return 'radio';
	}

	/**
	 * @param string $index
	 * @param string $title
	 * @param string $description
	 * @param null|int $value
	 * @param int $defaultValue
	 * @param array<int,string> $mapping
	 */
	public function __construct( string $index, string $title, string $description, ?int $value, int $defaultValue, array $mapping ) {
		$this->mapping = $mapping;
		parent::__construct( $index, $title, $description, $value, $defaultValue );
	}

	public function getMappedValue(): ?string {
		return $this->mapping[ $this->getValue() ] ?? null;
	}

	public function getMappedDefaultValue(): ?string {
		return $this->mapping[ $this->defaultValue ] ?? null;
	}

	/**
	 * @return array<int,string>
	 */
	public function getMapping(): array {
		return $this->mapping;
	}
}