<?php

namespace App\Http\Controllers;

use App\Models\Pages;
use Illuminate\Http\Request;

class PageController extends Controller
{
 /**
     * Get all active pages
     */
    public function index(Request $request)
    {
        $pages = Pages::query()
            ->where('is_active', true)
            ->when($request->has('featured'), function ($query) {
                $query->where('is_featured', true);
            })
            ->latest()
            ->get();

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

    /**
     * Get single page by slug
     */
    public function show(string $slug)
    {
        $page = Pages::where('slug', $slug)
            ->where('is_active', true)
            ->firstOrFail();

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

    /**
     * Get featured pages
     */
    public function featured()
    {
        $pages = Pages::where('is_active', true)
            ->where('is_featured', true)
            ->latest()
            ->get();

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