<?php

namespace App\Http\Controllers\GoogleCloud;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

class CloudApiPricingController extends Controller
{
    public function index(Request $request): View|Response
    {
        if ($request->header('HX-Request')) {
            return response('', 200)->header('HX-Redirect', route('google-cloud.cloud-api-pricing.index'));
        }

        return view('google-cloud.cloud-api-pricing.index');
    }

    public function download(): BinaryFileResponse
    {
        $path = public_path('downloads/google-cloud-api-pricing.pptx');

        abort_unless(file_exists($path), 404, 'PPTX 파일을 찾을 수 없습니다.');

        return response()->download($path, 'Google_Cloud_API_요금표.pptx');
    }
}
