<?php

declare(strict_types=1);

namespace App\Framework\Redis;

use App\Framework\Exception\ErrorCode;
use App\Framework\Exception\FrameworkException;

/**
 * Exception thrown when Redis TTL (Time-To-Live) is invalid
 */
final class InvalidRedisTtlException extends FrameworkException
{
    /**
     * Create exception for negative TTL
     */
    public static function negative(int $seconds): self
    {
        return self::create(
            ErrorCode::VAL_INVALID_INPUT,
            "Redis TTL cannot be negative: {$seconds} seconds"
        )->withData([
            'ttl_seconds' => $seconds,
            'reason' => 'negative_value',
        ]);
    }

    /**
     * Create exception for zero TTL
     */
    public static function zero(): self
    {
        return self::create(
            ErrorCode::VAL_INVALID_INPUT,
            'Redis TTL cannot be zero. Use delete() to remove keys immediately.'
        )->withData([
            'ttl_seconds' => 0,
            'reason' => 'zero_value',
            'suggested_action' => 'Use RedisConnection::delete() instead',
        ]);
    }

    /**
     * Create exception for expired DateTimeInterface
     */
    public static function alreadyExpired(int $seconds): self
    {
        return self::create(
            ErrorCode::VAL_INVALID_INPUT,
            "Redis TTL refers to a time in the past: {$seconds} seconds ago"
        )->withData([
            'ttl_seconds' => $seconds,
            'reason' => 'past_timestamp',
            'suggested_action' => 'Provide a future timestamp',
        ]);
    }
}
