<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;

class SystemController extends Controller
{
    public function index(): JsonResponse
    {
        return response()->json([
            'name' => config('app.name').' API',
            'version' => 'v1',
        ]);
    }

    public function health(): JsonResponse
    {
        try {
            DB::select('select 1');

            return response()->json(['status' => 'ok']);
        } catch (\Throwable $exception) {
            report($exception);

            return response()->json(['status' => 'unavailable'], 503);
        }
    }
}
