
<?php

require_once __DIR__ . '/../config/constants.php';

class Logger
{

    /**
     * Basic file logger
     */
    public static function log($file, $message)
    {
        $path = LOG_PATH . $file;

        if (!file_exists($path)) {
            touch($path);
        }

        $entry = "[" . date("Y-m-d H:i:s") . "] " . $message . PHP_EOL;

        file_put_contents($path, $entry, FILE_APPEND);
    }



    /**
     * Activity logger (for employees)
     */
    public static function activity($employee_id, $action, $module, $reference_id = null, $ip = null)
    {
        $path = LOG_PATH . "activity.log";

        if (!file_exists($path)) {
            touch($path);
        }

        $entry = [
            "time" => date("Y-m-d H:i:s"),
            "employee_id" => $employee_id,
            "action" => $action,
            "module" => $module,
            "reference_id" => $reference_id,
            "ip" => $ip
        ];

        file_put_contents(
            $path,
            json_encode($entry) . PHP_EOL,
            FILE_APPEND
        );
    }

}