package com.lingniu.ingest.inbound.xinda;

import com.lingniu.ingest.api.ProtocolId;
import com.lingniu.ingest.api.annotation.EventEmit;
import com.lingniu.ingest.api.annotation.MessageMapping;
import com.lingniu.ingest.api.annotation.ProtocolHandler;
import com.lingniu.ingest.api.event.VehicleEvent;

import java.util.List;

@ProtocolHandler(protocol = ProtocolId.XINDA_PUSH)
public final class XindaPushRealtimeHandler {

    private final XindaPushEventMapper mapper;

    public XindaPushRealtimeHandler(XindaPushEventMapper mapper) {
        this.mapper = mapper;
    }

    @MessageMapping(command = 0x0200, desc = "信达定位")
    @EventEmit(VehicleEvent.Location.class)
    public List<VehicleEvent> onLocation(XindaPushMessage message) {
        return mapper.toEvents(message);
    }

    @MessageMapping(command = 0x0300, desc = "信达报警")
    @EventEmit(VehicleEvent.Alarm.class)
    public List<VehicleEvent> onAlarm(XindaPushMessage message) {
        return mapper.toEvents(message);
    }

    @MessageMapping(desc = "信达透传/未知业务消息兜底")
    @EventEmit(VehicleEvent.Passthrough.class)
    public List<VehicleEvent> onPassthrough(XindaPushMessage message) {
        return mapper.toEvents(message);
    }
}
