<?php

declare(strict_types=1);

namespace App\Application\LiveComponents\ValueObjects;

/**
 * TimeRange - Time period for metrics
 */
enum TimeRange: string
{
    case LAST_24_HOURS = '24h';
    case LAST_7_DAYS = '7d';
    case LAST_30_DAYS = '30d';
    case LAST_90_DAYS = '90d';
    case LAST_YEAR = '1y';

    public function getLabel(): string
    {
        return match ($this) {
            self::LAST_24_HOURS => 'Letzte 24 Stunden',
            self::LAST_7_DAYS => 'Letzte 7 Tage',
            self::LAST_30_DAYS => 'Letzte 30 Tage',
            self::LAST_90_DAYS => 'Letzte 90 Tage',
            self::LAST_YEAR => 'Letztes Jahr'
        };
    }

    public function getMultiplier(): float
    {
        return match ($this) {
            self::LAST_24_HOURS => 1.0,
            self::LAST_7_DAYS => 7.0,
            self::LAST_30_DAYS => 30.0,
            self::LAST_90_DAYS => 90.0,
            self::LAST_YEAR => 365.0
        };
    }

    public static function fromString(string $value): self
    {
        return match ($value) {
            '24h' => self::LAST_24_HOURS,
            '7d' => self::LAST_7_DAYS,
            '30d' => self::LAST_30_DAYS,
            '90d' => self::LAST_90_DAYS,
            '1y' => self::LAST_YEAR,
            default => self::LAST_30_DAYS
        };
    }
}
