package com.dxb.app.urbanmop.network

import com.dxb.app.urbanmop.data.master.cms.GetPageResponse
import com.dxb.app.urbanmop.models.CommonResponse
import com.dxb.app.urbanmop.models.addItemCart.AddAllSlotTime
import com.dxb.app.urbanmop.models.addItemCart.ModifyAllSlotTime
import com.dxb.app.urbanmop.models.addressResponse.AddAddressResponse
import com.dxb.app.urbanmop.models.addressResponse.AddressListingResponse
import com.dxb.app.urbanmop.models.addressResponse.AddressUpdateResponse
import com.dxb.app.urbanmop.models.addressResponse.CityResponse
import com.dxb.app.urbanmop.models.addressResponse.DeleteAddressResponse
import com.dxb.app.urbanmop.models.booking.BookingDetailResponse
import com.dxb.app.urbanmop.models.booking.BookingListingResponse
import com.dxb.app.urbanmop.models.booking.BookingPriceDetailResponse
import com.dxb.app.urbanmop.models.booking.reviewBooking.ReviewBooking
import com.dxb.app.urbanmop.models.cart.CartResponse
import com.dxb.app.urbanmop.models.cart.DeleteCartResponse
import com.dxb.app.urbanmop.models.checkout.ApplyTipResponse
import com.dxb.app.urbanmop.models.checkout.CheckoutDataResponse
import com.dxb.app.urbanmop.models.checkout.CheckoutResponse
import com.dxb.app.urbanmop.models.checkout.CouponAppliedResponse
import com.dxb.app.urbanmop.models.checkout.PaymentInitResponse
import com.dxb.app.urbanmop.models.checkout.TipResponse
import com.dxb.app.urbanmop.models.confirmDetail.ConfirmDetailResponse
import com.dxb.app.urbanmop.models.contactSupport.ContactUsResponse
import com.dxb.app.urbanmop.models.homeMode.HomeResponse
import com.dxb.app.urbanmop.models.homeMode.HomeSettingsResponse
import com.dxb.app.urbanmop.models.loginModel.LoginResponse
import com.dxb.app.urbanmop.models.loginModel.LogoutRespons
import com.dxb.app.urbanmop.models.preferedDays.PreferedDaysResponse
import com.dxb.app.urbanmop.models.rewards.MyRewardsResponse
import com.dxb.app.urbanmop.models.searchService.SearchServiceResponse
import com.dxb.app.urbanmop.models.searchService.TrendingRecentResponse
import com.dxb.app.urbanmop.models.serviceDetails.GetPriceResponse
import com.dxb.app.urbanmop.models.serviceDetails.ServiceDetailsResponse
import com.dxb.app.urbanmop.models.serviceDetails.cardStore.CardResponse2
import com.dxb.app.urbanmop.models.serviceDetails.cardStore.CardStoreResponse
import com.dxb.app.urbanmop.models.serviceDetails.cardStore.CartResponse3
import com.dxb.app.urbanmop.models.sessionHistory.SessionHistoryResponse
import com.dxb.app.urbanmop.models.slots.SlotsResponse
import com.dxb.app.urbanmop.models.slots.UpdateTimeSlotResponse
import com.dxb.app.urbanmop.models.verifyOtp.VerifyOtpResponse
import com.dxb.app.urbanmop.models.walletRecharge.WalletDisplayResponse
import com.dxb.app.urbanmop.utils.Constants
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path

interface ApiService {

    @POST("cms/page")
    @FormUrlEncoded
    suspend fun getPage(
        @Field("id") page_id: String,
    ): Response<GetPageResponse>

    @POST("login_otp")
    @FormUrlEncoded
    suspend fun login(
        @Field("phone") phone: String,
        @Field("dial_code") dial_code: String,
    ): Response<LoginResponse>

    @POST("verify_otp")
    @FormUrlEncoded
    suspend fun verifyOtp(
        @Field("phone") phone: String,
        @Field("otp") otp: String,
        @Field("user_device_token") user_device_token: String,
        @Field("user_device_type") user_device_type: String,
        @Field("device_cart_id") device_cart_id: String,
        @Field("dial_code") dial_code: String,
    ): Response<VerifyOtpResponse>

    @POST("resend_otp")
    @FormUrlEncoded
    suspend fun resendOtp(@Field("phone") phone: String): Response<VerifyOtpResponse>

