package com.lingniu.ingest.protocol.jt1078.handler;

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 com.lingniu.ingest.protocol.jt1078.model.Jt1078MessageId;
import com.lingniu.ingest.protocol.jt808.mapper.Jt808EventMapper;
import com.lingniu.ingest.protocol.jt808.model.Jt808Message;

import java.util.List;

/**
 * JT/T 1078 信令复用 JT808 包头、连接与 dispatcher，但路由独立放在 1078 模块内。
 */
@ProtocolHandler(protocol = ProtocolId.JT808)
public final class Jt1078MediaSignalHandler {

    private final Jt808EventMapper mapper;

    public Jt1078MediaSignalHandler(Jt808EventMapper mapper) {
        this.mapper = mapper;
    }

    @MessageMapping(command = {
            Jt1078MessageId.TERMINAL_MEDIA_ATTRS_REPORT,
            Jt1078MessageId.TERMINAL_PASSENGER_VOLUME,
            Jt1078MessageId.TERMINAL_FILE_LIST,
            Jt1078MessageId.TERMINAL_FILE_UPLOAD_DONE
    }, desc = "JT/T 1078 音视频信令")
    @EventEmit({VehicleEvent.MediaMeta.class, VehicleEvent.Passthrough.class})
    public List<VehicleEvent> onMediaSignal(Jt808Message msg) {
        return mapper.toEvents(msg);
    }
}
