package com.radiola.data.remote

import com.radiola.data.remote.dto.AuthResponseDto
import com.radiola.data.remote.dto.BackendNowPlayingDto
import com.radiola.data.remote.dto.BackendStationDto
import com.radiola.data.remote.dto.ChartsResponseDto
import com.radiola.data.remote.dto.GenresResponseDto
import com.radiola.data.remote.dto.HistoryResponseDto
import com.radiola.data.remote.dto.MagicLinkRequestDto
import com.radiola.data.remote.dto.MagicLinkVerifyDto
import com.radiola.data.remote.dto.TrackStatsDto
import com.radiola.data.remote.dto.UserSettingsDto
import kotlinx.serialization.json.JsonObject
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PATCH
import retrofit2.http.Path
import retrofit2.http.Query

interface RadiolaApi {

    @POST("auth/magic-link")
    suspend fun requestMagicLink(@Body dto: MagicLinkRequestDto): JsonObject

    @POST("auth/verify")
    suspend fun verifyMagicLink(@Body dto: MagicLinkVerifyDto): AuthResponseDto

    @GET("now-playing")
    suspend fun getNowPlaying(): List<BackendNowPlayingDto>

    // Сабмит обложки, найденной клиентом в iTunes (см. CoverEnrichmentManager).
    @POST("covers/submit")
    suspend fun submitCover(@Body dto: com.radiola.data.remote.dto.SubmitCoverDto): com.radiola.data.remote.dto.SubmitCoverResponse

    // station_id оффлайн-станций — скрываем их в каталоге (мёртвые потоки)
    @GET("stations/offline-ids")
    suspend fun getOfflineStationIds(): List<Int>

    @GET("users/me")
    suspend fun getMe(): JsonObject

    @GET("users/me/settings")
    suspend fun getSettings(): UserSettingsDto

    @PATCH("users/me/settings")
    suspend fun updateSettings(@Body dto: UserSettingsDto): UserSettingsDto

    @GET("users/me/favorites")
    suspend fun getFavorites(): List<BackendStationDto>

    @POST("users/me/favorites/{stationId}")
    suspend fun addFavorite(@Path("stationId") stationId: String): JsonObject

    @DELETE("users/me/favorites/{stationId}")
    suspend fun removeFavorite(@Path("stationId") stationId: String): JsonObject

    @GET("users/me/history")
    suspend fun getHistory(): HistoryResponseDto

    @POST("users/me/history/{stationId}")
    suspend fun addHistory(@Path("stationId") stationId: String): JsonObject

    // --- Чарты ---

    @GET("charts/tracks")
    suspend fun getCharts(
        @Query("period") period: String,
        @Query("limit") limit: Int = 100,
        @Query("genre") genre: String? = null
    ): ChartsResponseDto

    @GET("charts/genres")
    suspend fun getGenres(): GenresResponseDto

    @GET("charts/tracks/{trackId}")
    suspend fun getTrackStats(@Path("trackId") trackId: String): TrackStatsDto

    @POST("charts/tracks/{trackId}/like")
    suspend fun likeTrack(@Path("trackId") trackId: String): JsonObject

    @DELETE("charts/tracks/{trackId}/like")
    suspend fun unlikeTrack(@Path("trackId") trackId: String): JsonObject
}
