package id.iiyh.inatrading.core.data.remote

import id.iiyh.inatrading.core.data.remote.model.ApiResponse
import id.iiyh.inatrading.core.data.remote.model.LoginData
import id.iiyh.inatrading.feature.auth.data.model.RegisterRequest
import id.iiyh.inatrading.feature.cart.data.model.CartCreateRequest
import id.iiyh.inatrading.feature.cart.data.model.CartListResponse
import id.iiyh.inatrading.feature.cart.data.model.CartUpdateRequest
import id.iiyh.inatrading.feature.favorite.data.model.FavoriteCreateRequest
import id.iiyh.inatrading.feature.favorite.data.model.FavoriteItemsResponse
import id.iiyh.inatrading.feature.favorite.data.model.FavoriteListResponse
import id.iiyh.inatrading.feature.favorite.data.model.AddToFavoriteRequest
import id.iiyh.inatrading.feature.explore.data.model.LocationListResponse
import id.iiyh.inatrading.feature.news.data.model.NewsListResponse
import id.iiyh.inatrading.feature.profile.data.model.BuyerProfile
import id.iiyh.inatrading.feature.profile.data.model.CityListResponse
import id.iiyh.inatrading.feature.profile.data.model.ChangePasswordRequest
import id.iiyh.inatrading.feature.profile.data.model.CreateShippingAddressRequest
import id.iiyh.inatrading.feature.profile.data.model.FileUploadData
import id.iiyh.inatrading.feature.profile.data.model.ProvinceListResponse
import id.iiyh.inatrading.feature.profile.data.model.ShippingAddressListResponse
import id.iiyh.inatrading.feature.profile.data.model.UpdateBuyerProfileRequest
import id.iiyh.inatrading.feature.product.data.model.ProductDetailResponse
import id.iiyh.inatrading.feature.product.data.model.ProductListResponse
import okhttp3.MultipartBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Part
import retrofit2.http.Query
import retrofit2.http.PUT

interface ApiService {

    @POST("api/v1.0/buyer/login")
    suspend fun loginBuyer(
        @Header("Authorization") basicAuth: String,
    ): ApiResponse<LoginData>

    @POST("api/v1.0/buyer/register")
    suspend fun registerBuyer(
        @Body request: RegisterRequest,
    ): ApiResponse<Unit?>

    @GET("api/v1.0/seller/profile")
    suspend fun getBuyerProfile(): ApiResponse<BuyerProfile>

    @GET("api/v1.0/addresses")
    suspend fun getAddresses(): ShippingAddressListResponse

    @GET("api/v1.0/provinces")
    suspend fun getProvinces(
        @Query("page") page: Int,
        @Query("limit") limit: Int,
    ): ProvinceListResponse

    @GET("api/v1.0/cities")
    suspend fun getCities(
        @Query("provinceId") provinceId: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,
    ): CityListResponse

    @POST("api/v1.0/addresses")
    suspend fun createAddress(
        @Body request: CreateShippingAddressRequest,
    ): ApiResponse<Unit?>

    @PUT("api/v1.0/addresses/{addressId}")
    suspend fun updateAddress(
        @Path("addressId") addressId: String,
        @Body request: CreateShippingAddressRequest,
    ): ApiResponse<Unit?>

    @DELETE("api/v1.0/addresses/{addressId}")
    suspend fun deleteAddress(
        @Path("addressId") addressId: String,
    ): ApiResponse<Unit?>

    @PUT("api/v1.0/seller/profile")
    suspend fun updateBuyerProfile(
        @Body request: UpdateBuyerProfileRequest,
    ): ApiResponse<Unit?>

    @PUT("api/v1.0/profile/change-password")
    suspend fun changePassword(
        @Body request: ChangePasswordRequest,
    ): ApiResponse<Unit?>

    @Multipart
    @POST("api/v1.0/file/upload")
    suspend fun uploadFile(
        @Part file: MultipartBody.Part,
    ): ApiResponse<FileUploadData>

    @GET("api/v1.0/newsarticles")
    suspend fun getNewsArticles(): NewsListResponse

    @GET("api/v1.0/product")
    suspend fun getProducts(
        @Query("page") page: Int,
        @Query("limit") limit: Int,
    ): ProductListResponse

    @GET("api/v1.0/locations")
    suspend fun getLocations(
        @Query("page") page: Int,
        @Query("limit") limit: Int,
    ): LocationListResponse

    @GET("api/v1.0/product/{productId}")
    suspend fun getProductDetail(
        @Path("productId") productId: String,
    ): ProductDetailResponse

    @GET("api/v1.0/favorites")
    suspend fun getFavorites(): FavoriteListResponse

    @GET("api/v1.0/carts")
    suspend fun getCarts(): CartListResponse

    @POST("api/v1.0/cart")
    suspend fun createCart(
        @Body request: CartCreateRequest,
    ): ApiResponse<Unit?>

    @PUT("api/v1.0/cart")
    suspend fun updateCart(
        @Body request: CartUpdateRequest,
    ): ApiResponse<Unit?>

    @GET("api/v1.0/favorite/item/{favoriteId}")
    suspend fun getFavoriteItems(
        @Path("favoriteId") favoriteId: String,
    ): FavoriteItemsResponse

    @POST("api/v1.0/favorite")
    suspend fun createFavorite(
        @Body request: FavoriteCreateRequest,
    ): ApiResponse<Unit?>

    @PUT("api/v1.0/favorite/{favoriteId}")
    suspend fun updateFavorite(
        @Path("favoriteId") favoriteId: String,
        @Body request: FavoriteCreateRequest,
    ): ApiResponse<Unit?>

    @DELETE("api/v1.0/favorite/product/{productId}")
    suspend fun deleteFavoriteItem(
        @Path("productId") productId: String,
    ): ApiResponse<Unit?>

    @POST("api/v1.0/favorite/add")
    suspend fun addToFavorite(
        @Body request: AddToFavoriteRequest,
    ): ApiResponse<Unit?>
}
