<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Guide;
use Illuminate\Http\Request;

class GuideController extends Controller
{
    /**
     * Get Prayer Guide PDFs
     */
    public function prayerGuide()
    {
        $guides = Guide::where('type', Guide::TYPE_PRAYER_GUIDE)
            ->orderBy('created_at', 'desc')
            ->get()
            ->map(function ($guide) {
                return [
                    'id' => $guide->id,
                    'title' => $guide->title,
                    'description' => $guide->description,
                    'pdf_url' => $guide->pdf_file ? url($guide->pdf_file) : null,
                    'created_at' => $guide->created_at,
                ];
            });

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

    /**
     * Get More Zikar PDFs
     */
    public function moreZikar()
    {
        $guides = Guide::where('type', Guide::TYPE_MORE_ZIKAR)
            ->orderBy('created_at', 'desc')
            ->get()
            ->map(function ($guide) {
                return [
                    'id' => $guide->id,
                    'title' => $guide->title,
                    'description' => $guide->description,
                    'pdf_url' => $guide->pdf_file ? url($guide->pdf_file) : null,
                    'created_at' => $guide->created_at,
                ];
            });

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

    /**
     * Get Hajj & Umrah PDFs
     */
    public function hajjUmrah()
    {
        $guides = Guide::where('type', Guide::TYPE_HAJJ_UMRAH)
            ->orderBy('created_at', 'desc')
            ->get()
            ->map(function ($guide) {
                return [
                    'id' => $guide->id,
                    'title' => $guide->title,
                    'description' => $guide->description,
                    'pdf_url' => $guide->pdf_file ? url($guide->pdf_file) : null,
                    'created_at' => $guide->created_at,
                ];
            });

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