/*
 *  TnProtoBufToTrafficData.h
 *
 *  Created by Thant on July 15, 2013.
 *  Copyright 2013 TeleNav. All rights reserved.
 *
 *  http://spaces.telenav.com:8080/display/eng/VectorData+Proxy+Refactor+Proposal
 *
 *  This is a version of the proxy that also supports Traffic Speed
 *  Indicators.
 */

#ifndef TN_PROTOBUF_TRAFFIC_DATA_TSI_H
#define TN_PROTOBUF_TRAFFIC_DATA_TSI_H

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

#include <foundation/TnTypes.h>

#include <RenderEngine/TnMapTrafficData.h>
#include <GenericProxy/ITnTrafficProtoBufData.h>
#include <GenericProxy/TnTrafficID2LatLon.h>
#include <GenericProxy/TnTrafficSpeedIcon.h>

class TnProtoBufToTrafficDataTSI : public ITnTrafficProtoBufData
{
public:

    virtual void SetTrafficData(ProtoBufPtr const &);
    virtual void SetRequestResult(eTnMapRequestResult);

    virtual TnMapTileId const & GetTileId() const;

    TnProtoBufToTrafficDataTSI(TnMapTrafficData::ptr const &,
                               TnTrafficID2LatLon::ptr const &,
                               eTnSpeedUnits,
                               double tsi_threshold,
                               uint32_t tsi_count);

private:

    static void Decode(ProtoBufPtr const & from,
                       TnMapTrafficData::ptr const & to,
                       TnTrafficID2LatLon::ptr const &,
                       eTnSpeedUnits,
                       double tsi_threshold,
                       uint32_t tsi_count);

    static void DecodeFlow(ProtoBufPtr const & from,
                           TnMapTrafficData::ptr const & to,
                           TnTrafficID2LatLon::ptr const &,
                           eTnSpeedUnits,
                           double tsi_threshold,
                           uint32_t tsi_count);

    static void DecodeIncidents(ProtoBufPtr const & from,
                                TnMapTrafficData::ptr const & to);


    static void DecodeIncident(TnMapTrafficData::ptr const & annotationData,
                               double incidentLat,
                               double incidentLon,
                               std::string const & incidentType,
                               int32_t severity,
                               int32_t laneClosed,
                               std::string const & message,
                               std::string const & crossStreet1,
                               std::string const & crossStreet2);

    static void AddTrafficSpeedIcon(TnMapTrafficData::ptr const & annotationData,
                                    TnTrafficSpeedIcon const & tsi,
                                    eTnSpeedUnits);
    
    static const char* SeverityToStyle(int32_t severity);

    static uint32_t convertSpeed(double meters_per_second, eTnSpeedUnits units);

    TnMapTrafficData::ptr m_data;
    ProtoBufPtr m_protoBuf;
    TnMapTileId m_tileId;
    TnTrafficID2LatLon::ptr m_tid2LatLon;
    eTnSpeedUnits m_units;
    double m_tsi_threshold;
    uint32_t m_tsi_count;
};


#endif // TN_PROTOBUF_TRAFFIC_DATA_H
