<?php
declare(strict_types=1);

require_once __DIR__ . '/../../security/auth_guard.php';
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../core/Response.php';

$db = Database::getInstance();

$stmt = $db->prepare("
    SELECT 
        e.id,
        e.first_name,
        e.last_name,
        e.email,
        e.mobile,
        e.status,
        e.last_login_at,
        e.created_at,
        e.updated_at,
        r.id   AS role_id,
        r.name AS role_name,
        r.level AS role_level
    FROM employees e
    JOIN roles r ON r.id = e.role_id
    WHERE e.id = :employee_id
    LIMIT 1
");

$stmt->execute([
    'employee_id' => $_SESSION['employee_id']
]);

$employee = $stmt->fetch();

if (!$employee) {
    Response::error('Employee not found', 404);
}

Response::success('Employee profile fetched successfully', [
    'employee' => $employee
]);
