
import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQuery } from "../baseQuery";

export const cardsApi = createApi({
    reducerPath: "cardsApi",
    baseQuery,

    tagTypes: ["cardsInCart"],

    endpoints: (builder) => ({

        getCardsinCart: builder.query({
            query: (cityId) => {
                const params = new URLSearchParams()
                params.append('cityXid', cityId);
                return `/website/passes/cart/passes?${params.toString()}`
            },
            providesTags: ["cardsInCart"]
        }),

        getCheckoutPageData: builder.query({
            query: (cityId) => `/website/pass/${cityId}`,
        }),

        getCardBookingDetails: builder.query({
            query: (bookingId) => `/website/passes/${bookingId}/details`,
        }),

        storeRecipientDetails: builder.mutation({
            query: ({ recipientDetails, bookingId }) => ({ // keep the name of the variables being passed here same as when calling the mutation hook
                url: `/website/passes/${bookingId}/store-gift-details`,
                method: "PUT",
                body: recipientDetails
            }),
        }),
        addCardToCart: builder.mutation({
            query: (cardBookingDetails) => ({ // keep the name of the variables being passed here same as when calling the mutation hook
                url: `/website/passes/add-to-cart`,
                method: "POST",
                body: cardBookingDetails
            }),
        }),

        payForCard: builder.mutation({
            query: (id) => ({ 
                url: `/website/passes/${id}/pay`,
                method: "POST",
                body: {},
            }),
        }),

        confirmCardPayment: builder.mutation({
            query: (id) => ({ 
                url: `/website/passes/${id}/confirm-payment`,
                method: "POST",
                // body: id,
            }),
        }),






    }),
});

export const {
    useGetCardsinCartQuery,
    useGetCheckoutPageDataQuery,
    useGetCardBookingDetailsQuery,
    useStoreRecipientDetailsMutation,
    useAddCardToCartMutation,
    usePayForCardMutation,
    useConfirmCardPaymentMutation

} = cardsApi;