From de652e8ac41b9a298cb6fdb31493d3c55c2d420d Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:13:36 -0300 Subject: [PATCH] Add files via upload --- .../model/chat/ChatMessagePinTimer.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/it/auties/whatsapp/model/chat/ChatMessagePinTimer.java diff --git a/src/main/java/it/auties/whatsapp/model/chat/ChatMessagePinTimer.java b/src/main/java/it/auties/whatsapp/model/chat/ChatMessagePinTimer.java new file mode 100644 index 00000000..aa5c5f94 --- /dev/null +++ b/src/main/java/it/auties/whatsapp/model/chat/ChatMessagePinTimer.java @@ -0,0 +1,63 @@ +package it.auties.whatsapp.model.chat; + +import it.auties.protobuf.annotation.ProtobufConverter; +import it.auties.protobuf.annotation.ProtobufEnumIndex; +import it.auties.protobuf.model.ProtobufEnum; + +import java.time.Duration; +import java.util.Arrays; + +/** + * Enum representing the ChatMessagePinTimer period. Each constant is associated with a specific + * duration period. + */ +public enum ChatMessagePinTimer implements ProtobufEnum { + /** + * ChatMessagePinTimer with duration of 0 days. + */ + OFF(0, Duration.ofDays(0)), + + /** + * ChatMessagePinTimer with duration of 1 day. + */ + ONE_DAY(1, Duration.ofDays(1)), + + /** + * ChatMessagePinTimer with duration of 7 days. + */ + ONE_WEEK(2, Duration.ofDays(7)), + + /** + * ChatMessagePinTimer with duration of 30 days. + */ + ONE_MONTH(3, Duration.ofDays(30)); + + private final Duration period; + final int index; + + ChatMessagePinTimer(@ProtobufEnumIndex int index, Duration period) { + this.index = index; + this.period = period; + } + + public int index() { + return index; + } + + public Duration period() { + return period; + } + + @ProtobufConverter + public static ChatMessagePinTimer of(int value) { + return Arrays.stream(values()) + .filter(entry -> entry.period().toSeconds() == value || entry.period().toDays() == value) + .findFirst() + .orElse(OFF); + } + + @ProtobufConverter + public int periodSeconds() { + return (int) period.toSeconds(); + } +} \ No newline at end of file