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

export const citiesApi = createApi({
    reducerPath: 'citiesApi',
    // baseQuery: fetchBaseQuery({
    //     baseUrl: 'https://testingapi.citycards.betadelivery.com',
    // }),
    baseQuery,
    endpoints: (builder) => ({

        getCityListWithBanner: builder.query({
            query: ({ search }) => {
                const params = new URLSearchParams();

                if (search) params.append('search', search);

                return `/cities/list/customer/cities?${params.toString()}`
            }
        }),

        getUpcomingCities: builder.query({
            query: (listType) => `/cities/list/all?listType=${listType}`,

        }),

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

        getSelectedCityOffers: builder.query({
            query: ({ cityId, categoryId, page, limit }) => {
                const params = new URLSearchParams()

                params.append('cityXid', cityId);

                if (categoryId) params.append('categoryXid', categoryId);
                if (page) params.append('page', page);
                if (limit) params.append('limit', limit);

                return `/website/super-savings/list/offers?${params.toString()}`;
            }
        }),

        getOfferDetailsById: builder.query({
            query: (id: number) => `/website/super-savings/list/offers/${id}`,
        }),


    }),
});

export const { useGetCityListWithBannerQuery, useGetUpcomingCitiesQuery, useGetSelectedCityDetailsQuery, useGetSelectedCityOffersQuery, useGetOfferDetailsByIdQuery } = citiesApi;