package com.mob5.smarthousew

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView
import com.mob5.smarthouse.common.MyRetrofit
import com.mob5.smarthouse.common.Rooms
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MainScreen : Activity() {
    lateinit var rooms_rec: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main_screen)

        rooms_rec = findViewById(R.id.rooms_rec)

        val token = getSharedPreferences("data", Context.MODE_PRIVATE).getString("token", null)
        val call = MyRetrofit.getRetrofit().getRooms(token!!, "5FA1B987-3890-4A87-9712-ACDEAD0173AE")
        call.enqueue(object : Callback<Rooms> {
            override fun onResponse(call: Call<Rooms>, response: Response<Rooms>) {
                response.body()?.let { rooms_rec.adapter = RoomsAdapter(this@MainScreen, it) }
            }

            override fun onFailure(call: Call<Rooms>, t: Throwable) {
                AlertDialog.Builder(this@MainScreen).setTitle("Ошибка").setMessage(t.message).setPositiveButton("OK", null).show()
            }
        })
//startActivity(Intent(this, DeviceScreen::class.java))


    }
}