]> git.basschouten.com Git - openhab-addons.git/blob
5a62f6e2b75649467662787759e10b4cfd0b50a9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.unifi.internal.api.dto;
14
15 import java.time.Instant;
16
17 import org.openhab.binding.unifi.internal.api.cache.UniFiControllerCache;
18 import org.openhab.binding.unifi.internal.api.util.UniFiTimestampDeserializer;
19
20 import com.google.gson.annotations.JsonAdapter;
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * The {@link UniFiVoucher} is the base data model for a guest network voucher
25  *
26  * @author Mark Herwege - Initial contribution
27  */
28 public class UniFiVoucher implements HasId {
29
30     private final transient UniFiControllerCache cache;
31
32     @SerializedName("_id")
33     private String id;
34
35     private String siteId;
36
37     private String code;
38     @JsonAdapter(UniFiTimestampDeserializer.class)
39     private Instant createTime;
40     private Integer duration;
41     private Integer quota;
42     private Integer used;
43     private boolean qosOverwrite;
44     private Integer qosUsageQuota;
45     private String status;
46
47     public UniFiVoucher(final UniFiControllerCache cache) {
48         this.cache = cache;
49     }
50
51     @Override
52     public String getId() {
53         return id;
54     }
55
56     public String getCode() {
57         return code;
58     }
59
60     public Instant getCreateTime() {
61         return createTime;
62     }
63
64     public Integer getDuration() {
65         return duration;
66     }
67
68     public Integer getQuota() {
69         return quota;
70     }
71
72     public Integer getUsed() {
73         return used;
74     }
75
76     public boolean isQosOverwrite() {
77         return qosOverwrite;
78     }
79
80     public Integer getQosUsageQuota() {
81         return qosUsageQuota;
82     }
83
84     public String getStatus() {
85         return status;
86     }
87
88     public UniFiSite getSite() {
89         return cache.getSite(siteId);
90     }
91
92     @Override
93     public String toString() {
94         return String.format(
95                 "UniFiVoucher{id: '%s', code: '%s', created: '%s', duration: '%s', quota: '%s', used: '%s', qosUsageQuota: '%s', status: '%s', site: %s}",
96                 id, code, createTime, duration, quota, used, qosUsageQuota, status, getSite());
97     }
98 }