]> git.basschouten.com Git - openhab-addons.git/blob
6023e255271042d5ba2a4ea512206dd4718aee33
[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 Integer qosUsageQuota;
44     private Integer qosRateMaxUp;
45     private Integer qosRateMaxDown;
46     private boolean qosOverwrite;
47     private String note;
48     private String status;
49
50     public UniFiVoucher(final UniFiControllerCache cache) {
51         this.cache = cache;
52     }
53
54     @Override
55     public String getId() {
56         return id;
57     }
58
59     public String getCode() {
60         return code;
61     }
62
63     public Instant getCreateTime() {
64         return createTime;
65     }
66
67     public Integer getDuration() {
68         return duration;
69     }
70
71     public Integer getQuota() {
72         return quota;
73     }
74
75     public Integer getUsed() {
76         return used;
77     }
78
79     public Integer getQosUsageQuota() {
80         return qosUsageQuota;
81     }
82
83     public Integer getQosRateMaxUp() {
84         return qosRateMaxUp;
85     }
86
87     public Integer getQosRateMaxDown() {
88         return qosRateMaxDown;
89     }
90
91     public boolean isQosOverwrite() {
92         return qosOverwrite;
93     }
94
95     public String getNote() {
96         return note;
97     }
98
99     public String getStatus() {
100         return status;
101     }
102
103     public UniFiSite getSite() {
104         return cache.getSite(siteId);
105     }
106
107     @Override
108     public String toString() {
109         return String.format(
110                 """
111                         UniFiVoucher{id: '%s', code: '%s', created: '%s', duration: '%s', quota: '%s', used: '%s', qosUsageQuota: '%s', \
112                         qosRateMaxUp: '%s', qosRateMaxDown: '%s', qosOverwrite: '%s', note: '%s', status: '%s', site: %s}\
113                         """,
114                 id, code, createTime, duration, quota, used, qosUsageQuota, qosRateMaxUp, qosRateMaxDown, qosOverwrite,
115                 note, status, getSite());
116     }
117 }