package com.github.nullptroma.wallenc.domain.vault.network.yandexdisk

import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.dto.CustomPropertiesPatchDto
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.dto.DiskInfoDto
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.dto.LinkDto
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.dto.OperationStatusDto
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.dto.ResourceDto
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.PATCH
import retrofit2.http.PUT
import retrofit2.http.Query
import retrofit2.http.Url

interface YandexDiskApi {

    @GET("v1/disk/")
    suspend fun getDisk(): DiskInfoDto

    @GET("v1/disk/resources")
    suspend fun listResources(
        @Query("path") path: String,
        @Query("limit") limit: Int,
        @Query("offset") offset: Int,
        @Query("sort") sort: String? = null,
        @Query("fields") fields: String,
    ): ResourceDto

    @GET("v1/disk/resources")
    suspend fun getResource(
        @Query("path") path: String,
        @Query("fields") fields: String,
    ): ResourceDto

    @PUT("v1/disk/resources")
    suspend fun createFolder(@Query("path") path: String): Response<ResponseBody>

    @DELETE("v1/disk/resources")
    suspend fun deleteResource(
        @Query("path") path: String,
        @Query("permanently") permanently: Boolean,
    ): Response<ResponseBody>

    @GET("v1/disk/resources/upload")
    suspend fun getUploadLink(
        @Query("path") path: String,
        @Query("overwrite") overwrite: Boolean = true,
    ): LinkDto

    @GET("v1/disk/resources/download")
    suspend fun getDownloadLink(@Query("path") path: String): LinkDto

    @PATCH("v1/disk/resources")
    @Headers("Content-Type: application/json")
    suspend fun patchResource(
        @Query("path") path: String,
        @Body body: CustomPropertiesPatchDto,
    ): Response<ResponseBody>

    @GET
    suspend fun getOperationByUrl(@Url url: String): OperationStatusDto
}
