<?php

namespace App\Enum;

enum CacheKey: string
{
    case USER_PROFILE = 'user_profile_%d';
    case EVENT_LIST = 'event_list';
    case EVENT_DETAIL = 'event_detail_%d';
    case EVENT_TICKETS = 'event_tickets_%d';
    case SEARCH_RESULTS = 'search_%s';
    case SITEMAP_MAIN = 'sitemap_main';
    case SITEMAP_EVENTS = 'sitemap_events_%d';
    case HOME_PAGE = 'home_page';

    public function resolve(string|int ...$params): string
    {
        return sprintf($this->value, ...$params);
    }

    public function ttl(): int
    {
        return match ($this) {
            self::USER_PROFILE => 1800,
            self::EVENT_LIST => 300,
            self::EVENT_DETAIL => 600,
            self::EVENT_TICKETS => 60,
            self::SEARCH_RESULTS => 120,
            self::SITEMAP_MAIN => 3600,
            self::SITEMAP_EVENTS => 3600,
            self::HOME_PAGE => 300,
        };
    }
}
