/*
 *  TnTrafficProtoBufProxy.h
 *
 *  Created by Thant on August 26, 2013.
 *  Copyright 2013 TeleNav. All rights reserved.
 *
 */


#ifndef TN_TRAFFIC_PROTOBUF_PROXY_H
#define TN_TRAFFIC_PROTOBUF_PROXY_H

#include <foundation/SharedPtr.h>
#include <foundation/WeakPtr.h>

#include <RenderEngine/ITnMapResourceProxy.h>
#include <GenericProxy/ITnTrafficProtoBufProxy.h>
#include <foundation/Util/TnPruningMap.h>


class TnTrafficProtoBufProxy :
    public  ITnTrafficProtoBufProxy,
    public boost::enable_shared_from_this<TnTrafficProtoBufProxy>
{
public:

    typedef Tn::Foundation::shared_ptr<TnTrafficProtoBufProxy> ptr;
    typedef Tn::Foundation::weak_ptr<TnTrafficProtoBufProxy> wptr;

    static TnTrafficProtoBufProxy::ptr Create(ITnMapResourceProxy::ptr const &);

    /*  ITnTrafficProtoBufProxy
     *
     */

    virtual bool PrefetchSupported() const;
    virtual void RequestTilePrefetch(TnMapTileId const & id);

    virtual void RequestTile(ITnTrafficProtoBufData::ptr const & data);

    virtual void CancelRequest(ITnTrafficProtoBufData::ptr const & data);

    /*  TnTrafficProtoBufProxy
     *
     */

    void SetBaseURL(std::string const & baseURL);
    void SetPostParameter(std::string const & postParam);

private:

    std::string BuildUrl(TnMapTileId clientTileId, boost::optional<std::string> const & version);

    TnTrafficProtoBufProxy(ITnMapResourceProxy::ptr const &);

    ITnMapResourceProxy::ptr m_resourceProxy;

    typedef TnPruningMap<ITnTrafficProtoBufData::ptr, ITnMapResourceData::wptr> PendingRequests;
    PendingRequests m_pendingRequests;

    std::string m_baseURL, m_postParameter;
};


#endif // TN_TRAFFIC_PROTOBUF_PROXY_H
