<?php
use App\Core\Router;
use App\Controllers\{GalleryController,CartController,CheckoutController};
use App\Controllers\Admin\{AuthController,DashboardController,EventController,PhotoController,OrderController,SettingsController};
use App\Middleware\AdminAuth;

$r = new Router();

// Público
$r->get('/',                [GalleryController::class,'home']);
$r->get('/contactos',      [GalleryController::class,'contact']);
$r->get('/evento/{slug}',    [GalleryController::class,'show']);
$r->post('/evento/{slug}',   [GalleryController::class,'show']);
$r->get('/carrinho',        [CartController::class,'show']);
$r->post('/carrinho/add',   [CartController::class,'add']);
$r->post('/carrinho/update',[CartController::class,'update']);
$r->post('/carrinho/remove',[CartController::class,'remove']);
$r->post('/carrinho/clear', [CartController::class,'clear']);
$r->get('/checkout',        [CheckoutController::class,'show']);
$r->post('/checkout',       [CheckoutController::class,'process']);
$r->get('/obrigado/{num}',  [CheckoutController::class,'thankyou']);
$r->get('/recibo/{num}',    [CheckoutController::class,'recibo']);

// Admin
$r->get('/admin/login',  [AuthController::class,'showLogin']);
$r->post('/admin/login', [AuthController::class,'login']);
$r->get('/admin/logout',     [AuthController::class,'logout']);
$r->get('/admin/definicoes',  [SettingsController::class,'index'],  [AdminAuth::class]);
$r->post('/admin/definicoes', [SettingsController::class,'update'], [AdminAuth::class]);
$r->post('/admin/definicoes/logo',     [SettingsController::class,'uploadLogo'],    [AdminAuth::class]);
$r->post('/admin/definicoes/password', [SettingsController::class,'changePassword'],[AdminAuth::class]);
$r->post('/admin/definicoes/precos',   [SettingsController::class,'updatePrecos'],  [AdminAuth::class]);
$r->get('/admin',        [DashboardController::class,'index'],[AdminAuth::class]);

$r->get('/admin/eventos',                          [EventController::class,'index'],    [AdminAuth::class]);
$r->post('/admin/eventos',                         [EventController::class,'store'],    [AdminAuth::class]);
$r->post('/admin/eventos/{id}/update',             [EventController::class,'update'],   [AdminAuth::class]);
$r->post('/admin/eventos/{id}/toggle',             [EventController::class,'toggle'],   [AdminAuth::class]);
$r->post('/admin/eventos/{id}/delete',             [EventController::class,'delete'],   [AdminAuth::class]);
$r->get('/admin/eventos/{id}/relatorio',           [EventController::class,'report'],      [AdminAuth::class]);
$r->get('/admin/eventos/{id}/fotos-vendidas',      [EventController::class,'soldPhotos'],  [AdminAuth::class]);
$r->post('/admin/eventos/{id}/reset-vendas',       [EventController::class,'resetSales'],[AdminAuth::class]);
$r->get('/admin/eventos/{id}/fotos',               [PhotoController::class,'manage'],   [AdminAuth::class]);
$r->post('/admin/eventos/{id}/upload',             [PhotoController::class,'upload'],   [AdminAuth::class]);
$r->post('/admin/eventos/{eid}/capa/{pid}',        [PhotoController::class,'setCover'], [AdminAuth::class]);
$r->post('/admin/eventos/{eid}/foto/{pid}/delete', [PhotoController::class,'delete'],   [AdminAuth::class]);

$r->get('/admin/encomendas',        [OrderController::class,'index'], [AdminAuth::class]);
$r->get('/admin/encomendas/{id}',              [OrderController::class,'show'],        [AdminAuth::class]);
$r->post('/admin/encomendas/{id}',             [OrderController::class,'update'],      [AdminAuth::class]);
$r->post('/admin/encomendas/{id}/foto/add',    [OrderController::class,'addPhoto'],    [AdminAuth::class]);
$r->post('/admin/encomendas/{id}/foto/remove', [OrderController::class,'removePhoto'], [AdminAuth::class]);

return $r;
