/*
 *  TnGenericLandmarkProxy.h
 *
 *  Created by jianhuang on 7/22/11.
 *  Copyright 2011 TeleNav. All rights reserved.
 *
 */

#ifndef TN_GENERIC_LANDMARK_PROXY_H
#define TN_GENERIC_LANDMARK_PROXY_H

#include <RenderEngine/ITnMapLandmarkProxy.h>
#include <RenderEngine/ITnMapResourceProxy.h>
#include <RenderEngine/TnMapResourceData.h>
#include <foundation/Util/TnPruningMap.h>
#include <GenericProxy/TnBuildingModelProto.pb.h>


class TnMapLandmarkBlockData : public TnMapResourceData
{
public:
    typedef Tn::Foundation::weak_ptr<TnMapLandmarkBlockData> wptr;
    typedef Tn::Foundation::shared_ptr<TnMapLandmarkBlockData> ptr;

    TnMapLandmarkBlockData(std::string baseUrl, std::string url, int32_t zoom, int32_t x, int32_t y);
    
    virtual ~TnMapLandmarkBlockData();

    void AddDataImpl(TnMapLandmarkData::ptr data);

    void RemoveDataImpl(TnMapLandmarkData::ptr data);

    int32_t DadaImplSize();

    void SetResult(eTnMapRequestResult result);

    static int64_t LandmarkId(int32_t zoom, int32_t x, int32_t y, int32_t index);

    int64_t CreateModels(TnBuildingModelProto::BuildingBlock & block);

    virtual void SetRequestResult(eTnMapRequestResult result);

protected:

    std::string m_baseUrl;
    int32_t m_zoom;
    int32_t m_x;
    int32_t m_y;
    std::vector<TnMapLandmarkData::ptr> m_vecData;
    Tn::Foundation::mutex m_mutex;
};


class TnGenericLandmarkProxy : public ITnMapLandmarkProxy
{

public:
    typedef Tn::Foundation::shared_ptr<TnGenericLandmarkProxy> ptr;
    
    TnGenericLandmarkProxy(ITnMapResourceProxy::ptr proxy);

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

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

    virtual void SetLandmarkBaseURL(std::string const & url);

    /*  We want CityScape to use its own cache independent of the
     *  default tile cache. (Do we want this to be setable?)
     */
    static std::string const & DefaultCacheName();


private:

    static std::string const s_cacheName;

    std::string BuildIndexUrl(TnMapTileId& idTile) const;

    std::string BuildBlockUrl(int32_t zoom, int32_t x, int32_t y) const;

protected:

    ITnMapResourceProxy::ptr    m_resProxy;
    std::string                 m_strUrl;

    TnPruningMap<std::string, TnMapLandmarkBlockData::wptr> m_mapBlock;
};

#endif
