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

import com.lingniu.ingest.protocol.jt1078.handler.Jt1078MediaSignalHandler;
import com.lingniu.ingest.protocol.jt808.config.Jt808AutoConfiguration;
import com.lingniu.ingest.protocol.jt808.mapper.Jt808EventMapper;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * 1078 信令复用 JT808 解码和 mapper，必须在 JT808 AutoConfiguration 之后判断。
 */
@AutoConfiguration(after = Jt808AutoConfiguration.class)
@ConditionalOnProperty(prefix = "lingniu.ingest.jt1078", name = "enabled", havingValue = "true")
@ConditionalOnBean(Jt808EventMapper.class)
public class Jt1078SignalAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public Jt1078MediaSignalHandler jt1078MediaSignalHandler(Jt808EventMapper mapper) {
        return new Jt1078MediaSignalHandler(mapper);
    }
}
