api-swift / Sources / IrdAPI / Generated / Support.swift
1,304 words
  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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// Generated by scripts/gen-api.py from spec/openapi.json — do not edit.

import Foundation

// MARK: - Types

/// Values this build does not know decode as `.unrecognized`.
public enum SupportThreadService: RawRepresentable, Codable, Sendable, Hashable {
    case domains
    case consultancy
    case spatial
    case general
    /// A value the server sent that this version of the package does not list.
    case unrecognized(String)

    /// Every value the spec listed when this file was generated.
    public static let known: [SupportThreadService] = [.domains, .consultancy, .spatial, .general]

    public init(rawValue: String) {
        switch rawValue {
        case "domains": self = .domains
        case "consultancy": self = .consultancy
        case "spatial": self = .spatial
        case "general": self = .general
        default: self = .unrecognized(rawValue)
        }
    }

    public var rawValue: String {
        switch self {
        case .domains: return "domains"
        case .consultancy: return "consultancy"
        case .spatial: return "spatial"
        case .general: return "general"
        case .unrecognized(let raw): return raw
        }
    }

    public init(from decoder: any Decoder) throws {
        self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

/// Shared by 4 operations.
public struct SupportThread: Codable, Sendable, Hashable, Identifiable {
    public var id: String
    public var email: String
    public var title: String?
    public var service: SupportThreadService?
    public var lastName: String?
    public var messageCount: Int
    public var unreadCount: Int
    public var lastPreview: String?
    public var createdAt: String
    public var updatedAt: String
    public var lastActivityAt: String

    public init(id: String, email: String, title: String? = nil, service: SupportThreadService? = nil, lastName: String? = nil, messageCount: Int, unreadCount: Int, lastPreview: String? = nil, createdAt: String, updatedAt: String, lastActivityAt: String) {
        self.id = id
        self.email = email
        self.title = title
        self.service = service
        self.lastName = lastName
        self.messageCount = messageCount
        self.unreadCount = unreadCount
        self.lastPreview = lastPreview
        self.createdAt = createdAt
        self.updatedAt = updatedAt
        self.lastActivityAt = lastActivityAt
    }

    enum CodingKeys: String, CodingKey {
        case id
        case email
        case title
        case service
        case lastName = "last_name"
        case messageCount = "message_count"
        case unreadCount = "unread_count"
        case lastPreview = "last_preview"
        case createdAt = "created_at"
        case updatedAt = "updated_at"
        case lastActivityAt = "last_activity_at"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(email, forKey: .email)
        try container.encode(title, forKey: .title)
        try container.encode(service, forKey: .service)
        try container.encode(lastName, forKey: .lastName)
        try container.encode(messageCount, forKey: .messageCount)
        try container.encode(unreadCount, forKey: .unreadCount)
        try container.encode(lastPreview, forKey: .lastPreview)
        try container.encode(createdAt, forKey: .createdAt)
        try container.encode(updatedAt, forKey: .updatedAt)
        try container.encode(lastActivityAt, forKey: .lastActivityAt)
    }
}

/// Used by GET /contact/threads.
public struct ListThreadsResponse: Codable, Sendable, Hashable {
    public var threads: [SupportThread]
    public var nextCursor: String?
    public var unreadCount: Int

    public init(threads: [SupportThread], nextCursor: String? = nil, unreadCount: Int) {
        self.threads = threads
        self.nextCursor = nextCursor
        self.unreadCount = unreadCount
    }

    enum CodingKeys: String, CodingKey {
        case threads
        case nextCursor = "next_cursor"
        case unreadCount = "unread_count"
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(threads, forKey: .threads)
        try container.encode(nextCursor, forKey: .nextCursor)
        try container.encode(unreadCount, forKey: .unreadCount)
    }
}

/// Used by POST /contact/threads.
public struct CreateThreadBody: Codable, Sendable, Hashable {
    public var title: String
    public var service: SupportThreadService
    public var message: String

    public init(title: String, service: SupportThreadService, message: String) {
        self.title = title
        self.service = service
        self.message = message
    }

    enum CodingKeys: String, CodingKey {
        case title
        case service
        case message
    }
}

/// Used by POST /contact/threads.
public struct CreateThreadResponse: Codable, Sendable, Hashable {
    public var thread: SupportThread

    public init(thread: SupportThread) {
        self.thread = thread
    }

    enum CodingKeys: String, CodingKey {
        case thread
    }
}

/// Shared by 2 operations.
public struct ThreadReply: Codable, Sendable, Hashable, Identifiable {
    public var id: String
    public var displayName: String
    public var body: String
    public var createdAt: String

    public init(id: String, displayName: String, body: String, createdAt: String) {
        self.id = id
        self.displayName = displayName
        self.body = body
        self.createdAt = createdAt
    }

    enum CodingKeys: String, CodingKey {
        case id
        case displayName = "display_name"
        case body
        case createdAt = "created_at"
    }
}

/// Shared by 2 operations.
public struct ThreadMessage: Codable, Sendable, Hashable, Identifiable {
    public var id: String
    public var threadId: String?
    public var name: String
    public var email: String
    public var message: String
    public var userId: String?
    public var createdAt: String
    public var replies: [ThreadReply]

    public init(id: String, threadId: String? = nil, name: String, email: String, message: String, userId: String? = nil, createdAt: String, replies: [ThreadReply]) {
        self.id = id
        self.threadId = threadId
        self.name = name
        self.email = email
        self.message = message
        self.userId = userId
        self.createdAt = createdAt
        self.replies = replies
    }

    enum CodingKeys: String, CodingKey {
        case id
        case threadId = "thread_id"
        case name
        case email
        case message
        case userId = "user_id"
        case createdAt = "created_at"
        case replies
    }

    /// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(threadId, forKey: .threadId)
        try container.encode(name, forKey: .name)
        try container.encode(email, forKey: .email)
        try container.encode(message, forKey: .message)
        try container.encode(userId, forKey: .userId)
        try container.encode(createdAt, forKey: .createdAt)
        try container.encode(replies, forKey: .replies)
    }
}

/// Shared by 2 operations.
public struct ThreadResponse: Codable, Sendable, Hashable {
    public var thread: SupportThread
    public var messages: [ThreadMessage]

