<?php

declare(strict_types=1);

namespace App\Framework\Console\Analytics\ValueObjects;

/**
 * Enum for analytics time periods
 */
enum Period: string
{
    case HOURLY = 'hourly';
    case DAILY = 'daily';
    case WEEKLY = 'weekly';
    case MONTHLY = 'monthly';
    case YEARLY = 'yearly';

    public function getDescription(): string
    {
        return match ($this) {
            self::HOURLY => 'Hourly analysis',
            self::DAILY => 'Daily analysis',
            self::WEEKLY => 'Weekly analysis',
            self::MONTHLY => 'Monthly analysis',
            self::YEARLY => 'Yearly analysis',
        };
    }

    public function getDateFormat(): string
    {
        return match ($this) {
            self::HOURLY => 'Y-m-d H:00',
            self::DAILY => 'Y-m-d',
            self::WEEKLY => 'Y-\WW',
            self::MONTHLY => 'Y-m',
            self::YEARLY => 'Y',
        };
    }

    public function getIntervalSpec(): string
    {
        return match ($this) {
            self::HOURLY => 'PT1H',
            self::DAILY => 'P1D',
            self::WEEKLY => 'P1W',
            self::MONTHLY => 'P1M',
            self::YEARLY => 'P1Y',
        };
    }
}
