<?php
    include "../db/headerApi.php";
    include "../db/connection_main.php";

    $json = file_get_contents('php://input');
    $data = json_decode($json);

    $sql = "SELECT DISTINCT a.brand id, a.brand text
              FROM apps.YTY_ITEM_MAPPING_SKUSIZEBRAND_V a
             WHERE a.sku = :sku
               AND a.p_size = :siz
          ORDER BY brand";

    $sqlarr = oci_parse($dbcon , $sql);
    oci_bind_by_name($sqlarr, ':sku', $data->sku->ID);
    oci_bind_by_name($sqlarr, ':siz', $data->siz->ID);
    $r = oci_execute($sqlarr);
    $resMsg = "OK";

    if (!$r) {
         $e = oci_error($sqlarr);
         $resMsg = json_encode($e['message']);
    }
    oci_fetch_all($sqlarr, $rows_main, null, null, OCI_FETCHSTATEMENT_BY_ROW);

    $result[] = [
        "message" => $resMsg,
        "data" => $rows_main
    ];

    print json_encode($result);
?>