git.iko.soy/parseable-android
on 0da331f help sign in
162 lines 4.4 kB history raw
1package com.parseable.android.data.model
3import kotlinx.serialization.SerialName
4import kotlinx.serialization.Serializable
5import kotlinx.serialization.json.JsonElement
6import kotlinx.serialization.json.JsonObject
8/**
9 * Server connection configuration stored in DataStore.
10 */
11data class ServerConfig(
12 val serverUrl: String,
13 val username: String,
14 val password: String,
15 val useTls: Boolean = true,
18/**
19 * Represents a log stream entry returned by GET /api/v1/logstream
20 */
21@Serializable
22data class LogStream(
23 val name: String,
26/**
27 * Query request body sent to POST /api/v1/query
28 */
29@Serializable
30data class QueryRequest(
31 val query: String,
32 val startTime: String,
33 val endTime: String,
36/**
37 * Stream stats from GET /api/v1/logstream/{name}/stats
38 */
39@Serializable
40data class StreamStats(
41 val ingestion: IngestionStats? = null,
42 val storage: StorageStats? = null,
43 val stream: String? = null,
44 val time: String? = null,
47@Serializable
48data class IngestionStats(
49 val count: Long? = null,
50 val size: String? = null,
51 val format: String? = null,
52 @SerialName("lifetime_count")
53 val lifetimeCount: Long? = null,
54 @SerialName("lifetime_size")
55 val lifetimeSize: String? = null,
56 @SerialName("deleted_count")
57 val deletedCount: Long? = null,
58 @SerialName("deleted_size")
59 val deletedSize: String? = null,
62@Serializable
63data class StorageStats(
64 val size: String? = null,
65 val format: String? = null,
66 @SerialName("lifetime_size")
67 val lifetimeSize: String? = null,
68 @SerialName("deleted_size")
69 val deletedSize: String? = null,
72/**
73 * Schema field info from GET /api/v1/logstream/{name}/schema
74 */
75@Serializable
76data class StreamSchema(
77 val fields: List<SchemaField> = emptyList(),
80@Serializable
81data class SchemaField(
82 val name: String,
83 @SerialName("data_type")
84 val dataType: JsonElement? = null,
85 val nullable: Boolean? = null,
86 val dict_id: Long? = null,
87 val dict_is_ordered: Boolean? = null,
88 val metadata: JsonObject? = null,
91/**
92 * Retention config from GET /api/v1/logstream/{name}/retention
93 */
94@Serializable
95data class RetentionConfig(
96 val description: String? = null,
97 val duration: String? = null,
98 val action: String? = null,
101/**
102 * About info from GET /api/v1/about
103 */
104@Serializable
105data class AboutInfo(
106 val version: String? = null,
107 val commit: String? = null,
108 @SerialName("deploymentId")
109 val deploymentId: String? = null,
110 val license: JsonObject? = null,
111 val mode: String? = null,
112 val staging: String? = null,
113 val store: JsonObject? = null,
114 @SerialName("grpcPort")
115 val grpcPort: Int? = null,
116 val analytics: JsonObject? = null,
117 @SerialName("queryEngine")
118 val queryEngine: String? = null,
121/**
122 * Alert configuration
123 */
124@Serializable
125data class Alert(
126 val id: String? = null,
127 val version: String? = null,
128 val name: String? = null,
129 val message: String? = null,
130 val rule: JsonObject? = null,
131 val targets: List<JsonObject> = emptyList(),
132 val stream: String? = null,
133 val enabled: Boolean? = null,
136/**
137 * Result wrapper for API calls
138 */
139sealed class ApiResult<out T> {
140 data class Success<T>(val data: T) : ApiResult<T>()
141 data class Error(val message: String, val code: Int = 0) : ApiResult<Nothing>() {
142 val isUnauthorized: Boolean get() = code == 401
143 val isNotFound: Boolean get() = code == 404
144 val isServerError: Boolean get() = code in 500..599
145 val isNetworkError: Boolean get() = code == 0
147 val userMessage: String get() = when {
148 code == 401 -> "Session expired. Please log in again."
149 code == 403 -> "Permission denied."
150 code == 404 -> "Resource not found. It may have been deleted."
151 code == 429 -> "Too many requests. Please wait and try again."
152 code in 500..599 -> "Server error ($code). Please try again later."
153 code == 0 -> when {
154 message.contains("timeout", ignoreCase = true) -> "Connection timed out. Check your network."
155 message.contains("Unable to resolve host", ignoreCase = true) -> "No internet connection."
156 message.contains("Connection refused", ignoreCase = true) -> "Server is unreachable."
157 else -> "Network error: $message"
158 }
159 else -> message
160 }
161 }