    public init(thread: SupportThread, messages: [ThreadMessage]) {
        self.thread = thread
        self.messages = messages
    }

    enum CodingKeys: String, CodingKey {
        case thread
        case messages
    }
}

/// Used by POST /contact/threads/{id}/messages.
public struct ReplyBody: Codable, Sendable, Hashable {
    public var message: String

    public init(message: String) {
        self.message = message
    }

    enum CodingKeys: String, CodingKey {
        case message
    }
}

/// Query parameters of `listThreads`; unset fields are omitted.
public struct ListThreadsQuery: Sendable, Hashable {
    public var limit: Int?
    public var cursor: String?

    public init(limit: Int? = nil, cursor: String? = nil) {
        self.limit = limit
        self.cursor = cursor
    }

    /// The items in spec order.
    public var queryItems: [QueryItem] {
        var items: [QueryItem] = []
        if let value = limit { items.append(QueryItem("limit", String(value))) }
        if let value = cursor { items.append(QueryItem("cursor", value)) }
        return items
    }
}

// MARK: - Operations

extension IrdOperation {
    public static let support_listThreads = IrdOperation(method: .get, pathTemplate: "/contact/threads", module: "support", name: "listThreads", security: .keyOrJwt)
    public static let support_createThread = IrdOperation(method: .post, pathTemplate: "/contact/threads", module: "support", name: "createThread", security: .keyOrJwt)
    public static let support_getThread = IrdOperation(method: .get, pathTemplate: "/contact/threads/{id}", module: "support", name: "getThread", security: .keyOrJwt)
    public static let support_reply = IrdOperation(method: .post, pathTemplate: "/contact/threads/{id}/messages", module: "support", name: "reply", security: .keyOrJwt)

    static let supportOperations: [IrdOperation] = [.support_listThreads, .support_createThread, .support_getThread, .support_reply]
}

/// The `support` operations (4).
public struct SupportAPI: Sendable {
    let client: IrdClient

    /// List your support threads
    /// Your support conversations with the ird team, newest first (threads are keyed by account email), plus `unread_count` — how many team replies you haven't read yet.
    /// `GET /contact/threads` — 200
    public func listThreads(query: ListThreadsQuery = ListThreadsQuery()) async throws -> ListThreadsResponse {
        try await client.request(.support_listThreads, query: query.queryItems)
    }

    /// Open a support thread
    /// Starts a conversation with the ird team: a title, the service it concerns (`domains`, `consultancy`, `spatial`, or `general`), and your message.
    /// `POST /contact/threads` — 200
    public func createThread(body: CreateThreadBody) async throws -> CreateThreadResponse {
        try await client.request(.support_createThread, body: body)
    }

    /// Read a support thread
    /// One of your threads with every message and every ird-team reply, chronological. Reading marks the thread's replies as seen (resets its `unread_count`). 0-priced at launch (contract `support.reads`).
    /// `GET /contact/threads/{id}` — 200
    public func getThread(id: String) async throws -> ThreadResponse {
        try await client.request(.support_getThread, params: ["id": id])
    }

    /// Reply on a support thread
    /// Appends your message to one of your threads and returns the refreshed conversation. 0-priced at launch (contract `support.writes`).
    /// `POST /contact/threads/{id}/messages` — 200
    public func reply(id: String, body: ReplyBody) async throws -> ThreadResponse {
        try await client.request(.support_reply, params: ["id": id], body: body)
    }
}

extension IrdClient {
    public var support: SupportAPI { SupportAPI(client: self) }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git