<?php

declare(strict_types=1);

namespace CalendarPlugin\Infrastructure\WordPress;

use CalendarPlugin\Contracts\AuthAdapterInterface;

final class WordPressAuthAdapter implements AuthAdapterInterface
{
    public function currentUserId(): int
    {
        return (int) get_current_user_id();
    }

    public function currentUserCan(string $capability): bool
    {
        return current_user_can($capability);
    }

    public function verifyNonce(string $nonce, string $action): bool
    {
        return wp_verify_nonce($nonce, $action) !== false;
    }

    public function currentUserEmail(): string
    {
        $user = wp_get_current_user();
        return is_object($user) ? (string) ($user->user_email ?? '') : '';
    }
}
