<?php

namespace App\Http\Controllers\Api;

use App\Exceptions\ApiHttpException;
use App\Facades\InformationService;
use App\Http\Controllers\Controller;
use App\Http\Resources\InformationListResource;
use App\Http\Resources\InformationResource;

class InformationController extends Controller
{
    public function index()
    {
        $informationList = InformationService::getInformation();

        return InformationListResource::collection($informationList);
    }

    public function show($slug)
    {
        $information = InformationService::getInformationBySlug($slug);

        if (empty($information)) {
            throw new ApiHttpException(404, 'information_not_found');
        }

        return new InformationResource($information);
    }
}
