package com.jiooption.trading.network

import com.jiooption.trading.network.models.*
import retrofit2.Response
import retrofit2.http.*

/**
 * Retrofit API endpoints interface
 */
interface ApiService {

    // ========== Authentication ==========

    @FormUrlEncoded
    @POST("user/login.php")
    suspend fun login(
        @Field("email") email: String,
        @Field("password") password: String
    ): Response<ApiResponse<UserData>>

    @FormUrlEncoded
    @POST("user/register.php")
    suspend fun register(
        @Field("name") name: String,
        @Field("email") email: String,
        @Field("phone") phone: String,
        @Field("password") password: String,
        @Field("confirm_password") confirmPassword: String
    ): Response<ApiResponse<UserData>>

    // ========== User ==========

    @GET("user/balance.php")
    suspend fun getBalance(): Response<BalanceResponse>

    @GET("user/app-config.php")
    suspend fun getAppConfig(): Response<AppConfigResponse>

    // ========== Trading ==========

    @FormUrlEncoded
    @POST("trade/place.php")
    suspend fun placeTrade(
        @Field("asset") asset: String,
        @Field("amount") amount: Double,
        @Field("direction") direction: String,
        @Field("duration") duration: Int,
        @Field("is_demo") isDemo: Int = 0
    ): Response<ApiResponse<TradeData>>

    @GET("trade/active.php")
    suspend fun getActiveTrades(): Response<ApiResponse<List<TradeData>>>

    @FormUrlEncoded
    @POST("trade/close.php")
    suspend fun closeTrade(
        @Field("trade_id") tradeId: String
    ): Response<ApiResponse<TradeData>>

    // ========== Payments ==========

    @POST("payment/google-play-verify.php")
    suspend fun verifyGooglePlayPurchase(
        @Body request: GooglePlayVerifyRequest
    ): Response<ApiResponse<DepositData>>

    @FormUrlEncoded
    @POST("payment/create.php")
    suspend fun createPayment(
        @Field("amount") amount: Double,
        @Field("method") method: String = "upi"
    ): Response<ApiResponse<PaymentData>>

    @GET("payment/check.php")
    suspend fun checkPayment(
        @Query("payment_id") paymentId: String
    ): Response<ApiResponse<PaymentData>>

    // ========== Device / Push Notifications ==========

    @POST("user/device-register.php")
    suspend fun registerDevice(
        @Body request: DeviceRegisterRequest
    ): Response<ApiResponse<Nothing>>

    @POST("user/device-unregister.php")
    suspend fun unregisterDevice(
        @Body request: DeviceUnregisterRequest
    ): Response<ApiResponse<Nothing>>

    // ========== Notifications ==========

    @GET("notifications/list.php")
    suspend fun getNotifications(
        @Query("page") page: Int = 1,
        @Query("limit") limit: Int = 20
    ): Response<NotificationsResponse>

    @POST("notifications/mark-read.php")
    suspend fun markNotificationRead(
        @Body request: MarkReadRequest
    ): Response<ApiResponse<Nothing>>
}
