<?php


namespace ABR\Api;




class abrestan_api
{
    public function apiRequest($method, $data = array())
    {
        if ($method == null) {
            return false;
        }

        $endpoint = 'https://kasb.abrestan.com/webservice/v1/' . $method;

        $body = array_merge(
            [
                'token' => get_option('abrestan_login')['token'] ? get_option('abrestan_login')['token'] : ''
            ]
            , $data);
        $options = array(
            'body' => $body,
            'timeout' => 60,
            'redirection' => 5,
            'blocking' => true,
            'httpversion' => '1.0',
            'sslverify' => false,
            'data_format' => 'body',
        );
            $wp_remote_post = wp_remote_post($endpoint, $options);
            return $wp_remote_post;
    }
    public function Login($Data)
    {
        $method = 'login';
        return $this->apiRequest($method, $Data);
    }
    public function SyncProduct($Data)
    {
        $method = 'import/commodities/or/persons';
        return $this->apiRequest($method, $Data);
    }
    public function SelectCompany($Data)
    {
        $method = 'set/domain';
        return $this->apiRequest($method, $Data);
    }
    public function SyncUser($Data)
    {
        $method = 'import/commodities/or/persons';
        return $this->apiRequest($method, $Data);
    }
    public function SyncOrder($Data)
    {
        $method = 'insert/sale/factor';
        return $this->apiRequest($method, $Data);
    }
    public function DeleteOrder($Data)
    {
        $method = 'delete/sale/factor';
        return $this->apiRequest($method, $Data);
    }
}