import { z } from 'zod'; import { CollectionHalSchema } from './collections'; import { ListSchema } from './common'; import type { ProductionFilterQuery, ProductionSubfilterQuery, } from './production'; import { ProductionHalSchema } from './production'; import { ProductionTypeHalSchema } from './production-type'; import type { EmbedQuery, PaginationQuery, SortQuery } from './query'; import type { VenueFilterQuery } from './venue'; import { VenueHalSchema } from './venue'; export const EventSchema = z.object({ id: z.uuid(), productionId: z.uuid().nullable().optional(), productionTypeId: z.string(), productionHint: z .object({ universalIds: z .array( z.object({ type: z.string(), value: z.string(), }) ) .nullish(), title: z.string().nullable(), }) .optional(), venueId: z.uuid(), ticketingUrl: z.url().nullish(), isHidden: z.boolean(), attributes: z.any().optional(), localizableAttributes: z.any().optional(), startDate: z.string(), // this differs from backend, backend needs to be adjusted in the future endDate: z.string().nullish(), // this differs from backend, backend needs to be adjusted in the future 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 Event = z.infer; export const EventCreateInputSchema = EventSchema.pick({ productionId: true, productionTypeId: true, productionHint: true, venueId: true, ticketingUrl: true, isHidden: true, attributes: true, localizableAttributes: true, startDate: true, endDate: true, }); export type EventCreateInput = z.infer; export const EventUpdateInputSchema = EventSchema.pick({ productionId: true, productionTypeId: true, productionHint: true, venueId: true, ticketingUrl: true, isHidden: true, attributes: true, localizableAttributes: true, startDate: true, endDate: true, }); export type EventUpdateInput = z.infer; export const EventPatchInputSchema = EventUpdateInputSchema.partial(); export type EventPatchInput = z.infer; export const EventHalSchema = EventSchema.pick({ id: true, productionId: true, productionTypeId: true, productionHint: true, venueId: true, ticketingUrl: true, isHidden: true, attributes: true, localizableAttributes: true, startDate: true, endDate: true, createdAt: true, updatedAt: true, }).extend({ _links: z.object({ self: z.object({ href: z.string(), }), production: z .object({ href: z.string(), }) .optional(), venue: z.object({ href: z.string(), }), }), _embedded: z.object({ production: ProductionHalSchema.optional(), productionType: ProductionTypeHalSchema.optional(), venue: VenueHalSchema.optional(), collections: z.array(CollectionHalSchema).optional(), }), }); export type EventHalSchemaType = z.infer; // not present in backend yet export const EventHalListSchema = ListSchema.extend({ _embedded: z.object({ events: z.array(EventHalSchema), }), }); export type EventHalListSchemaType = z.infer; // not present in backend yet export type EventListQuery = EventFilterQuery & EventSubfilterQuery & EventEmbedQuery & EventSortQuery & PaginationQuery; // TODO extract common filter groups like StringFilter, IdFilter, DateStringFilter, RelationIdFilter, CollectionFilter... export type EventFilterQuery = { id?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; }; startDate?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; }; endDate?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; }; createdAt?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; }; updatedAt?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; }; productionId?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; isNull?: boolean; }; venueId?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; isNull?: boolean; }; productionHintTitle?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; contains?: string | string[]; isNull?: boolean; }; isHidden?: { eq?: boolean; }; tags?: { contains?: string | string[]; }; subtitles?: { contains?: string | string[]; }; collection?: { [collectionGroupName: string]: { in: string[]; }; }; }; export type EventSubfilterQuery = { production?: ProductionFilterQuery & ProductionSubfilterQuery; venue?: VenueFilterQuery; }; export type EventEmbedQuery = EmbedQuery< 'production' | 'productionType' | 'venue' | 'collections' >; export type EventSortQuery = SortQuery< 'startDate' | 'endDate' | 'createdAt' | 'updatedAt' | 'productionHintTitle' >;