<?php
declare(strict_types=1);

/** Pure decision for one frozen A-side synthetic fixture; deny on uncertainty. */
function dualSwappedARecoveryDecision(array $journal, array $seen): string
{
    $marker = 'CDXEMDUAL89C5BDEB043A';
    $keys = ['electronic_menu', 'electronic_menu_bind_code',
        'electronic_menu_device', 'electronic_menu_device_log'];
    if (($journal['lane'] ?? null) !== 'A'
        || ($journal['phase'] ?? null) !== 'http_started'
        || ($journal['marker'] ?? null) !== $marker
        || (int)($journal['actor_id'] ?? 0) <= 0
        || (int)($journal['menu_id'] ?? 0) <= 0
        || preg_match('/^[A-F0-9]{32}$/D', (string)($journal['uuid'] ?? '')) !== 1
        || preg_match('/^[a-f0-9]{64}$/D',
            (string)($journal['public_token'] ?? '')) !== 1
        || !is_array($journal['source_before'] ?? null)
        || array_keys($journal['source_before']) !== $keys) {
        return 'deny';
    }
    foreach ($journal['source_before'] as $hash) {
        if (preg_match('/^[a-f0-9]{64}$/D', (string)$hash) !== 1) return 'deny';
    }
    foreach (['same_worker_generation', 'same_source',
        'two_ordered_boundaries', 'dev_db_identity',
        'unmodified_relation_hashes'] as $key) {
        if (($seen[$key] ?? false) !== true) return 'deny';
    }
    if (!is_array($seen['actor_rows'] ?? null)
        || !is_array($seen['menu_rows'] ?? null)
        || ($seen['relations'] ?? null) !== [
            'electronic_menu_bind_code' => 0,
            'electronic_menu_device' => 0,
            'electronic_menu_device_log' => 0]) {
        return 'deny';
    }
    if ($seen['actor_rows'] === [] && $seen['menu_rows'] === []) {
        return ($seen['full_baseline_restored'] ?? false) === true
            ? 'advance_zero' : 'deny';
    }
    if (count($seen['actor_rows']) !== 1
        || count($seen['menu_rows']) !== 1) return 'deny';
    $actor = $seen['actor_rows'][0];
    $menu = $seen['menu_rows'][0];
    if (!is_array($actor) || !is_array($menu)
        || (int)($actor['id'] ?? 0) !== (int)$journal['actor_id']
        || (string)($actor['uuid'] ?? '') !== $marker
        || (string)($actor['account'] ?? '') !== $marker
        || (string)($actor['create_by'] ?? '') !== $marker
        || (int)($actor['type'] ?? -1) !== 0
        || (int)($actor['is_delete'] ?? -1) !== 0
        || (int)($menu['id'] ?? 0) !== (int)$journal['menu_id']
        || (string)($menu['uuid'] ?? '') !== $journal['uuid']
        || (string)($menu['public_token'] ?? '') !== $journal['public_token']
        || (string)($menu['create_by'] ?? '') !== $marker
        || (int)($menu['store_id'] ?? 0) !== 10001
        || (int)($menu['status'] ?? 0) !== 1
        || (int)($menu['is_delete'] ?? -1) !== 0
        || (int)($menu['display_mode'] ?? 0) !== 2
        || (int)($menu['left_restaurant_id'] ?? 0) <= 0
        || (int)($menu['right_restaurant_id'] ?? 0) <= 0
        || (int)$menu['left_restaurant_id'] === (int)$menu['right_restaurant_id']
        || (int)($menu['carousel_interval'] ?? 0) !== 9) {
        return 'deny';
    }
    return 'exact_delete';
}
