package co.tiagoaguiar.course.instagram.register.presentation

import android.net.Uri
import co.tiagoaguiar.course.instagram.R
import co.tiagoaguiar.course.instagram.register.RegisterNameAndPassword
import co.tiagoaguiar.course.instagram.register.RegisterPhoto
import co.tiagoaguiar.course.instagram.register.data.RegisterCallback
import co.tiagoaguiar.course.instagram.register.data.RegisterRepository

class RegisterPhotoPresenter(
  private var view: RegisterPhoto.View?,
  private val repository: RegisterRepository
) : RegisterPhoto.Presenter {

  override fun updateUser(photoUri: Uri) {
    view?.showProgress(true)

    repository.updateUser(photoUri, object : RegisterCallback {
      override fun onSuccess() {
        view?.onUpdateSuccess()
      }

      override fun onFailure(message: String) {
        view?.onUpdateFailure(message)
      }

      override fun onComplete() {
        view?.showProgress(false)
      }
    })
  }

  override fun onDestroy() {
    view = null
  }

}