import Foundation

struct SavedServer: Codable, Identifiable, Equatable {
    let id: UUID
    var host: String
    var port: UInt16
    var authMode: AuthMode
    var savedUsername: String
    /// Free-form display name used when connecting as a guest. Distinct from the account
    /// `savedUsername`. Empty falls back to a default. Optional for backward-compatible decoding.
    var nickname: String?
    var keychainTag: String

    enum AuthMode: String, Codable { case guest, password }

    init(id: UUID = UUID(), host: String, port: UInt16,
         authMode: AuthMode = .guest, savedUsername: String = "",
         nickname: String? = nil, keychainTag: String = "") {
        self.id = id
        self.host = host
        self.port = port
        self.authMode = authMode
        self.savedUsername = savedUsername
        self.nickname = nickname
        self.keychainTag = keychainTag.isEmpty ? id.uuidString : keychainTag
    }

    var displayString: String { "\(host):\(port)" }
}
