<?php

class Operation extends CurlRequest 
{
    
    private $envirounment;
    private $authentication;
    private $header;

    
    public function __construct(Environment $envirounment, Authentication $authentication){

        $this->envirounment = $envirounment;
        $this->authentication = $authentication;
        $this->header = [
            'Content-Type: application/json',
            'Accept: application/json',
            'Authorization: Bearer '.$authentication->getToken()
        ];        
          
    }

    public function createOrder(Order $order){
        
        $urlrequest = $this->envirounment->getApiUrl().'v1/orders';
        $jsonsend   = json_encode($order);
        $requestResult = parent::callAPI($urlrequest,'POST',$jsonsend,$this->header,false,$retorno);
        return json_encode($requestResult);

    }

    public function getOrderStatus($order_id){
        
        $urlrequest = $this->envirounment->getApiUrl().'v1/orders/'.$order_id.'/status';
        $requestResult = parent::callAPI($urlrequest,'GET',false,$this->header,false,$retorno);
        return json_encode($requestResult);

    }

    public function setOrderStatus($order_id,$status){

        $jsonsend = json_encode(array("status" => $status));
        $urlrequest = $this->envirounment->getApiUrl().'v1/orders/'.$order_id.'/status';
        $requestResult = parent::callAPI($urlrequest,'PUT',$jsonsend,$this->header,false,$retorno);
        return json_encode($requestResult);

    }    

}