<?php
include '../db.php';

header('Content-Type: application/json');

if (!isset($_GET['id'])) {
    echo json_encode(['success' => false, 'message' => 'Mapping ID is required']);
    exit;
}

$mapping_id = intval($_GET['id']);

$stmt = $conn->prepare("
    SELECT 
        am.*,
        coa.account_code,
        coa.account_name,
        coa.account_type,
        coa.account_category
    FROM account_mappings am
    LEFT JOIN chart_of_accounts coa ON am.account_id = coa.id
    WHERE am.id = ?
");

$stmt->bind_param("i", $mapping_id);
$stmt->execute();
$result = $stmt->get_result();

if ($mapping = $result->fetch_assoc()) {
    echo json_encode([
        'success' => true,
        'mapping' => $mapping
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Mapping not found'
    ]);
}
?>
