package app.furmeet.events.brasilfurfest.schedule

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import app.furmeet.events.brasilfurfest.MainActivity
import com.adlerosn.brasilfurfest.R
import app.furmeet.events.brasilfurfest.TranslatableAppCompatActivity
import app.furmeet.events.brasilfurfest.helper.logException
import app.furmeet.events.brasilfurfest.schedule.abstractDataTypes.managed.AttendeeConFavorite
import com.google.gson.GsonBuilder
import org.jetbrains.anko.longToast

// Only redirects; shows nothing
class RoomPartyPreviewerActivity : TranslatableAppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_room_party_previewer)
        if (this.intent?.data == null) return finish()
        val uri = this.intent!!.data!!
        try {
            val json = Uri.decode(uri.encodedFragment!!)
            GsonBuilder().create().fromJson(json, AttendeeConFavorite::class.java)
        } catch (e: Throwable) {
            logException(e)
            longToast(getString(R.string.error_broken_invite))
            startActivity(Intent(this, MainActivity::class.java))
            return finish()
        }
        val json = Uri.decode(uri.encodedFragment!!)
        val favorite = GsonBuilder().create().fromJson(json, AttendeeConFavorite::class.java)
        favorite.notified = false
        startActivity(Intent(this, EventActivity::class.java).apply {
            putExtra("favorite", favorite)
            putExtra("offerStar", true)
            putExtra("fromNotification", this@RoomPartyPreviewerActivity.intent.getBooleanExtra("notQr", true))
        })
        finish()
    }
}
