400,'status'=>'error','message'=>'هوية الدرس غير صالحة.']; $lesson=Database::selectOne("SELECT cl.id,cl.uuid,cl.grade_key,cl.title FROM curriculum_lessons cl WHERE cl.uuid=? AND cl.source_status='approved' LIMIT 1",[$lessonUuid]); if(!$lesson)return ['http_status'=>404,'status'=>'error','message'=>'الدرس غير منشور.']; $access=StudentAccessControlService::validateLessonAccess($studentId,$nationalId,StudentAccessControlService::normalizeGrade((string)$lesson['grade_key']),null,null,false); if(empty($access['allowed']))return ['http_status'=>403,'status'=>'forbidden','message'=>$access['message']??'غير مصرح بالوصول إلى الدرس.']; $package=Database::selectOne("SELECT lp.id,lp.structure_json,pb.bundle_version FROM lesson_learning_packages lp JOIN publication_bundles pb ON pb.id=lp.bundle_id AND pb.status='published' WHERE lp.curriculum_lesson_id=? AND lp.package_type='english' AND lp.status='published' LIMIT 1",[$lesson['id']]); if(!$package)return ['http_status'=>404,'status'=>'not_ready','message'=>'حزمة الإنجليزية المعتمدة لهذا الدرس لم تُنشر بعد.']; $entries=Database::select("SELECT e.lemma,e.part_of_speech,e.meaning_ar,e.ipa_verified,a.uuid AS audio_asset_id FROM english_lexical_entries e LEFT JOIN content_assets a ON a.id=e.audio_asset_id AND a.review_status='approved' WHERE e.lesson_learning_package_id=? AND e.review_status='approved' ORDER BY e.id",[$package['id']]); return ['http_status'=>200,'status'=>'success','data'=>['curriculum_lesson_id'=>$lesson['uuid'],'title'=>$lesson['title'],'bundle_version'=>$package['bundle_version'],'structure'=>json_decode((string)$package['structure_json'],true)??[],'lexical_entries'=>$entries]]; } }