summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/StatusHistory.java
blob: 6335ada13968003ed5d533e9afe16bf7225b3202 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.yahoo.vespa.hosted.controller.api.integration.billing;

import java.time.Clock;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @author ogronnesby
 */
public class StatusHistory {
    SortedMap<ZonedDateTime, BillStatus> history;

    public StatusHistory(SortedMap<ZonedDateTime, BillStatus> history) {
        this.history = history;
    }

    public static StatusHistory open(Clock clock) {
        var now = clock.instant().atZone(ZoneOffset.UTC);
        return new StatusHistory(
                new TreeMap<>(Map.of(now, BillStatus.OPEN))
        );
    }

    public BillStatus current() {
        return history.get(history.lastKey());
    }

    public SortedMap<ZonedDateTime, BillStatus> getHistory() {
        return history;
    }

}