<?php

namespace App\Framework\Smartlinks\Actions;

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

final readonly class GenericDataAccessAction implements SmartlinkAction
{
    public function __construct(
        private string $actionName,
        private TokenConfig $config,
        private array $requiredPermissions = []
    ) {}

    public function getName(): string
    {
        return $this->actionName;
    }

    public function getDefaultConfig(): TokenConfig
    {
        return $this->config;
    }

    public function validatePayload(array $payload): bool
    {
        // Generic validation - just check that payload is not empty
        return !empty($payload);
    }

    public function execute(SmartlinkData $smartlinkData, array $context = []): ActionResult
    {
        // Generic execution - just return the payload data
        return ActionResult::success(
            message: "Action '{$this->actionName}' executed successfully",
            data: $smartlinkData->payload
        );
    }

    public function getRequiredPermissions(): array
    {
        return $this->requiredPermissions;
    }
}
