import type { SupportedCurrencies } from '@entities' import type { HttpClient } from '@services' import type { ApiError, Response } from '@types' export type HousePeriodsIdsInput = { currency?: SupportedCurrencies endDate: string maxBudget?: string minBudget?: string page?: string sortBy?: string startDate: string states?: string destinationIds?: string[] housesIds?: string[] } export type HousePeriodsIdsResponseData = { validHousePeriodsIds: number[] invalidHousePeriodsIds: number[] } const getHousePeriodsIds = (http: HttpClient) => { return { query: ({ currency = 'EUR', endDate, maxBudget = '1000000', minBudget = '0', page = 'all', sortBy = 'recommended', startDate, states, destinationIds, housesIds, }: HousePeriodsIdsInput): Promise< Response > => { const state = states ? `&states[]=${states}` : '' const destination_ids = destinationIds && destinationIds.length > 0 ? `&${destinationIds .map((id) => `destination_ids[]=${id}`) .join('&')}` : '' const house_ids = housesIds && housesIds.length > 0 ? `&${housesIds.map((id) => `house_ids[]=${id}`).join('&')}` : '' return http.get( `v3/ids/house_periods?currency=${currency}&end_at=${endDate}&max_budget=${maxBudget}&min_budget=${minBudget}&page=${page}&start_at=${startDate}&sort_by=${sortBy}${state}${destination_ids}${house_ids}`, ) }, } } export default getHousePeriodsIds