    @POST("register")
    @Multipart
    suspend fun register(
        @Part("phone") phone: RequestBody,
        @Part("role") role: RequestBody,
        @Part("email") email: RequestBody,
        @Part("name") name: RequestBody,
        @Part("dial_code") dial_code: RequestBody,
        @Part("DOB") DOB: RequestBody,
        @Part("gender") gender: RequestBody,
        @Part fileImage: MultipartBody.Part? = null,
        @Part("invite_code") invite_code: RequestBody,
    ): Response<VerifyOtpResponse>

    @GET("home")
    suspend fun home(): Response<HomeResponse>
    @GET("home/setting")
    suspend fun homeSettings(): Response<HomeSettingsResponse>

    @POST("store/address")
    @FormUrlEncoded
    suspend fun addAddress(
        @Header("Authorization") token: String,
        @Field("address") address: String,
        @Field("address_type") address_type: String,
        @Field("flat_no") flat_no: String,
        @Field("building") building: String,
        @Field("locality_id") locality_id: String,
        @Field("latitude") latitude: String,
        @Field("longitude") longitude: String,
        @Field("city_id") city_id: String,

        ): Response<AddAddressResponse>


    @POST("edit/address/{id}")
    @FormUrlEncoded
    suspend fun updateAddress(
        @Header("Authorization") token: String,
        @Path("id") id: String,
        @Field("address") address: String,
        @Field("address_type") address_type: String,
        @Field("flat_no") flat_no: String,
        @Field("building") building: String,
        @Field("locality_id") locality_id: String,
        @Field("latitude") latitude: String,
        @Field("longitude") longitude: String,
        @Field("city_id") city_id: String,

        ): Response<AddAddressResponse>


    // GET request with dynamic path for the ID
    @POST("service/details/{id}")
    @FormUrlEncoded
    suspend fun getServiceDetails(
        @Path("id") id: String,
        @Field("item_object") item_object: String? = null,
    ): Response<ServiceDetailsResponse>



    @GET("get/city")
    suspend fun getCity(): Response<CityResponse>

    @POST("get/locality")
    @FormUrlEncoded
    suspend fun getLocality(
        @Field("city_id") city_id: String,
    ): Response<CityResponse>



    @POST("card/store")
    @FormUrlEncoded
    suspend fun cardStore2(
        @Header("Authorization") token: String,
        @Field("address_id") address_id: String,
        @Field("alternative_number") alternative_number: String,
        @Field("cart_id") cart_id: String,
        @Field("dial_code") dial_code: String,
    ): Response<CardResponse2>

    @POST("card/store")
    @FormUrlEncoded
    suspend fun cartStore3(
        @Header("Authorization") token: String,
        @Field("preffered_days") preffered_days: String="",
        @Field("cart_id") cart_id: String,
        @Field("slot_id") slot_id: String,
        @Field("is_revisit") is_revisit: String,
        @Field("date") date: String
    ): Response<CartResponse3>

    @GET("user/address")
    suspend fun addressListing(
        @Header("Authorization") token: String,
    ): Response<AddressListingResponse>

    @POST("update_address/{id}")

    suspend fun updateAddress(
        @Path("id") id: String,
        @Header("Authorization") token: String
    ): Response<AddressUpdateResponse>

    @POST("user_info")
    @FormUrlEncoded
    suspend fun getProfile(
        @Header("Authorization") token: String,
        @Field("user_id") user_id: String,
    ): Response<VerifyOtpResponse>

    @POST("profile_update")
    @Multipart
    suspend fun updateProfile(
        @Header("Authorization") token: String,
        @Part("name") name: RequestBody,
        @Part("email") email: RequestBody,
        @Part("phone") phone: RequestBody,
        @Part("DOB") DOB: RequestBody,
        @Part("gender") gender: RequestBody,
        @Part("dial_code") dial_code: RequestBody,
        @Part fileImage: MultipartBody.Part? = null,

        ): Response<CommonResponse>
    @POST("resend_otp_profile")
    @FormUrlEncoded
    suspend fun resendOTPForPhoneUpdate(
        @Header("Authorization") token: String,
        @Field("phone") phone: String,
        @Field("dial_code") dial_code: String,
        ): Response<CommonResponse>

    @POST("phone_verify")
    @FormUrlEncoded
    suspend fun verifyOTPForPhoneUpdate(
        @Header("Authorization") token: String,
        @Field("phone") phone: String,
        @Field("dial_code") dial_code: String,
        @Field("otp") otp: String,
    ): Response<CommonResponse>


