import { z } from 'zod'; import { ListSchema } from './common'; import type { PaginationQuery, SortQuery } from './query'; export const VenueAddressSchema = z.object({ street: z.string(), houseNumber: z.string(), postalCode: z.string(), city: z.string(), country: z.string().regex(/^[A-Z]{2}$/gm), latitude: z.number().nullable(), longitude: z.number().nullable(), }); export type VenueAddress = z.infer; export const VenueSchema = z.object({ id: z.uuid(), name: z.string().min(1), address: VenueAddressSchema, slug: z.string().min(1), assets: z.any().optional(), isHidden: z.boolean(), attributes: z.any().optional(), localizableAttributes: z.any().optional(), createdAt: z.string(), // this differs from backend, backend needs to be adjusted in the future updatedAt: z.string(), // this differs from backend, backend needs to be adjusted in the future }); export type Venue = z.infer; export const VenueCreateInputSchema = VenueSchema.pick({ name: true, slug: true, address: true, isHidden: true, attributes: true, localizableAttributes: true, }); export type VenueCreateInput = z.infer; export const VenueUpdateInputSchema = VenueSchema.pick({ name: true, slug: true, address: true, isHidden: true, attributes: true, localizableAttributes: true, }); export type VenueUpdateInput = z.infer; export const VenueHalSchema = VenueSchema.pick({ id: true, name: true, address: true, slug: true, assets: true, isHidden: true, attributes: true, localizableAttributes: true, createdAt: true, updatedAt: true, }).extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), }); export type VenueHalSchemaType = z.infer; // not present in backend yet export const VenuesHalListSchema = ListSchema.extend({ _embedded: z.object({ venues: z.array(VenueHalSchema), }), }); export type VenueHalListSchemaType = z.infer; // not present in backend yet export type VenueListQuery = VenueFilterQuery & VenueSortQuery & PaginationQuery; // TODO extract common filter groups like StringFilter, IdFilter, CollectionFilter... export type VenueFilterQuery = { id?: { eq?: string; neq?: string; in?: string[]; nin?: string[]; }; name?: { eq?: string; neq?: string; in?: string[]; nin?: string[]; contains?: string; }; slug?: { eq?: string; neq?: string; in?: string[]; nin?: string[]; contains?: string; }; city?: { eq?: string; neq?: string; in?: string[]; nin?: string[]; contains?: string; }; country?: { eq?: string; neq?: string; in?: string[]; nin?: string[]; contains?: string; }; isHidden?: { eq?: boolean; }; collection?: { [collectionGroupName: string]: { in: string[]; }; }; }; export type VenueSortQuery = SortQuery< 'name' | 'slug' | 'createdAt' | 'updatedAt' >;