import { z } from 'zod'; import { HalListLinksSchema } from './common'; export const MimeTypeSchema = z.enum([ 'image/jpeg', 'image/png', 'image/bmp', 'video/mp4', ]); export const AssetSchema = z.object({ id: z.uuid(), url: z.url(), mimeType: MimeTypeSchema, createdAt: z.string(), updatedAt: z.string(), }); export const AssetHalSchema = AssetSchema.pick({ id: true, url: true, mimeType: true, createdAt: true, updatedAt: true, }).extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), }); export type AssetHalSchemaType = z.infer; export const AssetCreateInputSchema = z.object({ file: typeof window !== 'undefined' ? z.instanceof(File) : z.any(), fileName: z.string(), mimeType: MimeTypeSchema, }); export type AssetCreateInputSchemaType = z.infer; export const AssetHalListSchema = z.object({ count: z.number(), totalCount: z.number(), _links: HalListLinksSchema, _embedded: z.object({ assets: z.array(AssetHalSchema), }), }); export type AssetHalListSchemaType = z.infer; const allowedRelationTypes = ['production', 'venue'] as const; export const AssetResponse = AssetSchema.extend({ filePath: z.string(), }); export const AssetRelationSchema = z.object({ id: z.uuid(), assetId: z.uuid(), asset: AssetResponse, relationType: z.enum(allowedRelationTypes), relationId: z.uuid(), assetType: z.string(), createdAt: z.string(), updatedAt: z.string(), }); export const AssetRelationHalSchema = AssetRelationSchema.pick({ id: true, relationType: true, relationId: true, assetType: true, createdAt: true, updatedAt: true, }).extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), asset: AssetHalSchema, }); export type AssetRelationHalSchemaType = z.infer; export const AssetRelationCreateInputSchema = AssetRelationSchema.pick({ assetId: true, assetType: true, }); export type AssetRelationCreateInput = z.infer< typeof AssetRelationCreateInputSchema >; export const AssetRelationListHalSchema = z.object({ count: z.number(), totalCount: z.number(), _links: HalListLinksSchema, _embedded: z.object({ assetRelations: z.array(AssetRelationHalSchema), }), }); export type AssetRelationListHalSchemaType = z.infer< typeof AssetRelationListHalSchema >;