import { buildFilterableCommerceAPIRequest } from '../../../common/filterable-commerce-api-request-builder.js';
import { getFacetIdWithoutCommerceFieldSuggestionNamespace } from '../commerce-facet-search-actions.js';
export const buildFacetSearchRequest = (facetId, state, isFieldSuggestionsRequest, navigatorContext) => {
    const baseFacetQuery = state.facetSearchSet[facetId].options.query;
    const facetQuery = `*${baseFacetQuery}*`;
    const query = !isFieldSuggestionsRequest
        ? state.commerceQuery?.query
        : baseFacetQuery;
    const { url, accessToken, organizationId, trackingId, language, country, currency, clientId, context, ...restOfCommerceAPIRequest } = buildFilterableCommerceAPIRequest(state, navigatorContext);
    return {
        url,
        accessToken,
        organizationId,
        facetId: getFacetIdWithoutCommerceFieldSuggestionNamespace(facetId),
        facetQuery: isFieldSuggestionsRequest ? '*' : facetQuery,
        trackingId,
        language,
        country,
        currency,
        clientId,
        context,
        query,
        ...(!isFieldSuggestionsRequest && { ...restOfCommerceAPIRequest }),
    };
};
