aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/EventInformation.kt
blob: 17682b8e1b9c9a8f9c80093cf59ab82d108638ac (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * TrackerMap
 * Copyright (C) 2021-2022  Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package mx.trackermap.TrackerMap.client.models

import kotlinx.serialization.Serializable

@Serializable
data class EventInformation(
    val event: Event,
    val position: Position?,
    val geofence: Geofence?
) {
    enum class Type {
        ALL,
        DEVICE_ONLINE,
        DEVICE_UNKNOWN,
        DEVICE_OFFLINE,
        DEVICE_INACTIVE,
        DEVICE_MOVING,
        DEVICE_STOPPED,
        DEVICE_OVERSPEED,
        DEVICE_FUEL_DROP,
        COMMAND_RESULT,
        GEOFENCE_ENTER,
        GEOFENCE_EXIT,
        ALARM,
        IGNITION_ON,
        IGNITION_OFF,
        MAINTENANCE,
        TEXT_MESSAGE,
        DRIVER_CHANGED,
        UNKNOWN
    }

    companion object {
        fun reportTypeToString(t: Type) =
            when (t) {
                Type.ALL -> "%"
                Type.DEVICE_ONLINE -> "deviceOnline"
                Type.DEVICE_UNKNOWN -> "deviceUnknown"
                Type.DEVICE_OFFLINE -> "deviceOffline"
                Type.DEVICE_INACTIVE -> "deviceInactive"
                Type.DEVICE_MOVING -> "deviceMoving"
                Type.DEVICE_STOPPED -> "deviceStopped"
                Type.DEVICE_OVERSPEED -> "deviceOverspeed"
                Type.DEVICE_FUEL_DROP -> "deviceFuelDrop"
                Type.COMMAND_RESULT -> "commandResult"
                Type.GEOFENCE_ENTER -> "geofenceEnter"
                Type.GEOFENCE_EXIT -> "geofenceExit"
                Type.ALARM -> "alarm"
                Type.IGNITION_ON -> "ignitionOn"
                Type.IGNITION_OFF -> "ignitionOff"
                Type.MAINTENANCE -> "maintenance"
                Type.TEXT_MESSAGE -> "textMessage"
                Type.DRIVER_CHANGED -> "driverChanged"
                Type.UNKNOWN -> "unknown"
            }

        fun reportTypesToStrings(t: List<Type>) =
            if (t.isEmpty() || t.contains(Type.ALL)) {
                listOf(reportTypeToString(Type.ALL))
            } else {
                t.map(this::reportTypeToString)
            }

        fun stringToReportType(s: String) =
            when (s) {
                "deviceOnline" -> Type.DEVICE_ONLINE
                "deviceUnknown" -> Type.DEVICE_UNKNOWN
                "deviceOffline" -> Type.DEVICE_OFFLINE
                "deviceInactive" -> Type.DEVICE_INACTIVE
                "deviceMoving" -> Type.DEVICE_MOVING
                "deviceStopped" -> Type.DEVICE_STOPPED
                "deviceOverspeed" -> Type.DEVICE_OVERSPEED
                "deviceFuelDrop" -> Type.DEVICE_FUEL_DROP
                "commandResult" -> Type.COMMAND_RESULT
                "geofenceEnter" -> Type.GEOFENCE_ENTER
                "geofenceExit" -> Type.GEOFENCE_EXIT
                "alarm" -> Type.ALARM
                "ignitionOn" -> Type.IGNITION_ON
                "ignitionOff" -> Type.IGNITION_OFF
                "maintenance" -> Type.MAINTENANCE
                "textMessage" -> Type.TEXT_MESSAGE
                "driverChanged" -> Type.DRIVER_CHANGED
                "unknown" -> Type.UNKNOWN
                else -> Type.UNKNOWN
            }
    }
}