aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillingReporterMock.java
blob: 689ecc356dc76610bb95d255c0e8168ca77aa20f (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
36
37
38
39
40
41
42
43
44
45
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.billing;

import com.yahoo.vespa.hosted.controller.tenant.BillingReference;
import com.yahoo.vespa.hosted.controller.tenant.CloudTenant;

import java.math.BigDecimal;
import java.time.Clock;
import java.time.ZonedDateTime;
import java.util.Optional;
import java.util.UUID;

public class BillingReporterMock implements BillingReporter {
    private final Clock clock;
    private final BillingDatabaseClient dbClient;

    public BillingReporterMock(Clock clock, BillingDatabaseClient dbClient) {
        this.clock = clock;
        this.dbClient = dbClient;
    }

    @Override
    public BillingReference maintainTenant(CloudTenant tenant) {
        return new BillingReference(UUID.randomUUID().toString(), clock.instant());
    }

    @Override
    public InvoiceUpdate maintainInvoice(Bill bill) {
        dbClient.addLineItem(bill.tenant(), maintainedMarkerItem(), Optional.of(bill.id()));
        return new InvoiceUpdate(1,0,0);
    }

    @Override
    public String exportBill(Bill bill, String exportMethod, CloudTenant tenant) {
        // Replace bill with a copy with exportedId set
        var exportedId = "EXT-ID-123";
        dbClient.setExportedInvoiceId(bill.id(), exportedId);
        return exportedId;
    }

    private static Bill.LineItem maintainedMarkerItem() {
        return new Bill.LineItem("maintained", "", BigDecimal.valueOf(0.0), "", "", ZonedDateTime.now());
    }

}