package cy.hexor.furumi.domain.model

data class ConnectedDevice(
    val id: String,
    val name: String,
    val kind: String,
    val isCurrent: Boolean,
    val isActive: Boolean,
    val lastSeenMs: Long
)

data class ConnectedDevicesState(
    val deviceId: String,
    val activeDeviceId: String?,
    val devices: List<ConnectedDevice>,
    val jams: List<ConnectedJam>,
    val currentJamId: String?,
    val remotePlaybackState: ConnectedPlaybackState?
) {
    val isCurrentDeviceActive: Boolean
        get() = activeDeviceId == deviceId
}

data class ConnectedJam(
    val id: String,
    val name: String,
    val hostUserId: Long,
    val hostName: String,
    val isOwner: Boolean,
    val isMember: Boolean,
    val isPending: Boolean,
    val isActive: Boolean,
    val memberCount: Long,
    val hostLastSeenMs: Long,
    val hostDeviceOnline: Boolean,
    val members: List<ConnectedJamMember>
)

data class ConnectedJamMember(
    val userId: Long,
    val name: String,
    val isJoined: Boolean,
    val isCurrentUser: Boolean,
    val lastSeenMs: Long
)

data class ConnectedJamUser(
    val id: Long,
    val username: String,
    val displayName: String?,
    val email: String?
) {
    val displayLabel: String
        get() = displayName?.takeIf { it.isNotBlank() } ?: username
}

data class ConnectedPlaybackState(
    val track: TrackCard?,
    val tracks: List<TrackCard>,
    val index: Int,
    val positionSeconds: Double,
    val durationSeconds: Double,
    val paused: Boolean,
    val shuffle: Boolean,
    val repeatMode: String,
    val volume: Double
)

data class ConnectedCommand(
    val id: String?,
    val command: String,
    val payload: ConnectedCommandPayload
)

data class ConnectedCommandPayload(
    val playbackState: ConnectedPlaybackState?,
    val tracks: List<TrackCard>,
    val index: Int?,
    val time: Double?,
    val volume: Double?,
    val shuffle: Boolean?,
    val repeatMode: String?,
    val fromIndex: Int?,
    val toIndex: Int?
)
