package com.example.mathseduc.controllers

import android.os.StrictMode
import android.util.Log
import com.example.mathseduc.models.Lobby
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.IOException

class ControllerUtiliser {
    companion object {

        fun createUtiliserByIdLobby(utiliserData: MultipartBody.Builder): Boolean {
            try {
                val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
                StrictMode.setThreadPolicy(policy)

                // Client HTTP API
                val client = OkHttpClient()

                // API Access
                val request = Request.Builder()
                    .url("https://trusting-panini.87-106-126-109.plesk.page/api/add/utiliser/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
                    .post(utiliserData.build())
                    .build()

                // API Response
                client.newCall(request).execute().use { response ->
                    // Vérifier si la création du lobby a réussi
                    return response.isSuccessful
                }
            } catch (e: Exception) {
                // Log en cas d'erreur
                Log.e("CreateLobby", "Error creating lobby", e)
                return false
            }
        }

    }
}
