package com.sybotan.android.demo.activities

import android.Manifest
import android.accounts.AccountManager
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.ActivityCompat
import androidx.core.content.PermissionChecker.PERMISSION_GRANTED
import com.framework.mvvm.model.vo.AdmRequest
import com.framework.mvvm.mv.AdmViewModel
import com.sybotan.android.demo.R
import com.sybotan.android.demo.activities.poc.SceneActivity
import com.sybotan.android.demo.activities.poc.SpaceActivity
import org.jetbrains.anko.startActivity
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.android.closestDI
import org.kodein.di.android.x.viewmodel.viewModel

class PocActivity : AppCompatActivity(), DIAware {

    override val di: DI by closestDI()

    private val mVm: AdmViewModel by viewModel()

    private val tag = "PocActivity"

    private val REQUEST_EXTERNAL_STORAGE = 1 // 不可改

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_poc)
        checkStoragePermission()
        val spaceCL = findViewById<ConstraintLayout>(R.id.spaceCL)
        spaceCL.setOnClickListener {
            startActivity<SpaceActivity>()
        }

        val sceneCL = findViewById<ConstraintLayout>(R.id.sceneCL)
        sceneCL.setOnClickListener {
            startActivity<SceneActivity>()
        }

        mVm.requestFrame(
            AdmRequest(
                userId = "bdtp",
                projectId = "Pj0002220002",
                groupCode = "BR"
            )
        )

        mVm.requestDict(
            AdmRequest(
                userId = "bdtp",
                projectId = "Pj0002220002",
                groupCode = "BR"
            )
        )

        mVm.requestBuilding(
            AdmRequest(
                userId = "bdtp",
                projectId = "Pj0002220002",
                groupCode = "BR",
                buildingId = "Bd0002220002bcaa181bd406439c9ecaddac13b0d543"
            )
        )

    }

    private fun checkStoragePermission() {
//        ActivityCompat.requestPermissions(
//            this, arrayOf(
//                Manifest.permission.READ_EXTERNAL_STORAGE,
//                Manifest.permission.WRITE_EXTERNAL_STORAGE
//            ),
//            REQUEST_EXTERNAL_STORAGE
//        )
        if (ActivityCompat.checkSelfPermission(
                this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            ActivityCompat.requestPermissions(
                this,
                arrayOf(
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_PHONE_STATE
                ),
                1
            )
        }
    }

}