package com.mob5.smarthouse

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import com.mob5.smarthouse.common.MyRetrofit
import com.mob5.smarthouse.common.Rooms
import com.mob5.smarthouse.main_screen.RoomsAdapter
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class AddRoomScreen : AppCompatActivity() {
    lateinit var name: EditText

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

        name = findViewById(R.id.add_room_et)
    }

    fun Close(view: View) {
        finish()
    }

    fun AddRoom(view: View) {
        val token = getSharedPreferences("data", Context.MODE_PRIVATE).getString("token", null)
        val call = MyRetrofit.getRetrofit().addRoom(name.text.toString(), "Bedroom", token!!, "5FA1B987-3890-4A87-9712-ACDEAD0173AE")
        call.enqueue(object : Callback<HashMap<String, String>> {
            override fun onResponse(call: Call<HashMap<String, String>>, response: Response<HashMap<String, String>>) {

            }

            override fun onFailure(call: Call<HashMap<String, String>>, t: Throwable) {
                AlertDialog.Builder(this@AddRoomScreen).setTitle("Ошибка").setMessage(t.message).setPositiveButton("OK", null).show()
            }
        })
    }
}