<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;

Route::get('/', function () {
    return redirect()->route('login');
});

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

Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [\App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard');
    Route::resource('categories', \App\Http\Controllers\CategoryController::class);
    Route::resource('units', \App\Http\Controllers\UnitController::class);
    Route::resource('suppliers', \App\Http\Controllers\SupplierController::class);
    Route::get('/medicines/template', [\App\Http\Controllers\MedicineController::class, 'downloadTemplate'])->name('medicines.template');
    Route::post('/medicines/import', [\App\Http\Controllers\MedicineController::class, 'import'])->name('medicines.import');
    Route::resource('medicines', \App\Http\Controllers\MedicineController::class);
    Route::resource('users', \App\Http\Controllers\UserController::class);
    Route::resource('purchases', \App\Http\Controllers\PurchaseController::class);

    // Kasir / POS
    Route::get('/pos', [\App\Http\Controllers\PosController::class, 'index'])->name('pos.index');
    Route::post('/pos/transaction', [\App\Http\Controllers\PosController::class, 'storeTransaction'])->name('pos.transaction');
    Route::get('/pos/search-medicines', [\App\Http\Controllers\PosController::class, 'searchMedicines'])->name('pos.search');
    Route::get('/pos/print/{id}', [\App\Http\Controllers\PosController::class, 'printReceipt'])->name('pos.print');

    // Shift Kasir
    Route::get('/shift/check', [\App\Http\Controllers\ShiftController::class, 'check'])->name('shift.check');
    Route::post('/shift/open', [\App\Http\Controllers\ShiftController::class, 'open'])->name('shift.open');
    Route::post('/shift/close', [\App\Http\Controllers\ShiftController::class, 'close'])->name('shift.close');
    
    // Admin Forecasting
    Route::get('/forecasting', [\App\Http\Controllers\ForecastingController::class, 'index'])->name('forecasting.index');

    // Admin Reports
    Route::get('/reports/sales', [\App\Http\Controllers\ReportController::class, 'sales'])->name('reports.sales');

    // System Settings
    Route::get('/settings', [\App\Http\Controllers\SettingController::class, 'index'])->name('settings.index');
    Route::put('/settings', [\App\Http\Controllers\SettingController::class, 'update'])->name('settings.update');
});