    @DELETE("delete_address/{id1}/{id2}")
    suspend fun deleteAddress(
        @Path("id1") id1: String,
        @Path("id2") id2: String,
        @Header("Authorization") token: String
    ): Response<DeleteAddressResponse>

    @POST("slots")
    @FormUrlEncoded
    suspend fun slots(
        @Field("date") date: String,
        @Field("service_id") service_id: String,
    ): Response<SlotsResponse>



    @POST("confirm_details")
    @FormUrlEncoded
    suspend fun confirmBooking(
        @Header("Authorization") token: String,
        @Field("cart_id") cart_id: String
    ): Response<ConfirmDetailResponse>

    @GET("preffered_days")
    suspend fun preferDay(): Response<PreferedDaysResponse>

    @GET("logout")
    suspend fun logout(
        @Header("Authorization") token: String
    ): Response<LogoutRespons>

    @POST("get/cards")
    suspend fun getCart(
        @Header("Authorization") token: String
    ): Response<CartResponse>

    @POST("reorder")
    @FormUrlEncoded
    suspend fun reorder(
        @Header("Authorization") token: String,
        @Field("card_id") card_id: String,
    ): Response<CommonResponse>

    @POST("delete/bookings/user")
    @FormUrlEncoded
    suspend fun deleteCart(
        @Header("Authorization") token: String,
        @Field("card_id") card_id: String,
    ): Response<DeleteCartResponse>

    @GET("get/tips")
    suspend fun getTips(
        @Header("Authorization") token: String
    ): Response<TipResponse>

    @POST("apply/tip")
    @FormUrlEncoded
    suspend fun applyTip(
        @Header("Authorization") token: String,
        @Field("tip_amount") tip_amount: String,
    ): Response<ApplyTipResponse>

    @POST("checkout/data")   // THis API is being called to show amount break down  from cart screen , checkout , confirm details , success
    @FormUrlEncoded
    suspend fun getCheckOutData(
        @Header("Authorization") token: String,
        @Field("tip_amount") tip_amount: String,
        @Field("coupon_code") coupon_code: String,
        @Field("payment_type") payment_type:String?
    ): Response<CheckoutDataResponse>

    @POST("payment/update")
    @FormUrlEncoded
    suspend fun checkOutPayment(
        @Header("Authorization") token: String,
        @Field("order_id") order_id: String,
        @Field("transaction_ref") transaction_ref: String?
    ): Response<CheckoutResponse>

    @POST("checkout/go")
    suspend fun checkoutGo(
        @Header("Authorization") token: String,
    ): Response<DeleteCartResponse>

    @POST("get/my/bookings")
    @FormUrlEncoded
    suspend fun getBookings(
        @Header("Authorization") token: String,
        @Field("limit") limit: String = Constants.PageLimit.toString(),
        @Field("page") page: String,

        ): Response<BookingListingResponse>

    @POST("my_rewards")
    suspend fun myRewards(
        @Header("Authorization") token: String
    ): Response<MyRewardsResponse>


    @GET("get/card/info/{id}")
    suspend fun bookingDetail(
        @Path("id") id: String,
        @Header("Authorization") token: String
    ): Response<BookingDetailResponse>

    @POST("booking/canceled")
    @FormUrlEncoded
    suspend fun deleteBooking(
        @Header("Authorization") token: String,
        @Field("booking_id") booking_id: String,
    ): Response<CommonResponse>
    @POST("cancel_charges")
    @FormUrlEncoded
    suspend fun preCancelAPI(
        @Header("Authorization") token: String,
        @Field("booking_id") booking_id: String,
    ): Response<CommonResponse>


    @POST("contacts")
    @FormUrlEncoded
    suspend fun contacts(
        @Header("Authorization") token: String,
        @Field("name") name: String,
        @Field("email") email: String,
        @Field("message") message: String,
    ): Response<ContactUsResponse>

    @POST("change/slot/time")
    @FormUrlEncoded
    suspend fun updateSlots(
        @Header("Authorization") token: String,
        @Field("cart_id") cart_id: String,
        @Field("slot_id") slot_id: String,
        @Field("date") date: String,
    ): Response<DeleteCartResponse>
    @POST("revisit")
    @FormUrlEncoded
    suspend fun createRevisit(
        @Header("Authorization") token: String,
        @Field("old_booking_id") old_booking_id: String,
        @Field("slot") slot_id: String,
        @Field("date") date: String,
    ): Response<CommonResponse>




