<?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DeviceController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\BorderStationController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\DispatchController;
use App\Http\Controllers\LeaseController;
use App\Http\Controllers\PricingController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\TagPointController;
use App\Http\Controllers\ReturnController;
use App\Http\Controllers\InventoryController;
use App\Http\Controllers\LeaseReportController;


Route::redirect('/', '/dashboard');

Route::middleware(['auth'])->group(function () {


    Route::resource('users', UserController::class);


    //Role

    Route::get('/roles', [RoleController::class, 'index'])
        ->name('roles.index');

    Route::post('/roles', [RoleController::class, 'store'])
        ->name('roles.store');

    Route::put('/roles/{role}', [RoleController::class, 'update'])
        ->name('roles.update');

    Route::resource('border-stations', BorderStationController::class);


    Route::get('/dashboard', [DashboardController::class, 'index'])
        ->name('dashboard');

    Route::get('/profile', [ProfileController::class, 'edit'])
        ->name('profile.edit');

    Route::patch('/profile', [ProfileController::class, 'update'])
        ->name('profile.update');

    Route::delete('/profile', [ProfileController::class, 'destroy'])
        ->name('profile.destroy');



    // Device

    Route::resource('devices', DeviceController::class);

    Route::post('/devices/import', [DeviceController::class, 'import'])
        ->name('devices.import');



    Route::resource(
        'pricings',
        PricingController::class
    );

    Route::resource(
        'customers',
        CustomerController::class
    );

    Route::resource(
        'tag-points',
        TagPointController::class
    );

    Route::resource('dispatches', DispatchController::class);

    Route::post(
        '/dispatches/{dispatch}/receive',
        [DispatchController::class, 'receive']
    )->name('dispatches.receive');

    Route::get(
        '/dispatches/{dispatch}/devices',
        [DispatchController::class, 'devices']
    )->name('dispatches.devices');


    Route::resource('leases', LeaseController::class);

    Route::post(
        '/leases/{lease}/audit',
        [LeaseController::class, 'audit']
    )->name('leases.audit');

    Route::get(
        '/leases/{lease}/details',
        [LeaseController::class, 'details']
    )->name('leases.details');


    Route::get(
        '/leases/{lease}/edit-details',
        [LeaseController::class, 'editDetails']
    )->name('leases.edit-details');


    Route::post(
        '/leases/{lease}/audit',
        [LeaseController::class, 'audit']
    )->name('leases.audit');


    Route::get(
        '/returns',
        [ReturnController::class, 'index']
    )->name('returns.index');

    Route::get(
        '/returns/{returnNo}',
        [ReturnController::class, 'show']
    )->name('returns.show');

    Route::post(
        '/returns/{returnNo}/receive',
        [ReturnController::class, 'receive']
    )->name('returns.receive');

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

            Route::get(
                '/devices',
                [InventoryController::class, 'devices']
            )->name('devices');

            Route::get(
                '/movements',
                [InventoryController::class, 'movements']
            )->name('movements');
        });



Route::get(
    '/reports/leases',
    [LeaseReportController::class, 'index']
)->name('reports.leases');


Route::get(
    '/reports/leases/view',
    [LeaseReportController::class, 'ViewReport']
)->name('reports.leases.view');



Route::get(
    '/leases/{lease}/swap-form',
    [LeaseController::class, 'swapForm']
)->name('leases.swap.form');

Route::post(
    '/leases/{lease}/swap-device',
    [LeaseController::class, 'swapDevice']
)->name('leases.swap');



Route::post(
    '/leases/{lease}/cancel',
    [LeaseController::class, 'cancel']
)->name('leases.cancel');



});




Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__ . '/auth.php';
