<?php

declare(strict_types=1);

namespace App\Framework\Queue\Interfaces;

use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Queue\ValueObjects\LockKey;
use App\Framework\Queue\ValueObjects\WorkerId;

/**
 * Interface für Distributed Locking System
 */
interface DistributedLockInterface
{
    /**
     * Lock erwerben
     */
    public function acquire(LockKey $key, WorkerId $workerId, Duration $ttl): bool;

    /**
     * Lock verlängern
     */
    public function extend(LockKey $key, WorkerId $workerId, Duration $ttl): bool;

    /**
     * Lock freigeben
     */
    public function release(LockKey $key, WorkerId $workerId): bool;

    /**
     * Prüfe ob Lock existiert
     */
    public function exists(LockKey $key): bool;

    /**
     * Lock Informationen abrufen
     */
    public function getLockInfo(LockKey $key): ?array;

    /**
     * Lock mit Timeout versuchen
     */
    public function acquireWithTimeout(LockKey $key, WorkerId $workerId, Duration $ttl, Duration $timeout): bool;

    /**
     * Alle Locks eines Workers freigeben
     */
    public function releaseAllWorkerLocks(WorkerId $workerId): int;

    /**
     * Abgelaufene Locks aufräumen
     */
    public function cleanupExpiredLocks(): int;

    /**
     * Lock Statistiken
     */
    public function getLockStatistics(): array;
}
