<?php

namespace Tests\Support;

use App\ScheduledTasks\ActionResult;
use App\ScheduledTasks\Contracts\TaskAction;
use App\ScheduledTasks\TaskRunContext;

class FakeTaskAction implements TaskAction
{
    public static array $executed = [];

    public function key(): string
    {
        return 'fake';
    }

    public function label(): string
    {
        return 'Fake action';
    }

    public function available(): bool
    {
        return true;
    }

    public function userSelectable(): bool
    {
        return true;
    }

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

    public function rules(array $config): array
    {
        return [];
    }

    public function execute(array $config, TaskRunContext $context): ActionResult
    {
        self::$executed[] = $config['marker'] ?? 'unmarked';

        if (!empty($config['fail'])) {
            return ActionResult::failed('Deliberate failure');
        }

        return ActionResult::completed('Fake done', ['marker' => $config['marker'] ?? null]);
    }

    public function queue(): string
    {
        return 'sync';
    }
}
