<?php

require_once '../../core/api_bootstrap.php';
require_once '../../core/employee_auth.php';

EmployeeAuth::check('manage_employees');

try {

$db = new Database();
$conn = $db->connect();

$stmt = $conn->prepare("

SELECT
e.id,
e.name,
e.email,
e.phone,
e.status,
e.last_login,
r.name AS role,
e.created_at

FROM employees e

LEFT JOIN roles r
ON e.role_id = r.id

ORDER BY e.id DESC

");

$stmt->execute();

$employees = $stmt->fetchAll();

Response::success($employees);

}
catch(Exception $e){

Logger::log("system.log",$e->getMessage());

Response::error("Server error",500);

}
