<?php
// includes/logger.php

class Logger {

    // 1. Log de Login (Sucesso ou Falha)
    public static function login($pdo, $user_id, $status, $ip) {
        try {
            // type = 'admin' ou 'reseller' (pode ajustar conforme sua lógica)
            $sql = "INSERT INTO login_logs (type, user_id, status, login_ip, date) VALUES (?, ?, ?, ?, ?)";
            $stmt = $pdo->prepare($sql);
            $stmt->execute(['admin', $user_id, $status, $ip, time()]);
        } catch (Exception $e) {}
    }

    // 2. Log de Créditos (Quando adiciona ou remove)
    public static function credit($pdo, $admin_id, $target_id, $amount, $reason) {
        try {
            $sql = "INSERT INTO credits_log (admin_id, target_id, amount, date, reason) VALUES (?, ?, ?, ?, ?)";
            $stmt = $pdo->prepare($sql);
            $stmt->execute([$admin_id, $target_id, $amount, time(), $reason]);
        } catch (Exception $e) {}
    }

    // 3. Log de Ações do Usuário (Criar user, Deletar, Editar)
    public static function userAction($pdo, $owner, $action, $description) {
        try {
            // Tabela users_logs (adaptada para seu uso)
            $sql = "INSERT INTO users_logs (owner, action, deleted_info, date) VALUES (?, ?, ?, ?)";
            $stmt = $pdo->prepare($sql);
            $stmt->execute([$owner, $action, $description, time()]);
        } catch (Exception $e) {}
    }
}
?>
