#ifndef __TNURL_H__
#define __TNURL_H__

#include <iostream>
#include <string>
#include <vector>
#include "foundation/SharedPtr.h"
#include "TnUrl/AbstractUrl.h"

class TnUrl
{
public:
    // Shared ptr
    typedef Tn::Foundation::shared_ptr<TnUrl> ptr;

    // Deprecated. Do not use anymore.
    static void Initialize();
    static void Shutdown();

    // Construction / copy-construction / assignment
    TnUrl();
    ~TnUrl();
    TnUrl(TnUrl const & other); // Deprecated. Do not use any more
    TnUrl & operator=(TnUrl const & other);
    
    // Return code for HTTP request
    enum ErrorCode
    {
        OK,                 // No error
        UNSUPPORTED,        // URL requests not built into lib
        FAILED,             // General failure to set up request
        CANCELED,           // Canceled by the caller using Cancel()
        COULDNT_CONNECT,    // Could not connect to the server
        HTTP_ERROR,         // Connection succeeded, but HTTP error > 400 returned
        UNSPECIFIED,         // Other, unspecified error
        PARTIAL_FILE         // Warning code
    };
    
    // GET to container
    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());

	// POST from container
	ErrorCode Post(std::string const & url, std::vector<char> const & postData, std::vector<char>& body, std::vector<std::string> & headers);

	// POST for http chunk response
	ErrorCode Post(std::string const & url, std::vector<char> const & postData, ReadHttpChunkListener& listener,std::vector<std::string> & headers);

	// POST for http chunk request
	ErrorCode Post(std::string const & url, WriteHttpChunkListener& listener, std::vector<char>& body,std::vector<std::string> & headers);

	//Set Proxy
	ErrorCode SetProxyConfiguration(const std::string& url, int port, const std::string& username = "", const std::string& password = "");

	//Disable Proxy
	ErrorCode ClearProxyConfiguration();
    
    // Cancel any operation mid-stream
    void Cancel();
    
    // Get the response code returned from the last successful transfer
    ErrorCode ResponseCode(long & code) const;

	std::string EffectiveURL() const;

	int GetCreatedTimeStamp() const;
    
private:    
    
    Tn::Foundation::shared_ptr<Tn::Url::AbstractUrl> m_pUrl;
    
private:

	int m_timeStamp;
    
};

// Convert a TnUrl::ErrorCode to a string
std::ostream & operator<<(std::ostream & out, TnUrl::ErrorCode const & errorCode);

#endif

