package kr.co.vividnext.sodalive.live

import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.core.Single
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.live.reservation.MakeLiveReservationRequest
import kr.co.vividnext.sodalive.live.reservation.MakeLiveReservationResponse
import kr.co.vividnext.sodalive.live.reservation_status.CancelLiveReservationRequest
import kr.co.vividnext.sodalive.live.reservation_status.GetLiveReservationResponse
import kr.co.vividnext.sodalive.live.room.CancelLiveRequest
import kr.co.vividnext.sodalive.live.room.EnterOrQuitLiveRoomRequest
import kr.co.vividnext.sodalive.live.room.LiveRoomStatus
import kr.co.vividnext.sodalive.live.room.SetManagerOrSpeakerOrAudienceRequest
import kr.co.vividnext.sodalive.live.room.StartLiveRequest
import kr.co.vividnext.sodalive.live.room.create.CreateLiveRoomResponse
import kr.co.vividnext.sodalive.live.room.create.GetRecentRoomInfoResponse
import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailResponse
import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser
import kr.co.vividnext.sodalive.live.room.donation.DeleteLiveRoomDonationMessage
import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationStatusResponse
import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationTotalResponse
import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationMessage
import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationRequest
import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationResponse
import kr.co.vividnext.sodalive.live.room.info.GetRoomInfoResponse
import kr.co.vividnext.sodalive.live.room.kick_out.LiveRoomKickOutRequest
import kr.co.vividnext.sodalive.live.room.like.GetLiveRoomHeartListResponse
import kr.co.vividnext.sodalive.live.room.like.GetLiveRoomHeartTotalResponse
import kr.co.vividnext.sodalive.live.room.like.LiveRoomLikeHeartRequest
import kr.co.vividnext.sodalive.live.room.profile.GetLiveRoomUserProfileResponse
import kr.co.vividnext.sodalive.live.room.tag.GetLiveTagResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.HTTP
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

interface LiveApi {
    @GET("/live/tag")
    fun getTags(
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<List<GetLiveTagResponse>>>

    @GET("/live/room")
    fun roomList(
        @Query("timezone") timezone: String,
        @Query("dateString") dateString: String?,
        @Query("status") status: LiveRoomStatus,
        @Query("isAdultContentVisible") isAdultContentVisible: Boolean,
        @Query("page") page: Int,
        @Query("size") size: Int,
        @Header("Authorization") authHeader: String
    ): Flowable<ApiResponse<List<GetRoomListResponse>>>

    @GET("/live/room/detail/{id}")
    fun getRoomDetail(
        @Path("id") id: Long,
        @Query("timezone") timezone: String,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetRoomDetailResponse>>

    @GET("/live/room/recent-room-info")
    fun getRecentRoomInfo(
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetRecentRoomInfoResponse>>

    @POST("/live/room")
    @Multipart
    fun createRoom(
        @Part coverImage: MultipartBody.Part?,
        @Part("request") request: RequestBody,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<CreateLiveRoomResponse>>

    @PUT("/live/room/start")
    fun startLive(
        @Body request: StartLiveRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @PUT("/live/room/cancel")
    fun cancelLive(
        @Body request: CancelLiveRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/room/enter")
    fun enterRoom(
        @Body request: EnterOrQuitLiveRoomRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/reservation")
    fun makeReservation(
        @Body request: MakeLiveReservationRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<MakeLiveReservationResponse>>

    @PUT("/live/room/{id}")
    @Multipart
    fun editLiveRoomInfo(
        @Path("id") id: Long,
        @Part coverImage: MultipartBody.Part?,
        @Part("request") request: RequestBody?,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @GET("/live/room/info/{id}")
    fun getRoomInfo(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetRoomInfoResponse>>

    @GET("/live/room/donation-message")
    fun getDonationMessageList(
        @Query("roomId") roomId: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<List<LiveRoomDonationMessage>>>

    @HTTP(method = "DELETE", path = "/live/room/donation-message", hasBody = true)
    fun deleteDonationMessage(
        @Body request: DeleteLiveRoomDonationMessage,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @GET("/live/room/{room_id}/profile/{user_id}")
    fun getUserProfile(
        @Path("room_id") roomId: Long,
        @Path("user_id") userId: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveRoomUserProfileResponse>>

    @GET("/live/room/{id}/donation-total")
    fun getDonationTotal(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveRoomDonationTotalResponse>>

    @PUT("/live/room/info/set/speaker")
    fun setSpeaker(
        @Body request: SetManagerOrSpeakerOrAudienceRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @PUT("/live/room/info/set/listener")
    fun setListener(
        @Body request: SetManagerOrSpeakerOrAudienceRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/room/kick-out")
    fun kickOut(
        @Body request: LiveRoomKickOutRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/room/donation/v2")
    fun donation(
        @Body request: LiveRoomDonationRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<LiveRoomDonationResponse>>

    @POST("/live/room/donation/refund/{id}")
    fun refundDonation(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/room/quit")
    fun quitRoom(
        @Query("id") roomId: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @PUT("/live/room/info/set/manager")
    fun setManager(
        @Body request: SetManagerOrSpeakerOrAudienceRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @GET("/live/room/{id}/donation-list")
    fun donationStatus(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveRoomDonationStatusResponse>>

    @GET("/live/room/recent_visit_room/users")
    fun recentVisitRoomUsers(
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<List<GetRoomDetailUser>>>

    @GET("/live/reservation")
    fun getReservations(
        @Query("timezone") timezone: String,
        @Query("isActive") active: Boolean,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<List<GetLiveReservationResponse>>>

    @GET("/live/reservation/{id}")
    fun getReservation(
        @Path("id") id: Long,
        @Query("timezone") timezone: String,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveReservationResponse>>

    @PUT("/live/reservation/cancel")
    fun cancelReservation(
        @Body request: CancelLiveReservationRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @POST("/live/room/like-heart")
    fun likeHeart(
        @Body request: LiveRoomLikeHeartRequest,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<Any>>

    @GET("/live/room/{id}/heart-total")
    fun getTotalHeartCount(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveRoomHeartTotalResponse>>

    @GET("/live/room/{id}/heart-list")
    fun heartStatus(
        @Path("id") id: Long,
        @Header("Authorization") authHeader: String
    ): Single<ApiResponse<GetLiveRoomHeartListResponse>>
}
