1111import com .fasterxml .jackson .annotation .JsonInclude ;
1212import com .fasterxml .jackson .annotation .JsonProperty ;
1313import com .fasterxml .jackson .annotation .JsonSetter ;
14+ import com .fasterxml .jackson .annotation .Nulls ;
1415import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
1516import so .trophy .core .ObjectMappers ;
1617import java .lang .Object ;
1718import java .lang .String ;
1819import java .util .HashMap ;
1920import java .util .Map ;
2021import java .util .Objects ;
22+ import java .util .Optional ;
2123import org .jetbrains .annotations .NotNull ;
2224import so .trophy .types .UpsertedUser ;
2325
@@ -30,12 +32,15 @@ public final class MetricsEventRequest {
3032
3133 private final double value ;
3234
35+ private final Optional <Map <String , String >> attributes ;
36+
3337 private final Map <String , Object > additionalProperties ;
3438
3539 private MetricsEventRequest (UpsertedUser user , double value ,
36- Map <String , Object > additionalProperties ) {
40+ Optional < Map < String , String >> attributes , Map <String , Object > additionalProperties ) {
3741 this .user = user ;
3842 this .value = value ;
43+ this .attributes = attributes ;
3944 this .additionalProperties = additionalProperties ;
4045 }
4146
@@ -55,6 +60,14 @@ public double getValue() {
5560 return value ;
5661 }
5762
63+ /**
64+ * @return Event attributes as key-value pairs. Keys must match existing event attributes set up in the Trophy dashboard.
65+ */
66+ @ JsonProperty ("attributes" )
67+ public Optional <Map <String , String >> getAttributes () {
68+ return attributes ;
69+ }
70+
5871 @ java .lang .Override
5972 public boolean equals (Object other ) {
6073 if (this == other ) return true ;
@@ -67,12 +80,12 @@ public Map<String, Object> getAdditionalProperties() {
6780 }
6881
6982 private boolean equalTo (MetricsEventRequest other ) {
70- return user .equals (other .user ) && value == other .value ;
83+ return user .equals (other .user ) && value == other .value && attributes . equals ( other . attributes ) ;
7184 }
7285
7386 @ java .lang .Override
7487 public int hashCode () {
75- return Objects .hash (this .user , this .value );
88+ return Objects .hash (this .user , this .value , this . attributes );
7689 }
7790
7891 @ java .lang .Override
@@ -96,6 +109,10 @@ public interface ValueStage {
96109
97110 public interface _FinalStage {
98111 MetricsEventRequest build ();
112+
113+ _FinalStage attributes (Optional <Map <String , String >> attributes );
114+
115+ _FinalStage attributes (Map <String , String > attributes );
99116 }
100117
101118 @ JsonIgnoreProperties (
@@ -106,6 +123,8 @@ public static final class Builder implements UserStage, ValueStage, _FinalStage
106123
107124 private double value ;
108125
126+ private Optional <Map <String , String >> attributes = Optional .empty ();
127+
109128 @ JsonAnySetter
110129 private Map <String , Object > additionalProperties = new HashMap <>();
111130
@@ -116,6 +135,7 @@ private Builder() {
116135 public Builder from (MetricsEventRequest other ) {
117136 user (other .getUser ());
118137 value (other .getValue ());
138+ attributes (other .getAttributes ());
119139 return this ;
120140 }
121141
@@ -141,9 +161,29 @@ public _FinalStage value(double value) {
141161 return this ;
142162 }
143163
164+ /**
165+ * <p>Event attributes as key-value pairs. Keys must match existing event attributes set up in the Trophy dashboard.</p>
166+ * @return Reference to {@code this} so that method calls can be chained together.
167+ */
168+ @ java .lang .Override
169+ public _FinalStage attributes (Map <String , String > attributes ) {
170+ this .attributes = Optional .ofNullable (attributes );
171+ return this ;
172+ }
173+
174+ @ java .lang .Override
175+ @ JsonSetter (
176+ value = "attributes" ,
177+ nulls = Nulls .SKIP
178+ )
179+ public _FinalStage attributes (Optional <Map <String , String >> attributes ) {
180+ this .attributes = attributes ;
181+ return this ;
182+ }
183+
144184 @ java .lang .Override
145185 public MetricsEventRequest build () {
146- return new MetricsEventRequest (user , value , additionalProperties );
186+ return new MetricsEventRequest (user , value , attributes , additionalProperties );
147187 }
148188 }
149189}
0 commit comments