<?php

use App\Controllers\CategoryController;
use App\Controllers\CommentController;
use App\Controllers\DashboardController;
use App\Controllers\DivisiController;
use App\Controllers\HomeController;
use App\Controllers\LoginController;
use App\Controllers\PriorityController;
use App\Controllers\SlaController;
use App\Controllers\StatusTicketController;
use App\Controllers\TeknisiController;
use App\Controllers\TicketAssignmentController;
use App\Controllers\TicketController;
use App\Controllers\UserController;
use App\Core\Router;
use App\Middlewares\AuthMiddleware;
use App\Middlewares\GuestMiddleware;
use App\Middlewares\RoleMiddleware;

$router = new Router();

// ===========================
// AUTH
// ===========================

// Guest
$router->get(PATH_URL["LOGIN"], [LoginController::class, "index"], [
  GuestMiddleware::class
]);

$router->post(PATH_URL["LOGIN"], [LoginController::class, "login"], [
  GuestMiddleware::class
]);

// Semua user yang sudah login
$router->get(PATH_URL["LOGOUT"], [LoginController::class, "logout"], [
  AuthMiddleware::class
]);

// ===========================
// USER
// ===========================

$router->get(PATH_URL["INCIDENT"], [CategoryController::class, "incident"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

$router->get(PATH_URL["REQUEST"], [CategoryController::class, "request"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

$router->get(PATH_URL["REQUEST_TIKET"], [HomeController::class, "requestTicket"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

$router->get(PATH_URL["MY_ACTIVITY"], [HomeController::class, "myActivity"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

$router->get(PATH_URL["USER_TIKET_DETAIL"], [HomeController::class, "detailTicket"], [
  AuthMiddleware::class
]);

// ===========================
// DASHBOARD
// ===========================

$router->get(PATH_URL["HOME"], [HomeController::class, "index"], [
  AuthMiddleware::class
]);

$router->get(PATH_URL["ADMIN"], [DashboardController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->get(
  PATH_URL["DASHBOARD"],
  [DashboardController::class, "index"],
  [
    AuthMiddleware::class,
    new RoleMiddleware('ADMIN')
  ]
);

$router->get(PATH_URL["DASHBOARD_SLA"], [DashboardController::class, "sla"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// ===========================
// MANAJEMEN USER
// ===========================

$router->get(PATH_URL["MANAJEMEN_USER"], [UserController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->get(PATH_URL["TAMBAH_USER"], [UserController::class, "createForm"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->get(PATH_URL["DETAIL_USER"], [UserController::class, "updateForm"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->get(PATH_URL["UBAH_PASSWORD"], [UserController::class, "changePasswordForm"], [
  AuthMiddleware::class
]);

$router->post(PATH_URL["TAMBAH_USER"], [UserController::class, "create"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_USER"], [UserController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["UBAH_PASSWORD"], [UserController::class, "changePassword"], [
  AuthMiddleware::class
]);

// ===========================
// PENGATURAN MASTER
// ===========================

// Divisi
$router->get(PATH_URL["PENGATURAN_DIVISI"], [DivisiController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["TAMBAH_DIVISI"], [DivisiController::class, "create"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_DIVISI"], [DivisiController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["HAPUS_DIVISI"], [DivisiController::class, "delete"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// Kategori
$router->get(PATH_URL["PENGATURAN_KATEGORI"], [CategoryController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["TAMBAH_KATEGORI"], [CategoryController::class, "create"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_KATEGORI"], [CategoryController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["HAPUS_KATEGORI"], [CategoryController::class, "delete"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// Prioritas
$router->get(PATH_URL["PENGATURAN_PRIORITAS"], [PriorityController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["INIT_PRIORITAS"], [PriorityController::class, "init"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_PRIORITAS"], [PriorityController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// SLA
$router->get(PATH_URL["PENGATURAN_SLA"], [SlaController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["TAMBAH_SLA"], [SlaController::class, "create"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_SLA"], [SlaController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["HAPUS_SLA"], [SlaController::class, "delete"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// Status Ticket
$router->get(PATH_URL["PENGATURAN_STATUS_TIKET"], [StatusTicketController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["EDIT_STATUS_TIKET"], [StatusTicketController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["HAPUS_STATUS_TIKET"], [StatusTicketController::class, "delete"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["INIT_STATUS_TIKET"], [StatusTicketController::class, "init"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// ===========================
// TIKET
// ===========================

// Semua role boleh melihat daftar tiket
$router->get(PATH_URL["DAFTAR_TIKET"], [TicketController::class, "index"], [
  AuthMiddleware::class
]);

// User membuat tiket
$router->get(PATH_URL["TAMBAH_TIKET"], [TicketController::class, "createForm"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

$router->post(PATH_URL["TAMBAH_TIKET"], [TicketController::class, "create"], [
  AuthMiddleware::class,
  new RoleMiddleware('USER')
]);

// Semua role boleh melihat detail
$router->get(PATH_URL["DETAIL_TIKET"], [TicketController::class, "detail"], [
  AuthMiddleware::class
]);

// Admin boleh edit & hapus tiket
$router->post(PATH_URL["EDIT_TIKET"], [TicketController::class, "update"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

$router->post(PATH_URL["HAPUS_TIKET"], [TicketController::class, "delete"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// admin dapat mengatur sla ticket
$router->post(PATH_URL["UPDATE_SLA_TIKET"], [TicketController::class, "updateSla"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// ===========================
// WORKFLOW
// ===========================

// Teknisi mengubah status
$router->post(PATH_URL["UPDATE_STATUS_TIKET"], [TicketController::class, "updateStatus"], [
  AuthMiddleware::class,
  new RoleMiddleware('TEKNISI', 'ADMIN')
]);

// Admin melakukan assignment
$router->post(PATH_URL["ASSIGN_TIKET"], [TicketAssignmentController::class, "assign"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// Teknisi melakukan eskalasi
$router->post(PATH_URL["ESKALASI_TIKET"], [TicketAssignmentController::class, "escalate"], [
  AuthMiddleware::class,
  new RoleMiddleware('ADMIN')
]);

// ===========================
// KOMENTAR
// ===========================

$router->post(PATH_URL["SUBMIT_KOMENTAR"], [CommentController::class, "store"], [
  AuthMiddleware::class
]);


// TEKNISI
$router->get(PATH_URL["TEKNISI"], [TeknisiController::class, "index"], [
  AuthMiddleware::class,
  new RoleMiddleware('TEKNISI')
]);

// -- display router
$router->dispatch();
