import Foundation import Observation /// `profile show ` plus the profile's reachable repositories via /// `repo search` filtered to the owner prefix. @Observable @MainActor final class ProfileViewModel { nonisolated struct Profile: Decodable, Sendable, Hashable { let name: String let kind: String // user | org let description: String? let website: String? } private(set) var state: LoadState = .loading private(set) var repos: [RepoSummary] = [] private let client: GitbayClient let name: String init(client: GitbayClient, name: String) { self.client = client self.name = name } func load() async { do { state = .loaded(try await client.read(["profile", "show", name], as: Profile.self)) } catch { state = .from(error) return } // Search matches on path, so the owner name surfaces their repos; // keep only true prefix matches. repos = ((try? await client.readList(["repo", "search", name], of: RepoSummary.self)) ?? []) .filter { $0.owner == name } } }