package com.vanta.smsgateway import android.app.Activity import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import kotlinx.coroutines.* class SmsDeliveredReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val jobId = intent.getLongExtra("job_id", -1L) if (jobId == -1L) return val prefs = context.getSharedPreferences(SmsService.PREF_NAME, Context.MODE_PRIVATE) val url = prefs.getString(SmsService.PREF_URL, "") ?: "" val apiKey = prefs.getString(SmsService.PREF_KEY, "") ?: "" if (url.isEmpty() || apiKey.isEmpty()) return // Only report actual delivery confirmation if (resultCode != Activity.RESULT_OK) return val client = ApiClient(url, apiKey) CoroutineScope(Dispatchers.IO).launch { client.reportReceipt(jobId, "delivered") } } }