<?php

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

use App\Http\Controllers\Controller;
use App\Http\Resources\Api\V1\Legal\LegalPageResource;
use App\Models\Legal\LegalPage;
use Illuminate\Http\JsonResponse;

class LegalPageController extends Controller
{
    /**
     * (Legal) Legal pages
     */
    public function index(): JsonResponse
    {
        return response()->rest(
            LegalPage::where('is_active', true)
                ->get(['slug', 'title'])
                ->map(fn ($legalPage) => [
                    'slug' => $legalPage->slug,
                    'title' => $legalPage->title,
                ])
        );
    }

    /**
     * (Legal) Legal pages
     */
    public function show(LegalPage $legalPage): JsonResponse
    {
        return response()->rest(new LegalPageResource($legalPage));
    }
}
