<?php

use App\Http\Controllers\FrontendController;
use App\Http\Controllers\NovostiController;
use App\Http\Controllers\ProizvodiController;
use App\Http\Controllers\QrCodeController;
use App\Models\Novosti;
use App\Models\Proizvodi;
use App\Models\QrCodes;
use App\Models\QrCodesList;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\language\LanguageController;
use App\Http\Controllers\pages\HomePage;
use App\Http\Controllers\pages\MiscError;
use App\Http\Controllers\authentications\LoginBasic;
use App\Http\Controllers\authentications\RegisterBasic;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/


//Protected

Route::group(['middleware' => ['auth:sanctum', 'verified', 'checkUserRoleType:administrator']], function () {
    //Route::get('/', [NarudzbeLista::class, 'index'])->name('home');

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

    //QR Kodovi
    Route::get('administracija/qrcodes', [QrCodeController::class, 'index'])->name('admin.qrcodes.lista');
    Route::get('administracija/qrcodes/{id}', [QrCodeController::class, 'show'])->name('admin.qrcodes.pregled');
    Route::get('administracija/pdf/qrcodes/{id}', [QrCodeController::class, 'generate_pdf_qrcode_list'])->name('admin.qrcodes.pdf.pregled');
    Route::post('administracija/novi', [QrCodeController::class, 'store'])->name('admin.qrcodes.novi');
    Route::get('administracija/qrcodes/brisanje/{id}', [QrCodeController::class, 'destroy'])->name('admin.qrcodes.destroy');


    //Proizvodi
    Route::get('administracija/proizvodi', [ProizvodiController::class, 'index'])->name('admin.proizvodi.lista');
    Route::get('administracija/proizvodi{id}', [ProizvodiController::class, 'show'])->name('admin.proizvodi.show');
    Route::get('administracija/proizvodi/uredi/{id}', [ProizvodiController::class, 'edit'])->name('admin.proizvodi.edit');
    Route::post('administracija/proizvodi/novi', [ProizvodiController::class, 'store'])->name('admin.proizvodi.novi');
    Route::put('administracija/proizvodi/update/{id}', [ProizvodiController::class, 'update'])->name('admin.proizvodi.update');
    Route::get('administracija/proizvodi/brisanje/{id}', [ProizvodiController::class, 'destroy'])->name('admin.proizvodi.brisanje');

    //Novosti
    Route::get('administracija/novosti', [NovostiController::class, 'index'])->name('admin.novosti.lista');
    Route::post('administracija/novosti/novi', [NovostiController::class, 'store'])->name('admin.novosti.novi');
    Route::get('administracija/novosti/uredi/{id}', [NovostiController::class, 'edit'])->name('admin.novosti.edit');
    Route::put('administracija/novosti/update/{id}', [NovostiController::class, 'update'])->name('admin.novosti.update');
    Route::get('administracija/novosti/brisanje/{id}', [NovostiController::class, 'destroy'])->name('admin.novosti.destroy');

    //API QR Kodovi
    Route::get('api/qrcodes', function () {
        $stavke = QrCodesList::all();
        return $stavke;
    });

    Route::get('api/qrcodes/lista/{id}', function (string $id) {
        $stavke = QrCodes::where('id_qrcodelist', $id)->get();
        return $stavke;
    });

    //API Novosti
    Route::get('api/novosti', function () {
        $stavke = Novosti::all();
        return $stavke;
    });

});

// Grupa ruta za obične korisnike
Route::group(['middleware' => ['auth:sanctum', 'verified', 'checkUserRoleType:user']], function () {


    Route::get('/profil', [FrontendController::class, 'profil'])->name('profil');
    Route::get('/skeniranje', [FrontendController::class, 'skeniranje'])->name('skeniranje');
    Route::put('/skeniranje/qrcodes/skeniraj', [FrontendController::class, 'skeniraj'])->name('skeniranje.novi');
    Route::post('/skeniranje/qrcodes/skeniraj', [FrontendController::class, 'skeniraj'])->name('skeniranje.novi');


});


//Proizvodi API
Route::get('api/proizvodi', function () {
    $stavke = Proizvodi::all();
    return $stavke;
});

// locale
Route::get('lang/{locale}', [LanguageController::class, 'swap']);

// pages
Route::get('/pages/misc-error', [MiscError::class, 'index'])->name('pages-misc-error');

// authentication
Route::get('/auth/login-basic', [LoginBasic::class, 'index'])->name('auth-login-basic');
Route::get('/auth/register-basic', [RegisterBasic::class, 'index'])->name('auth-register-basic');
//Route::get('/naslovna', [FrontendController::class, 'index'])->name('naslovna');

//Route kojim moze pristupiti public
Route::get('/rang-lista', [FrontendController::class, 'rangLista'])->name('rang-lista');
Route::get('/prijava', [FrontendController::class, 'prijava'])->name('korisnici.prijava');
Route::get('/novosti/{id}', [FrontendController::class, 'novostiShow'])->name('novost.single');
Route::get('/', [FrontendController::class, 'index'])->name('naslovna');

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
});