package com.example.tasq

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.media.AudioAttributes
import android.util.Log
import android.net.Uri

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        createTasqChannel()
    }

    private fun createTasqChannel() {
        val channelId = "tasq_custom_sound_channel_3"
        val name = "TasQ notifications"
        val importance = NotificationManager.IMPORTANCE_HIGH
        val channel = NotificationChannel(channelId, name, importance)

        val soundUri = Uri.parse("android.resource://$packageName/raw/tasq_notification")
        val audioAttributes = AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .build()

        channel.setSound(soundUri, audioAttributes)
        // Ensure we do NOT bypass Do Not Disturb — let the system enforce silent/vibrate modes
        channel.setBypassDnd(false)
        // Allow vibration; system will respect device vibrate settings
        channel.enableVibration(true)

        val nm = getSystemService(NotificationManager::class.java)
        nm?.createNotificationChannel(channel)
        Log.d("App", "Created notification channel: $channelId with sound=$soundUri")
    }
}
