%%%-------------------------------------------------------------------
%%% @author aresei
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 04. 7月 2023 11:30
%%%-------------------------------------------------------------------
-module(iot_router).
-author("aresei").
-include("iot.hrl").

%% API
-export([route_uuid/3]).

-spec route_uuid(RouterUUID :: binary(), Fields :: list(), Timestamp :: integer()) -> no_return().
route_uuid(RouterUUID, Fields, Timestamp) when is_binary(RouterUUID), is_list(Fields), is_integer(Timestamp) ->
    %% 查找终端设备对应的点位信息
    case redis_client:hgetall(RouterUUID) of
        {ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) ->
            iot_zd_endpoint:forward(LocationCode, DynamicLocationCode, Fields, Timestamp);
        {ok, _} ->
            lager:warning("[iot_host] the north_data hget location_code, uuid: ~p, not found, fields: ~p", [RouterUUID, Fields]);
        {error, Reason} ->
            lager:warning("[iot_host] the north_data hget location_code uuid: ~p, get error: ~p, fields: ~p", [RouterUUID, Reason, Fields])
    end.