<?php
include '../config.php'; // Include database connection

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csv_file_name'])) {
    $csv_file_name = $_POST['csv_file_name'];
    $log->system_debug("Fetching metadata for CSV file: $csv_file_name");
    $query = "SELECT total, valid, invalid, catch_all, unknown, skipped, syntax_error, disposable, free_account, role_account 
              FROM evp_email_list_metadata 
              WHERE csv_file_name = '$csv_file_name'";

    $result = $db->select($query);

    if ($result && $result->num_rows > 0) {
        $data = $result->fetch_assoc();
        echo json_encode(['success' => true, 'data' => $data]);
    } else {
        echo json_encode(['success' => false, 'message' => 'No data found.']);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request.']);
}
?>
