package org.codiki.metrics;

import org.codiki.core.entities.dto.Metrics;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.Clock;
import java.time.LocalDateTime;

@Service
public class MetricsService {
    /** Application start date. */
    private LocalDateTime uptime;
    /** Application version number. */
    private String appVersion;
    /** Platform name. */
    private String appPlatform;

    /**
     * Constructor.
     * @param clock System clock.
     */
    public MetricsService(Clock clock,
                          @Value("${app.version}") String appVersion,
                          @Value("${app.platform}") String appPlatform) {
        uptime = LocalDateTime.now(clock);
        this.appVersion = appVersion;
        this.appPlatform = appPlatform;
    }

    /**
     * Returns application metrics like uptime, version number or platform name and others.
     * @return Application metrics.
     */
    public Metrics getMetrics() {
        Metrics metrics = new Metrics();

        metrics.setUptime(uptime);
        metrics.setVersion(appVersion);
        metrics.setPlatform(appPlatform);

        return metrics;
    }
}
