<?php
$response = (object)[];
if (!empty($_GET)) {
    require_once __DIR__ . '/../connection/SqlServer.php';

    $db = new connection();
    $db->SERVER_11_2();

    $query = "SELECT poligono,nCasa from visitas.view_casas where sucursal = :sucursal and cluster = :cluster;";
    $stmt = $db->conexion->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED]);
    $stmt->bindParam(':sucursal', $_GET['sucursal'], PDO::PARAM_INT);
    $stmt->bindParam(':cluster', $_GET['cluster'], PDO::PARAM_INT);

    try {
        $stmt->execute();
        $response->status = 200;
        $response->message = 'EXITO';
        $response->data = $stmt->fetchAll(PDO::FETCH_OBJ);
    } catch (PDOException $e) {
        $response->status = 500;
        $response->message = $e->getMessage();
    } finally {
        $db->conexion = null;
    }
}

echo json_encode($response);
