package app.furmeet.events.system

import android.content.Intent
import android.os.Bundle
import android.provider.Settings.Secure.putString
import app.furmeet.events.system.helper.resourcesAliased
import app.furmeet.events.system.notification.NotificationFirer
import app.furmeet.events.system.schedule.RoomPartyPreviewerActivity
import app.furmeet.events.system.schedule.managers.FullUpdateCheckerCancellable
import app.furmeet.events.system.schedule.managers.RemoteAssetsHolder
import app.furmeet.events.bff.databinding.ActivityMainBinding

//Entry point
class MainActivity : TranslatableAppCompatActivityWithScheduleServiceWrapped() {

    lateinit var binding: ActivityMainBinding;

    override fun onCreate(savedInstanceState: Bundle?) {
        RemoteAssetsHolder.ensureIsBuilt(this)
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        FullUpdateCheckerCancellable(baseContext).run { NotificationFirer().fire(baseContext) }
        resourcesAliased = this.resources
        when {
            (this.intent != null) && (this.intent?.data?.path?.startsWith("/app/roomparty")
                    ?: false) ->
                startActivity(Intent(this, RoomPartyPreviewerActivity::class.java).apply {
                    data = this@MainActivity.intent?.data
                    flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
                })
            else ->
                startActivity(Intent(this, SplashActivity::class.java).apply {
                    flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
                    putExtra("uri", this@MainActivity.intent?.data?.toString())
                })
        }
        finish()
    }
}
