package llc.arma.ble.data.repository

import android.app.Application
import android.content.Intent
import androidx.core.content.FileProvider
import llc.arma.ble.domain.repository.EmailRepository
import java.io.File
import javax.inject.Inject

class EmailRepositoryImpl @Inject constructor(
    private val application: Application
) : EmailRepository {

    override fun sendFile(file: File) {
        val uri = FileProvider.getUriForFile(application, "llc.arma.ble.fileprovider", file)

        val sendIntent = Intent(Intent.ACTION_SEND)
        sendIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        sendIntent.type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Measure history")
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri)
        application.startActivity(
            Intent.createChooser(sendIntent, "Send email...").apply {
                flags = Intent.FLAG_ACTIVITY_NEW_TASK
            }
        )
    }

}