<?php

namespace App\Http\Controllers\Api;

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

class JuzController extends Controller
{
    /**
     * Get all Juzs
     */
    public function index()
    {
        $juzs = Juz::orderBy('juz_number')->get()->map(function ($juz) {
            return [
                'juz_number' => $juz->juz_number,
                'ayahs_count' => count($juz->ayahs_data['ayahs'] ?? []),
            ];
        });

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

    /**
     * Get a specific Juz detail
     */
    public function show($id)
    {
        $juz = Juz::where('juz_number', $id)->first();
        
        if (!$juz) {
            return response()->json([
                'success' => false,
                'message' => 'Juz not found',
            ], 404);
        }

        // Return in the same format as the original API
        return response()->json([
            'code' => 200,
            'status' => 'OK',
            'data' => $juz->ayahs_data,
        ]);
    }
}
