<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Patient\AuthController;
use App\Http\Controllers\Patient\DashboardController;
use App\Http\Controllers\Patient\AppointmentController;
use App\Http\Controllers\Patient\RecordController;
use App\Http\Controllers\Patient\NotificationController;
use App\Http\Controllers\Patient\DoctorController;
use App\Http\Controllers\Patient\SubscriptionController;

Route::prefix('patient')->name('patient.')->group(function () {

    Route::get('login',  [AuthController::class, 'showLogin'])->name('login');
    Route::post('login', [AuthController::class, 'login'])->name('login.post');
    Route::get('register',  [AuthController::class, 'showRegister'])->name('register');
    Route::post('register', [AuthController::class, 'register'])->name('register.post');

    Route::middleware('patient.auth')->group(function () {

        Route::post('logout', [AuthController::class, 'logout'])->name('logout');

        // الداشبورد
        Route::get('/',          [DashboardController::class, 'index'])->name('dashboard');

        // الأطباء والبحث
        Route::get('doctors',           [DoctorController::class, 'index'])->name('doctors.index');
        Route::get('doctors/{id}',      [DoctorController::class, 'show'])->name('doctors.show');
        Route::post('doctors/{id}/review', [DoctorController::class, 'storeReview'])->name('doctors.review');

        // المواعيد
        Route::get('appointments',          [AppointmentController::class, 'index'])->name('appointments.index');
        Route::post('appointments',         [AppointmentController::class, 'store'])->name('appointments.store');
        Route::delete('appointments/{id}',  [AppointmentController::class, 'cancel'])->name('appointments.cancel');

        // الطابور
        Route::post('queue/join/{doctorId}', [AppointmentController::class, 'joinQueue'])->name('queue.join');
        Route::get('queue/status',           [AppointmentController::class, 'queueStatus'])->name('queue.status');
        Route::delete('queue/leave',         [AppointmentController::class, 'leaveQueue'])->name('queue.leave');

        // السجلات الطبية
        Route::get('records',       [RecordController::class, 'index'])->name('records.index');
        Route::get('records/{id}',  [RecordController::class, 'show'])->name('records.show');

        // الإشعارات
        Route::get('notifications',           [NotificationController::class, 'index'])->name('notifications.index');
        Route::patch('notifications/{id}/read',[NotificationController::class, 'markRead'])->name('notifications.read');
        Route::post('notifications/read-all', [NotificationController::class, 'readAll'])->name('notifications.readAll');

        // الاشتراكات
        Route::get('subscription',               [SubscriptionController::class, 'index'])->name('subscription.index');
        Route::get('subscription/choose/{planId}',[SubscriptionController::class, 'choose'])->name('subscription.choose');
        Route::post('subscription/checkout/{planId}',[SubscriptionController::class, 'checkout'])->name('subscription.checkout');
        Route::post('subscription/cancel',       [SubscriptionController::class, 'cancel'])->name('subscription.cancel');

        // الملف الشخصي
        Route::get('profile',  [DashboardController::class, 'profile'])->name('profile');
        Route::put('profile',  [DashboardController::class, 'updateProfile'])->name('profile.update');
    });
});
