import Foundation

enum CallPhase: String, Sendable {
    case idle
    case incoming
    case outgoing
    case keyExchange
    case webRtcExchange
    case active
    case ended
}

enum CallRole: Sendable {
    case caller
    case callee
}

enum CallSignalingMode: String, Sendable {
    case undecided
    case legacy
    case createRoom
}

enum CallActionResult: Sendable {
    case started
    case alreadyInCall
    case accountNotBound
    case invalidTarget
    case notIncoming
}

struct CallUiState: Equatable, Sendable {
    var phase: CallPhase = .idle
    var peerPublicKey: String = ""
    var peerTitle: String = ""
    var peerUsername: String = ""
    var statusText: String = ""
    var durationSec: Int = 0
    var isMuted: Bool = false
    var isSpeakerOn: Bool = false
    var keyCast: String = ""
    var isMinimized: Bool = false

    var isVisible: Bool {
        phase != .idle
    }

    /// Full-screen overlay should show when call is active AND not minimized.
    var isFullScreenVisible: Bool {
        isVisible && !isMinimized
    }

    var displayName: String {
        if !peerTitle.isEmpty { return peerTitle }
        if !peerUsername.isEmpty { return "@\(peerUsername)" }
        if !peerPublicKey.isEmpty { return String(peerPublicKey.prefix(12)) }
        return "Unknown"
    }
}
