<?php

namespace App\Framework\Smartlinks\Actions;

use App\Framework\Smartlinks\SmartlinkData;
use App\Framework\Smartlinks\TokenConfig;
use DateTimeImmutable;
final readonly class EmailVerificationAction implements SmartlinkAction
{
    public function getName(): string
    {
        return 'email_verification';
    }

    public function getDefaultConfig(): TokenConfig
    {
        return new TokenConfig(
            expiryHours: 24,
            oneTimeUse: true,
            maxUses: 1,
            requireSecureContext: true
        );
    }

    public function validatePayload(array $payload): bool
    {
        return !empty($payload['email']) &&
            !empty($payload['user_id']) &&
            filter_var($payload['email'], FILTER_VALIDATE_EMAIL);
    }

    public function execute(SmartlinkData $smartlinkData, array $context = []): ActionResult
    {
        $payload = $smartlinkData->payload;

        // Email verification logic would go here
        // For now, just a simple success response

        return ActionResult::success(
            message: "Email {$payload['email']} successfully verified",
            data: [
                'user_id' => $payload['user_id'],
                'email' => $payload['email'],
                'verified_at' => new DateTimeImmutable()
            ],
            redirectUrl: '/dashboard'
        );
    }

    public function getRequiredPermissions(): array
    {
        return []; // No special permissions needed for email verification
    }
}
