ios_app_v2/yobble/Network/SearchModels.swift
2025-10-07 05:24:35 +03:00

55 lines
1.3 KiB
Swift

import Foundation
struct SearchDataPayload: Decodable {
let users: [UserSearchResult]
}
struct UserSearchResult: Decodable, Identifiable {
let userId: UUID
let login: String
let fullName: String?
let customName: String?
let createdAt: Date?
let profile: SearchProfile?
var id: UUID { userId }
}
struct SearchProfile: Decodable {
let userId: UUID
let login: String?
let fullName: String?
let customName: String?
let bio: String?
let lastSeen: Int?
let createdAt: Date?
}
extension UserSearchResult {
var displayName: String {
if let customName = customName, !customName.isEmpty {
return customName
}
if let fullName = fullName, !fullName.isEmpty {
return fullName
}
if let profileName = profile?.customName, !profileName.isEmpty {
return profileName
}
if let profileFullName = profile?.fullName, !profileFullName.isEmpty {
return profileFullName
}
return "@\(login)"
}
var secondaryText: String? {
if let fullName = fullName, !fullName.isEmpty, fullName != displayName {
return fullName
}
if let profileLogin = profile?.login, !profileLogin.isEmpty, profileLogin != login {
return "@\(profileLogin)"
}
return nil
}
}