<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Services\AppVersionService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;

class AppVersionController extends Controller
{
    /**
     * 최신 버전 확인
     * GET /api/v1/app/version?platform=android&current_version_code=1
     */
    public function latestVersion(Request $request): JsonResponse
    {
        $platform = $request->input('platform', 'android');
        $currentVersionCode = (int) $request->input('current_version_code', 0);

        $result = AppVersionService::getLatestVersion($platform, $currentVersionCode);

        return response()->json([
            'success' => true,
            'data' => $result,
        ]);
    }

    /**
     * APK 다운로드
     * GET /api/v1/app/download/{id}
     */
    public function download(int $id): StreamedResponse
    {
        return AppVersionService::downloadApk($id);
    }
}
