<?php

declare(strict_types=1);

namespace App\Framework\Redis\ValueObjects;

enum RedisDatabaseType: int
{
    case DEFAULT_SESSIONS = 0;
    case CACHE = 1;
    case QUEUE = 2;
    case METRICS = 3;
    case TEMP_DATA = 4;
    case RATE_LIMITING = 5;
    case BACKGROUND_JOBS = 6;
    case ANALYTICS = 7;

    public function getName(): string
    {
        return match ($this) {
            self::DEFAULT_SESSIONS => 'Default/Sessions',
            self::CACHE => 'Cache',
            self::QUEUE => 'Queue',
            self::METRICS => 'Metrics',
            self::TEMP_DATA => 'Temporary Data',
            self::RATE_LIMITING => 'Rate Limiting',
            self::BACKGROUND_JOBS => 'Background Jobs',
            self::ANALYTICS => 'Analytics'
        };
    }

    public function getDescription(): string
    {
        return match ($this) {
            self::DEFAULT_SESSIONS => 'User sessions and general data',
            self::CACHE => 'Application cache (templates, data)',
            self::QUEUE => 'Job queue and task processing',
            self::METRICS => 'Performance and analytics metrics',
            self::TEMP_DATA => 'Temporary application data',
            self::RATE_LIMITING => 'Rate limiting counters',
            self::BACKGROUND_JOBS => 'Background job processing',
            self::ANALYTICS => 'Analytics and tracking data'
        };
    }

    public static function fromId(int $id): ?self
    {
        return self::tryFrom($id);
    }

    public static function getNameForId(int $id): string
    {
        $type = self::fromId($id);

        return $type?->getName() ?? "Database $id";
    }
}
