<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Doctor\AuthController;
use App\Http\Controllers\Doctor\DashboardController;
use App\Http\Controllers\Doctor\QueueController;
use App\Http\Controllers\Doctor\AppointmentController;
use App\Http\Controllers\Doctor\ArchiveController;
use App\Http\Controllers\Doctor\ProfileController;
use App\Http\Controllers\Doctor\MedicineController;
use App\Http\Controllers\Doctor\SecretaryController;
use App\Http\Controllers\Doctor\ReferralController;

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

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

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

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

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

        // الطابور
        Route::get('queue',                    [QueueController::class, 'index'])->name('queue.index');
        Route::post('queue/call-next',         [QueueController::class, 'callNext'])->name('queue.callNext');
        Route::patch('queue/{id}/start',       [QueueController::class, 'startExam'])->name('queue.start');
        Route::patch('queue/{id}/complete',    [QueueController::class, 'completeExam'])->name('queue.complete');
        Route::patch('queue/{id}/skip',        [QueueController::class, 'skip'])->name('queue.skip');

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

        // الأرشيف الطبي
        Route::get('archive',                  [ArchiveController::class, 'index'])->name('archive.index');
        Route::get('archive/patient/{id}',     [ArchiveController::class, 'patient'])->name('archive.patient');
        Route::get('archive/record/{id}',      [ArchiveController::class, 'record'])->name('archive.record');
        Route::get('archive/record/{id}/print',[ArchiveController::class, 'print'])->name('archive.print');
        Route::post('archive/record',          [ArchiveController::class, 'store'])->name('archive.store');
        Route::put('archive/record/{id}',      [ArchiveController::class, 'update'])->name('archive.update');

        // الأدوية والتحاليل المفضلة
        Route::get('medicines',                    [MedicineController::class, 'index'])->name('medicines.index');
        Route::get('medicines/api/list',           [MedicineController::class, 'getMedicines'])->name('medicines.api');
        Route::get('medicines/api/auto-suggest',   [MedicineController::class, 'getAutoSuggest'])->name('medicines.auto-suggest');
        Route::get('medicines/api/tests',          [MedicineController::class, 'getTests'])->name('tests.api');
        Route::post('medicines/medicine',          [MedicineController::class, 'storeMedicine'])->name('medicines.store');
        Route::put('medicines/medicine/{id}',      [MedicineController::class, 'updateMedicine'])->name('medicines.update');
        Route::delete('medicines/medicine/{id}',   [MedicineController::class, 'destroyMedicine'])->name('medicines.destroy');
        Route::post('medicines/test',              [MedicineController::class, 'storeTest'])->name('tests.store');
        Route::put('medicines/test/{id}',          [MedicineController::class, 'updateTest'])->name('tests.update');
        Route::delete('medicines/test/{id}',       [MedicineController::class, 'destroyTest'])->name('tests.destroy');

        // التحويلات الطبية
        Route::post('referral',              [ReferralController::class, 'store'])->name('referral.store');
        Route::get('referral/{id}/print',    [ReferralController::class, 'print'])->name('referral.print');
        Route::delete('referral/{id}',       [ReferralController::class, 'destroy'])->name('referral.destroy');

        // إدارة السكرتيرين
        Route::get('secretaries',                [SecretaryController::class, 'index'])->name('secretaries.index');
        Route::post('secretaries',               [SecretaryController::class, 'store'])->name('secretaries.store');
        Route::patch('secretaries/{id}/toggle',  [SecretaryController::class, 'toggle'])->name('secretaries.toggle');
        Route::delete('secretaries/{id}',        [SecretaryController::class, 'destroy'])->name('secretaries.destroy');

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