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

%% API
-export([batch_route_uuid/2]).

-spec batch_route_uuid(RouterUUID :: binary(), Events :: list()) -> no_return().
batch_route_uuid(RouterUUID, Events) when is_binary(RouterUUID), is_list(Events) ->
    %% 查找终端设备对应的点位信息
    case redis_client:hgetall(RouterUUID) of
        {ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) ->
            iot_jinzhi_endpoint:batch_forward(LocationCode, DynamicLocationCode, Events);
        {ok, _} ->
            lager:debug("[iot_ai_router] the event_data hget location_code, uuid: ~p, not found", [RouterUUID]);
        {error, Reason} ->
            lager:debug("[iot_ai_router] the event_data hget location_code uuid: ~p, get error: ~p", [RouterUUID, Reason])
    end.