<?php

namespace App\Framework\Smartlinks\Actions;

use App\Framework\Smartlinks\SmartlinkData;
use App\Framework\Smartlinks\TokenConfig;

final readonly class PasswordResetAction implements SmartlinkAction
{
    public function getName(): string
    {
        return 'password_reset';
    }

    public function getDefaultConfig(): TokenConfig
    {
        return new TokenConfig(
            expiryHours: 1, // Short expiry for security
            oneTimeUse: true,
            maxUses: 1,
            requireSecureContext: true
        );
    }

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

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

        // Password reset form would be shown here
        // Return data needed for the password reset form

        return ActionResult::success(
            message: "Password reset form ready",
            data: [
                'user_id' => $payload['user_id'],
                'email' => $payload['email'],
                'form_action' => '/password/reset/submit',
                'csrf_token' => $context['csrf_token'] ?? null
            ]
        );
    }

    public function getRequiredPermissions(): array
    {
        return [];
    }
}
