<?php

include_once 'inc/functions.php';
include_once 'inc/database.php';
	
include_once 'requestFunctions.php';

	
require_once __DIR__ . '/vendor/autoload.php';
use Bigcommerce\Api\Client as Bigcommerce;

if(isset($_POST["promotions_ids"]) && !empty($_POST["promotions_ids"]))
{
	
    $promotions_id=implode(",",$_POST["promotions_ids"]);
    $Store_hash=$_POST['store_hash'];
    $store_access_token= $db->getSingleColumn( "stores", "access_token", array( "store_id" =>$Store_hash));

    $url = "https://api.bigcommerce.com/stores/".$Store_hash."/v3/promotions?id:in=$promotions_id";

		$headers = array(
			"accept: application/json",
			"content-type: application/json",
			"x-auth-client: ".CLIENT_ID,
			"x-auth-token: ".$store_access_token
		);

	$big_promotion_del_res= curlDeleteRequest($url, $headers);
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

	if($httpCode==422)
	{
		 echo json_encode(["msg"=>"Promtions Not Deleted Try Again"]);
	}
	else{
		 echo json_encode(["msg"=>"Promtions Deleted Successfully"]);

	}

}

?>