//
//  AbstractUrlExecutor.h
//  TelenavNavigator
//
//  Created by Shengxiong, Xia on 9/18/12.
//  Copyright (c) 2012 Telenav, Inc. All rights reserved.
//

#ifndef TelenavNavigator_AbstractUrl_h
#define TelenavNavigator_AbstractUrl_h

#include "HttpChunkListener.h"
#include <vector>
#include <string>
#include <time.h>

namespace Tn 
{
    namespace Url
    {
        // Return code for HTTP request
        enum ErrorCode
        {
            ErrorCode_OK,                 // No error
            ErrorCode_UNSUPPORTED,        // URL requests not built into lib
            ErrorCode_FAILED,             // General failure to set up request
            ErrorCode_CANCELED,           // Canceled by the caller using Cancel()
            ErrorCode_COULDNT_CONNECT,    // Could not connect to the server
            ErrorCode_HTTP_ERROR,         // Connection succeeded, but HTTP error > 400 returned
            ErrorCode_UNSPECIFIED,        // Other, unspecified error
            ErrorCode_PARTIAL_FILE        // Warning code : CURLE_PARTIAL_FILE. For download resource file from CDN, ignore it
        };
        
        class AbstractUrl
        {
        public:
            
            virtual ~AbstractUrl() {};
            
            // GET to container
            virtual ErrorCode Get(std::string const & url, std::vector<char>& body, std::vector<std::string> & headers, time_t ifmodifiedsince=0, std::string const & rangeString=std::string()) = 0;
            
            // POST from container
            virtual ErrorCode Post(std::string const & url, std::vector<char> const & postData, std::vector<char>& body, std::vector<std::string> & headers) = 0;
            
            // POST for http chunk response
            virtual ErrorCode Post(std::string const & url, std::vector<char> const & postData, ReadHttpChunkListener& listener,std::vector<std::string> & headers) = 0;
            
            // POST for http chunk request
            virtual ErrorCode Post(std::string const & url, WriteHttpChunkListener& listener, std::vector<char>& body,std::vector<std::string> & headers) = 0;
            
            //Set Proxy
            virtual ErrorCode SetProxyConfiguration(const std::string& url, int port, const std::string& username = "", const std::string& password = "") = 0;
            
            //Disable Proxy
            virtual ErrorCode ClearProxyConfiguration() = 0;
            
            // Cancel any operation mid-stream
            virtual void Cancel() = 0;
            
            // Get the response code returned from the last successful transfer
            virtual ErrorCode ResponseCode(long & code) const = 0;
            
            virtual std::string EffectiveURL() const = 0;

        };
    }
}

#endif
