// package com.icing.dialer.services

// import android.telecom.Connection
// import android.telecom.ConnectionService
// import android.telecom.PhoneAccountHandle
// import android.telecom.TelecomManager
// import android.telecom.DisconnectCause
// import android.util.Log
// import io.flutter.plugin.common.MethodChannel

// class CallConnectionService : ConnectionService() {
//     companion object {
//         var channel: MethodChannel? = null
//         private const val TAG = "CallConnectionService"
//     }

//     init {
//         Log.d(TAG, "CallConnectionService initialized")
//     }

//     override fun onCreate() {
//         super.onCreate()
//         Log.d(TAG, "Service created")
//     }

//     override fun onDestroy() {
//         super.onDestroy()
//         Log.d(TAG, "Service destroyed")
//     }

//     override fun onCreateOutgoingConnection(
//         connectionManagerPhoneAccount: PhoneAccountHandle?,
//         request: android.telecom.ConnectionRequest
//     ): Connection {
//         Log.d(TAG, "Creating outgoing connection for ${request.address}, account: $connectionManagerPhoneAccount")
//         val connection = object : Connection() {
//             override fun onStateChanged(state: Int) {
//                 super.onStateChanged(state)
//                 Log.d(TAG, "Connection state changed: $state")
//                 val stateStr = when (state) {
//                     STATE_DIALING -> "dialing"
//                     STATE_ACTIVE -> "active"
//                     STATE_DISCONNECTED -> "disconnected"
//                     else -> "unknown"
//                 }
//                 channel?.invokeMethod("callStateChanged", mapOf("state" to stateStr, "phoneNumber" to request.address.toString()))
//             }

//             override fun onDisconnect() {
//                 Log.d(TAG, "Connection disconnected")
//                 setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
//                 destroy()
//             }
//         }
//         connection.setAddress(request.address, TelecomManager.PRESENTATION_ALLOWED)
//         connection.setInitialized()
//         connection.setDialing()
//         return connection
//     }

//     override fun onCreateIncomingConnection(
//         connectionManagerPhoneAccount: PhoneAccountHandle?,
//         request: android.telecom.ConnectionRequest
//     ): Connection {
//         Log.d(TAG, "Creating incoming connection for ${request.address}, account: $connectionManagerPhoneAccount")
//         val connection = object : Connection() {
//             override fun onAnswer() {
//                 Log.d(TAG, "Connection answered")
//                 setActive()
//             }

//             override fun onDisconnect() {
//                 Log.d(TAG, "Connection disconnected")
//                 setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
//                 destroy()
//             }
//         }
//         connection.setAddress(request.address, TelecomManager.PRESENTATION_ALLOWED)
//         connection.setRinging()
//         return connection
//     }
// }