package com.bbva.arq.devops.ae.mirrorgate.model;

import java.time.temporal.ChronoUnit;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "historic_user_metrics")
public class HistoricUserMetric extends BaseModel{

    @Indexed
    private String identifier;

    private String viewId;

    private String appVersion;

    private String platform;

    @Indexed
    private String name;

    private Double value;

    private Double sampleSize;

    @Indexed
    private Long timestamp;

    /* Associated collector ID */
    private String collectorId;

    @Indexed
    private ChronoUnit historicType;

    public String getIdentifier() {
        return identifier;
    }

    public HistoricUserMetric setIdentifier(String identifier) {
        this.identifier = identifier;
        return this;
    }

    public String getViewId() {
        return viewId;
    }

    public HistoricUserMetric setViewId(String viewId) {
        this.viewId = viewId;
        return this;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public HistoricUserMetric setAppVersion(String appVersion) {
        this.appVersion = appVersion;
        return this;
    }

    public String getPlatform() {
        return platform;
    }

    public HistoricUserMetric setPlatform(String platform) {
        this.platform = platform;
        return this;
    }

    public String getName() {
        return name;
    }

    public HistoricUserMetric setName(String name) {
        this.name = name;
        return this;
    }

    public Double getValue() {
        return value;
    }

    public HistoricUserMetric setValue(Double value) {
        this.value = value;
        return this;
    }

    public Double getSampleSize() {
        return sampleSize;
    }

    public HistoricUserMetric setSampleSize(Double sampleSize) {
        this.sampleSize = sampleSize;
        return this;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public HistoricUserMetric setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
        return this;
    }

    public String getCollectorId() {
        return collectorId;
    }

    public HistoricUserMetric setCollectorId(String collectorId) {
        this.collectorId = collectorId;
        return this;
    }

    public ChronoUnit getHistoricType() {
        return historicType;
    }

    public HistoricUserMetric setHistoricType(ChronoUnit historicType) {
        this.historicType = historicType;
        return this;
    }
}

@@ -81,16 +81,82 @@
 noUnit;%0A
+import org.springframework.data.mongodb.core.index.CompoundIndex;%0A
 import o
@@ -319,16 +319,137 @@
 trics%22)%0A
+@CompoundIndex(name = %22average_index%22, def = %22%7B'viewId' : 1, 'name': 1, 'value': 1, 'historicType': 1, 'timestamp': 1%7D%22)%0A
 public c

add compound index