<?php

namespace app\common;

class Serve
{
    public static function push(string $action, array $data = [], int $delay = 0): bool
    {
        self::record('queue_push');
        return true;
    }

    public static function pushJump(string $action, array $data = []): bool
    {
        self::record('queue_jump');
        return true;
    }

    private static function record(string $event): void
    {
        $root = (string)(getenv('POC_APP_ROOT') ?: getenv('POC_TARGET_ROOT'));
        if ($root === '' || !is_dir($root . '/runtime')) {
            throw new \RuntimeException('Private queue stub root unavailable');
        }
        file_put_contents($root . '/runtime/poc-stub-hits.log', $event . "\n",
            FILE_APPEND | LOCK_EX);
    }
}

class UserApi
{
    public function run($apiType, $params = []): array
    {
        $root = (string)(getenv('POC_APP_ROOT') ?: getenv('POC_TARGET_ROOT'));
        if ($root === '' || !is_dir($root . '/runtime')) {
            throw new \RuntimeException('Private UserApi stub root unavailable');
        }
        file_put_contents($root . '/runtime/poc-stub-hits.log', 'user_sync' . "\n",
            FILE_APPEND | LOCK_EX);
        return ['is_success' => 1, 'zhct_user_id' => 0];
    }
}
