<?php

namespace App\Http\Controllers\Api\V1\Draw;

use App\Support\ApiResponse;
use Illuminate\Http\Request;
use App\Support\CurrencyResolver;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Services\Draw\DrawHallSnapshotBuilder;

/**
 * 下注大厅：`GET /api/v1/draw/current`。
 */
final class DrawCurrentController extends Controller
{
    public function __construct(
        private readonly DrawHallSnapshotBuilder $snapshot,
    ) {}

    public function __invoke(Request $request): JsonResponse
    {
        $currencyCode = CurrencyResolver::resolve($request, $request->lotteryPlayer());

        return ApiResponse::success([
            'server_now_ms' => (int) floor(microtime(true) * 1000),
            'data' => $this->snapshot->build(null, $currencyCode),
        ]);
    }
}
