true]), ); } /** * Check if the request is allowed. */ public function isAllowed(): bool { return $this->allowed; } /** * Check if the request is denied. */ public function isDenied(): bool { return ! $this->allowed; } /** * Get the denial message. */ public function getMessage(): ?string { return $this->reason; } /** * Check if this is an unlimited feature. */ public function isUnlimited(): bool { return $this->metadata['unlimited'] ?? false; } /** * Get usage percentage (0-100). */ public function getUsagePercentage(): ?float { if ($this->limit === null || $this->limit === 0) { return null; } return min(100, ($this->used ?? 0) / $this->limit * 100); } /** * Check if usage is near the limit (> 80%). */ public function isNearLimit(): bool { $percentage = $this->getUsagePercentage(); return $percentage !== null && $percentage >= 80; } /** * Check if usage is at the limit. */ public function isAtLimit(): bool { return $this->remaining === 0; } /** * Get the limit value. */ public function getLimit(): ?int { return $this->limit; } /** * Get the used value. */ public function getUsed(): ?int { return $this->used; } /** * Get the remaining value. */ public function getRemaining(): ?int { return $this->remaining; } /** * Convert to array for JSON responses. */ public function toArray(): array { return [ 'allowed' => $this->allowed, 'reason' => $this->reason, 'limit' => $this->limit, 'used' => $this->used, 'remaining' => $this->remaining, 'feature_code' => $this->featureCode, 'unlimited' => $this->isUnlimited(), 'usage_percentage' => $this->getUsagePercentage(), ]; } }