    @POST("wallet_payment_init")
    @FormUrlEncoded
    suspend fun paymentInit(
        @Header("Authorization") token: String,
        @Field("payment_type") payment_type: String,
        @Field("coupon_code") coupon_code: String,
        @Field("tip_amount") tip_amount: String,

        ): Response<PaymentInitResponse>


    @POST("wallet_init")
    @FormUrlEncoded
    suspend fun walletPaymentInit(
        @Header("Authorization") token: String,
        @Field("amount") amount: String,
        @Field("payment_type") payment_type: String
    ): Response<PaymentInitResponse>


    @POST("wallet_recharge")
    @FormUrlEncoded
    suspend fun walletRecharge(
        @Header("Authorization") token: String,
        @Field("invoice_id") invoice_id: String,
        @Field("transaction_ref") transaction_ref: String?
    ): Response<UpdateTimeSlotResponse>

    @POST("wallet_details")
    @FormUrlEncoded
    suspend fun walletDisplay(
        @Header("Authorization") token: String,
        @Field("limit") limit: String = Constants.PageLimit.toString(),
        @Field("page") page: String,
    ): Response<WalletDisplayResponse>

    @POST("get_selected_price_by_card")
    @FormUrlEncoded
    suspend fun getBookingPrice(
        @Header("Authorization") token: String,
        @Field("cart_id") card_id: String,
    ): Response<BookingPriceDetailResponse>


    @POST("search/services")
    @FormUrlEncoded
    suspend fun searchService(
        @Field("search") search: String,
        @Field("limit") limit: String = Constants.PageLimit.toString(),
        @Field("page") page: String,
    ): Response<SearchServiceResponse>


    @GET("search/services/trends")
    suspend fun tendSearch(
    ): Response<TrendingRecentResponse>


    @POST("card/store")
    @Multipart
    suspend fun singleBookingAPI(
        @Header("Authorization") token: String,
        @Part("material_status") material_status: RequestBody? = null,
        @Part("selected_packages") selected_packages: RequestBody? = null,
        @Part("item_object") item_object: RequestBody? = null,
        @Part("service_id") service_id: RequestBody? = null,
        @Part("preffered_days") preffered_days: RequestBody? = null,
        @Part("card_id") card_id: RequestBody? = null,
        @Part("cart_id") cart_id: RequestBody? = null,
        @Part("slot_id") slot_id: RequestBody? = null,
        @Part("alternative_number") alternative_number: RequestBody? = null,
        @Part("dial_code") dial_code: RequestBody? = null,
        @Part("note") note: RequestBody? = null,
        @Part("address_id") address_id: RequestBody? = null,
        @Part("category_id") category_id: RequestBody?=null,
    ): Response<CardStoreResponse>

    @POST("card/store")
    suspend fun addTimeForSession(
        @Header("Authorization") token: String,
        @Body addAllSlotTime: AddAllSlotTime
    ): Response<CommonResponse>
    @POST("change/slot/time/session")
    suspend fun updateSlotsSession(
        @Header("Authorization") token: String,
        @Body modifyAllSlotTime: ModifyAllSlotTime
    ): Response<CommonResponse>

    @POST("get_selected_price")
    @FormUrlEncoded
    suspend fun singlePriceAPI(
        @Field("material_status") material_status: String? = null,
        @Field("selected_packages") selected_packages: String? = null,
        @Field("item_object") item_object: String? = null,
        @Field("service_id") service_id: String,
    ): Response<GetPriceResponse>

    @POST("review-submit")
    @FormUrlEncoded
    suspend fun makeReview(
        @Header("Authorization") token: String,
        @Field("booking_id") booking_id: String? = null,
        @Field("service_id") service_id: String? = null,
        @Field("rating") rating: String? = null,
        @Field("opinion") opinion: String? = null,

        ): Response<ReviewBooking>

    @POST("get/session/history/{card_id}")
    suspend fun getSessionHistory(
        @Path("card_id") card_id: String,
        @Header("Authorization") token: String
    ):Response<SessionHistoryResponse>

    @POST("send/notification")
    @FormUrlEncoded
    suspend fun sendNotification(
        @Header("Authorization") token: String,
        @Field("title") title: String,
        @Field("body") body: String,
        @Field("data") data: String,
        @Field("user_id") user_id: String,
    ):Response<CommonResponse>
}

