package com.influx;

import com.config.AppProperties;
import com.influxdb.client.WriteOptions;
import com.influxdb.client.domain.WritePrecision;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class InfluxDBConfig {

    private final AppProperties appProperties;

    @Autowired
    public InfluxDBConfig(AppProperties appProperties) {
        this.appProperties = appProperties;
    }

    public WriteOptions getWriteOptions() {
        return WriteOptions.builder()
                .batchSize(appProperties.getInfluxBatchSize())
                .flushInterval(appProperties.getInfluxFlushInterval())
                .jitterInterval(1000)
                .retryInterval(appProperties.getInfluxRetryDelay())
                .build();
    }

    public WritePrecision getWritePrecision() {
        return WritePrecision.MS; // 毫秒精度
    }
}