package com.isidroid.job_sender.data.source.remote

import com.isidroid.job_sender.data.source.remote.api.ApiCommand
import com.isidroid.job_sender.data.source.remote.api.ApiUpload
import com.isidroid.network.ProgressEmittingRequestBody
import okhttp3.MultipartBody
import java.io.File
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SendJobNetworkSource @Inject constructor(
    private val apiUpload: ApiUpload,
    private val apiCommand: ApiCommand
) {
    fun uploadPage(jobId: String, token: String, filePath: String): Boolean {
        val file = File(filePath)
        val requestBody = ProgressEmittingRequestBody("image/*", file)
        val fileBody = MultipartBody.Part.createFormData("file", file.name, requestBody)
        val response = apiUpload.upload(jobId = jobId, token = token, fileBody).execute()

        return response.isSuccessful
    }

    fun complete(jobId: String, token: String): Boolean {
        apiCommand.complete(jobId = jobId, token = token).execute()
        return true
    }
}