<?php 

// Order
if (! function_exists('shopify_get_orders')) {
    function shopify_get_orders($api_target) {
        $endpoint = config('shopify_api.get_orders');
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_get_order')) {
    function shopify_get_order($api_target, $order_id) {
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.get_specific_order'));
        $url = $api_target.$endpoint;
        
        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_update_order')) {

 
	function shopify_update_order($api_target, $order_id, $body) {
	 
		$endpoint = str_replace('{order_id}', $order_id, config('shopify_api.update_order'));
        $url = $api_target.$endpoint;

        return shopify_put_request($url, $body);
    }
}

if (! function_exists('shopify_update_order_partial')) {
    function shopify_update_order_partial($api_target, $order_id, $body) {
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.update_order'));
        $url = $api_target.$endpoint;

        return shopify_put_request($url, $body);
    }
}

if (! function_exists('shopify_close_order')) {
    function shopify_close_order($api_target, $order_id, $body) {
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.close_order'));
        $url = $api_target.$endpoint;
        
        return shopify_post_request($url, $body);
    }
}

if (! function_exists('shopify_cancel_order')) {
    function shopify_cancel_order($api_target, $order_id, $body) {
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.cancel_order'));
        $url = $api_target.$endpoint;
        
        return shopify_post_request($url, $body);
    }
}

if (! function_exists('shopify_create_transactions')) {
    function shopify_create_transactions($api_target, $order_id, $body) {
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.create_transaction'));
        $url = $api_target.$endpoint;
        
        return shopify_post_request($url, $body);
    }
}

// Smart Collection
if (! function_exists('shopify_get_smart_collections')) {
    function shopify_get_smart_collections($api_target) {
        $endpoint = config('shopify_api.get_smart_collections').'?limit=250';
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_get_smart_collections_by_name')) {
    function shopify_get_smart_collections_by_name($api_target, $title) {
        $endpoint = config('shopify_api.get_smart_collections').'?title='.$title;
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_create_smart_collections')) {
    function shopify_create_smart_collections($api_target, $body) {
        $endpoint = config('shopify_api.create_smart_collections');
        $url = $api_target.$endpoint;
        
        return shopify_post_request($url, $body);
    }
}

// Order Fulfillment
if (! function_exists('shopify_create_fulfillment')) {
    function shopify_create_fulfillment($api_target, $order_id, $body) {

  
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.create_fulfillment'));
        $url = $api_target.$endpoint;

  
        return shopify_post_request($url, $body);
    }
}

//create fulfil2023

if (! function_exists('shopify_create_fulfillmentful')) {
    function shopify_create_fulfillmentful($api_target, $order_id, $body,$tracking, $branddomain,$brandapikey) {
       
        $endpoint = str_replace('{order_id}', $order_id, config('shopify_api.create_fulfillment'));

        $url = $api_target.$endpoint;

        
        return shopify_put_request_full($url, $body,$tracking,$order_id, $branddomain, $brandapikey);
    }
}

// Product
if (! function_exists('shopify_get_products')) {
    function shopify_get_products($api_target, $limit, $since_id) {
        $endpoint = config('shopify_api.get_products').'?limit='.$limit.'&since_id='.$since_id;
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_get_product_by_handle')) {
    function shopify_get_product_by_handle($api_target, $handle) {
        $endpoint = config('shopify_api.get_products').'?handle='.$handle;
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}


if (! function_exists('shopify_get_products_count')) {
    function shopify_get_products_count($api_target) {
        $endpoint = config('shopify_api.get_products_count');
        $url = $api_target.$endpoint;
        
        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_get_product')) {
    function shopify_get_product($api_target, $product_id) {
        $endpoint = str_replace('{product_id}', $product_id, config('shopify_api.get_specific_product'));
        $url = $api_target.$endpoint;
        
        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_update_product')) {
    function shopify_update_product($api_target, $product_id, $body) {
        $endpoint = str_replace('{product_id}', $product_id, config('shopify_api.update_product'));
        $url = $api_target.$endpoint;
        
        return shopify_put_request($url, $body);
    }
}

// Product Images
if (! function_exists('shopify_get_product_images')) {
    function shopify_get_product_images($api_target, $product_id) {
        $endpoint = str_replace('{product_id}', $product_id, config('shopify_api.get_product_images'));
        $url = $api_target.$endpoint;
        
        return shopify_get_request($url);
    }
}

// Product Variant
if (! function_exists('shopify_get_variant')) {
    function shopify_get_variant($api_target, $variant_id) {
        $endpoint = str_replace('{variant_id}', $variant_id, config('shopify_api.get_specific_variant'));
        $url = $api_target.$endpoint;
        
        return shopify_get_request($url);
    }
}

// Theme Asset
if (! function_exists('shopify_get_theme_asset')) {
    function shopify_get_theme_asset($api_target, $theme_id, $asset_name) {
        $endpoint = str_replace('{theme_id}', $theme_id, config('shopify_api.get_theme_asset'));
        $url = $api_target.$endpoint.$asset_name;
        
        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_update_theme_asset')) {
    function shopify_update_theme_asset($api_target, $theme_id, $body) {
        $endpoint = str_replace('{theme_id}', $theme_id, config('shopify_api.update_theme_asset'));
        $url = $api_target.$endpoint;
        
        return shopify_put_request($url, $body);
    }
}

if (! function_exists('shopify_get_orders_count')) {
    function shopify_get_orders_count($api_target) {
        $endpoint = config('shopify_api.get_orders_count');
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

if (! function_exists('shopify_get_orders_today')) {
    function shopify_get_orders_today($api_target, $created_at_max) {
        $endpoint = str_replace('{created_at_max}', $created_at_max, config('shopify_api.get_orders_count_today'));
        $url = $api_target.$endpoint;

        return shopify_get_request($url);
    }
}

?>
