# Extension and action examples

<!-- Maintained by scripts/generate-package-readmes.php -->

Use the action functions with records and Data objects supplied by your application.
They pass each argument to the package operation and return its result.

These adapters show container registration. Use the owning package registry when
a contract requires contributor discovery.

Contract adapters wrap an existing implementation. Call their registration function
from your service provider with that implementation; tagged contracts keep their declared tag.
Resolve the backend by its concrete class before registration so the replacement contract
does not resolve itself. Static contract metadata uses one backend class per adapter.

## Contract `Capell\AutomationStudio\Contracts\AutomationActionHandler`

<!-- example: contract Capell\AutomationStudio\Contracts\AutomationActionHandler -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

final class AutomationActionHandlerAdapter implements \Capell\AutomationStudio\Contracts\AutomationActionHandler
{
    public function __construct(private readonly \Capell\AutomationStudio\Contracts\AutomationActionHandler $backend) {}

    #[\Override]
    public function handle(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, \Capell\AutomationStudio\Data\AutomationRuleActionData $action): \Capell\AutomationStudio\Data\AutomationActionResultData
    {
        return $this->backend->handle($event, $action);
    }
}

function registerAutomationActionHandlerAdapter(\Capell\AutomationStudio\Contracts\AutomationActionHandler $backend): void
{
    app()->bind(AutomationActionHandlerAdapter::class, static fn (): AutomationActionHandlerAdapter => new AutomationActionHandlerAdapter($backend));
    app()->bind(\Capell\AutomationStudio\Contracts\AutomationActionHandler::class, AutomationActionHandlerAdapter::class);
}
```

## Action `dispatchAutomationTrigger`

<!-- example: action dispatchAutomationTrigger -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runDispatchAutomationTrigger(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, ?string $idempotencyKey = null, ?int $siteId = null, int $attemptNumber = 1, ?int $maxAttempts = null, ?\Capell\AutomationStudio\Support\AutomationRuleRegistry $rules = null, ?\Capell\AutomationStudio\Support\AutomationActionRegistry $actions = null, ?\Capell\AutomationStudio\Actions\PersistAutomationTriggerResultsAction $persistResults = null): array
{
    return \Capell\AutomationStudio\Actions\DispatchAutomationTriggerAction::run($event, $idempotencyKey, $siteId, $attemptNumber, $maxAttempts, $rules, $actions, $persistResults);
}
```

## Action `dryRunAutomationRules`

<!-- example: action dryRunAutomationRules -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runDryRunAutomationRules(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, ?int $siteId = null): array
{
    return \Capell\AutomationStudio\Actions\DryRunAutomationRulesAction::run($event, $siteId);
}
```

## Action `loadPersistedAutomationRules`

<!-- example: action loadPersistedAutomationRules -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runLoadPersistedAutomationRules(?int $siteId = null): \Illuminate\Support\Collection
{
    return \Capell\AutomationStudio\Actions\LoadPersistedAutomationRulesAction::run($siteId);
}
```

## Action `persistAutomationTriggerResults`

<!-- example: action persistAutomationTriggerResults -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runPersistAutomationTriggerResults(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, array $results, ?string $idempotencyKey = null, ?int $siteId = null, int $attemptNumber = 1, ?int $maxAttempts = null): void
{
    \Capell\AutomationStudio\Actions\PersistAutomationTriggerResultsAction::run($event, $results, $idempotencyKey, $siteId, $attemptNumber, $maxAttempts);
}
```

## Action `queueAutomationTrigger`

<!-- example: action queueAutomationTrigger -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runQueueAutomationTrigger(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, ?int $siteId = null, ?string $idempotencyKey = null, ?string $deduplicationKey = null): string
{
    return \Capell\AutomationStudio\Actions\QueueAutomationTriggerAction::run($event, $siteId, $idempotencyKey, $deduplicationKey);
}
```

## Action `reapStaleAutomationRuns`

<!-- example: action reapStaleAutomationRuns -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runReapStaleAutomationRuns(?int $staleAfterMinutes = null, ?int $limit = null): int
{
    return \Capell\AutomationStudio\Actions\ReapStaleAutomationRunsAction::run($staleAfterMinutes, $limit);
}
```

## Action `recordAutomationRun`

<!-- example: action recordAutomationRun -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runRecordAutomationRun(\Capell\AutomationStudio\Data\AutomationTriggerEventData $event, ?\Capell\AutomationStudio\Models\AutomationRule $rule = null, ?\Capell\AutomationStudio\Data\AutomationRuleActionData $action = null, ?\Capell\AutomationStudio\Data\AutomationActionResultData $result = null, ?int $siteId = null, ?string $idempotencyKey = null, int $attemptNumber = 1, ?int $maxAttempts = null): \Capell\AutomationStudio\Models\AutomationRun
{
    return \Capell\AutomationStudio\Actions\RecordAutomationRunAction::run($event, $rule, $action, $result, $siteId, $idempotencyKey, $attemptNumber, $maxAttempts);
}
```

## Action `registerAutomationStudioDefaults`

<!-- example: action registerAutomationStudioDefaults -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runRegisterAutomationStudioDefaults(): void
{
    \Capell\AutomationStudio\Actions\RegisterAutomationStudioDefaultsAction::run();
}
```

## Action `replayAutomationRun`

<!-- example: action replayAutomationRun -->

```php
<?php
declare(strict_types=1);

namespace App\CapellExamples\AutomationStudio;

function runReplayAutomationRun(\Capell\AutomationStudio\Models\AutomationRun $run): array
{
    return \Capell\AutomationStudio\Actions\ReplayAutomationRunAction::run($run);
}
```