<?php

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

EmployeeAuth::check('manage_employees');

$data = Request::get();

try {

Validator::required($data,['id']);

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

$stmt = $conn->prepare("

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

FROM employees e

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

WHERE e.id=:id

LIMIT 1

");

$stmt->execute([
':id'=>$data['id']
]);

$employee = $stmt->fetch();

Response::success($employee);

}
catch(Exception $e){

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

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

}
