<?php

namespace App\Http\Controllers\Api;

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

class DuaController extends Controller
{
    // Get all duas
    public function index()
    {
        $duas = Dua::with('category')->get();
        return response()->json([
            'success' => true,
            'data' => $duas,
        ]);
    }

    // Get a specific dua
    public function show($id)
    {
        $dua = Dua::with('category')->find($id);
        if (!$dua) {
            return response()->json([
                'success' => false,
                'message' => 'Dua not found',
            ], 404);
        }
        return response()->json([
            'success' => true,
            'data' => $dua,
        ]);
    }

    

      // Get duas by category ID
      public function byCategory($categoryId)
      {
          $duas = Dua::where('dua_category_id', $categoryId)->with('category')->get();
          if ($duas->isEmpty()) {
              return response()->json([
                  'success' => false,
                  'message' => 'No duas found for this category',
              ], 404);
          }
          return response()->json([
              'success' => true,
              'data' => $duas,
          ]);
      }
}
