<?php

declare(strict_types=1);

namespace kodorvan\neurobot\models\enumerations;

// The library for languages support
use mirzaev\languages\language;

// Library for currencies support
use mirzaev\currencies\currency;

// Built-in libraries
use InvalidArgumentException as exception_argument,
	DomainException as exception_domain;

/**
 * Tariff
 *
 * @package kodorvan\neurobot\models\enumeration
 *
 * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
 * @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
 */
enum tariff: int
{
	case free = 0;
	case standart = 1;
	case premium = 2;
	case sigma = 3;
	case professional = 4;
	case endless = 5;

	/**
	 * Label
	 *
	 * @param language $language The language
	 *
	 * @return string The tariff label
	 */
	public function label(language $language = language::en): string
	{
		// Exit (success)
		return match ($this) {
			static::free => match ($language) {
				language::en => 'Free',
				language::ru => 'Бесплатный'
			},
			static::standart => match ($language) {
				language::en => 'Standart',
				language::ru => 'Стандарт'
			},
			static::premium => match ($language) {
				language::en => 'Premium',
				language::ru => 'Премиум'
			},
			static::endless => match ($language) {
				language::en => 'Endless',
				language::ru => 'Бесконечный'
			}
		};
	}

	/**
	 * Tokens
	 *
	 * @see https://openai.com/api/pricing/
	 *
	 * @throws exception_domain for `static::endless`
	 *
	 * @return string The tariff tokens amount
	 */
	public function tokens(): int
	{
		// Exit (success)
		return match ($this) {
			static::free => 20000,
			static::standart => 100000,
			static::premium => 300000,
			static::endless => throw new exception_domain('bruh')
		};
	}

	/**
	 * Cost
	 *
	 * @throws exception_domain for `static::endless`
	 *
	 * @return int The tariff cost
	 */
	public function cost(currency $currency = currency::usd): int
	{
		// Exit (success)
		return match ($this) {
			static::free => 0,
			static::standart => match ($currency) {
				currency::rub => 100,
				currency::usd => 1
			},
			static::premium => match ($currency) {
				currency::rub => 250,
				currency::usd => 2.5
			},
			static::endless => throw new exception_domain('bruh')
		};
	}

	/**
	 * Priority
	 *
	 * @return string The tariff priority
	 */
	public function priority(): int
	{
		// Exit (success)
		return match ($this) {
			static::free => 0,
			static::standart => 1,
			static::premium => 2,
			static::endless => 999 
		};
	}
}
