package com.lingniu.ingest.inbound.mqtt.profile;

import com.lingniu.ingest.api.event.VehicleEvent;
import com.lingniu.ingest.inbound.mqtt.mapper.YutongEventMapper;
import com.lingniu.ingest.inbound.mqtt.model.MqttPayload;
import com.lingniu.ingest.inbound.mqtt.parser.MqttPayloadParser;

import java.util.List;

public final class YutongMqttProfile implements MqttProfile {

    public static final String NAME = "yutong";

    private final MqttPayloadParser parser;
    private final YutongEventMapper mapper;

    public YutongMqttProfile(MqttPayloadParser parser, YutongEventMapper mapper) {
        this.parser = parser;
        this.mapper = mapper;
    }

    @Override
    public String name() {
        return NAME;
    }

    @Override
    public MqttPayload parse(String endpointName, String topic, byte[] bytes) {
        return parser.parse(endpointName, NAME, topic, bytes);
    }

    @Override
    public List<VehicleEvent> toEvents(MqttPayload payload) {
        return mapper.toEvents(payload);
    }
}
