<?php

namespace App\Enums;

use Illuminate\Support\Carbon;

enum PriceClassification: string
{
    case Current = 'current';
    case Recent = 'recent';
    case Stale = 'stale';
    case Outdated = 'outdated';

    public static function fromUpdatedAt(?Carbon $updatedAt): self
    {
        if ($updatedAt === null) {
            return self::Outdated;
        }

        $hours = $updatedAt->diffInHours(now());

        return match (true) {
            $hours < 24 => self::Current,
            $hours < 48 => self::Recent,
            $hours < 120 => self::Stale,
            default => self::Outdated,
        };
    }

    public function weight(): int
    {
        return match ($this) {
            self::Current => 0,
            self::Recent => 1,
            self::Stale => 2,
            self::Outdated => 3,
        };
    }

    public function label(): string
    {
        return match ($this) {
            self::Current => 'Current',
            self::Recent => 'Recent',
            self::Stale => 'Stale',
            self::Outdated => 'Outdated',
        };
    }
}
