import { z } from 'zod'; import { ListSchema } from './common'; import type { EventFilterQuery, EventSubfilterQuery } from './event'; import type { PaginationQuery, SortQuery } from './query'; export const ProductionUniversalIds = z.enum([ 'MACCSBOX', 'COMSCORE', 'BIOGUIDEN', 'BIOTELLER', ]); export type ProductionUniversalIdsType = z.infer; export const ProductionSchema = z.object({ id: z.uuid(), slug: z.string().min(1), title: z.string().min(1), assets: z.any().optional(), attributes: z.any().optional(), localizableAttributes: z.any().optional(), productionTypeId: z.string(), universalIds: z .array( z.object({ type: z.string(), value: z.string().min(1), }) ) .nullish(), 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 Production = z.infer; export const ProductionCreateInputSchema = ProductionSchema.pick({ slug: true, title: true, attributes: true, localizableAttributes: true, productionTypeId: true, }); export type ProductionCreateInput = z.infer; export const ProductionUpdateInputSchema = ProductionSchema.pick({ slug: true, title: true, attributes: true, localizableAttributes: true, productionTypeId: true, universalIds: true, }); export type ProductionUpdateInput = z.infer; export const ProductionHalSchema = ProductionSchema.pick({ id: true, title: true, slug: true, assets: true, attributes: true, localizableAttributes: true, productionTypeId: true, universalIds: true, createdAt: true, updatedAt: true, }).extend({ _links: z.object({ self: z.object({ href: z.string(), }), events: z.object({ href: z.string(), }), }), }); export type ProductionHalSchemaType = z.infer; // not present in backend yet export const ProductionHalListSchema = ListSchema.extend({ _embedded: z.object({ productions: z.array(ProductionHalSchema), }), }); export type ProductionHalListSchemaType = z.infer< typeof ProductionHalListSchema >; // not present in backend yet export type ProductionListQuery = ProductionFilterQuery & ProductionSubfilterQuery & ProductionSortQuery & PaginationQuery; // TODO extract common filter groups like StringFilter, IdFilter, DateStringFilter, RelationIdFilter, CollectionFilter... export type ProductionFilterQuery = { id?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; }; slug?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; contains?: string | string[]; }; title?: { eq?: string; neq?: string; in?: string | string[]; nin?: string | string[]; contains?: 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[]; }; premiereDate?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; isNull?: boolean; }; releaseYear?: { eq?: string; neq?: string; gt?: string; gte?: string; lt?: string; lte?: string; in?: string | string[]; nin?: string | string[]; isNull?: boolean; }; collection?: { [collectionGroupName: string]: { in: string[]; }; }; }; export type ProductionSubfilterQuery = { event?: EventFilterQuery & EventSubfilterQuery; }; export type ProductionSortQuery = SortQuery< 'slug' | 'title' | 'createdAt' | 'updatedAt' | 'premiereDate' | 'releaseYear' >;