import Foundation /// MongoDB references are populated on some API routes and bare ObjectIds on others. nonisolated public enum APIReference: Decodable, Sendable { case id(String) case value(Value) public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() if let id = try? container.decode(String.self) { self = .id(id) } else { self = .value(try container.decode(Value.self)) } } } nonisolated public struct Artist: Decodable, Identifiable, Sendable { public let id: String public let name: String public let file: String? enum CodingKeys: String, CodingKey { case id = "_id" case name, file } } nonisolated public struct Genre: Decodable, Identifiable, Sendable { public let id: String public let name: String enum CodingKeys: String, CodingKey { case id = "_id" case name } } nonisolated public struct Album: Decodable, Identifiable, Sendable { public let id: String public let name: String public let artists: [APIReference] public let file: String? public let genre: APIReference? enum CodingKeys: String, CodingKey { case id = "_id" case name, artists, file, genre } } nonisolated public struct Lyrics: Decodable, Sendable { public let synced: Bool public let text: String } nonisolated public struct Track: Decodable, Identifiable, Sendable { public let id: String public let name: String public let album: APIReference public let artists: [APIReference] public let fileDir: String public let durationInSeconds: Double public let lyrics: Lyrics? enum CodingKeys: String, CodingKey { case id = "_id" case name, album, artists, fileDir, durationInSeconds, lyrics } } nonisolated public struct User: Decodable, Identifiable, Sendable { public let id: String public let name: String public let email: String public let role: String public let savedTracks: [String]? enum CodingKeys: String, CodingKey { case id = "_id" case name, email, role, savedTracks } } nonisolated public struct SessionStatus: Decodable, Sendable { public let authenticated: Bool } nonisolated public struct Session: Decodable, Sendable { public let expireAt: Date /// Returned for administrative bearer auth; ordinary user auth uses the HttpOnly cookie. public let sessionToken: String } nonisolated public struct SearchResults: Decodable, Sendable { public let tracks: [Track] public let albums: [Album] public let artists: [Artist] } nonisolated public struct TrackMembership: Decodable, Sendable { public let contains: Bool } nonisolated public enum SearchType: String, Sendable { case track, album, artist, `default` }