import { Announcement } from '../api/announcement/types'

const filterNames = ['userId', 'category', 'metro', 'bookedBy'] as const
type FilterNames = typeof filterNames[number]

type FiltersType = Partial<Pick<Announcement, FilterNames>>

const defaultFilters: FiltersType = { userId: undefined, category: undefined, metro: undefined, bookedBy: undefined }

const URLEncodeFilters = (filters: FiltersType) => Object.fromEntries(
    filterNames.map(
        fName => [fName, filters[fName]?.toString()]
    ).filter((p): p is [string, string] => typeof p[1] !== 'undefined')
)

export type { FilterNames, FiltersType }
export { defaultFilters, filterNames, URLEncodeFilters }
