import { z } from 'zod'; import { ListSchema } from './common'; export const paymentMethodTypes = ['sepa', 'creditcard'] as const; export const CustomerAddressSchema = z.object({ street: z.string(), houseNumber: z.string(), houseNumberExtension: z.string().nullable(), postalCode: z.string(), city: z.string(), country: z.string().regex(/^[A-Z]{2}$/gm), }); export type CustomerAddress = z.infer; export const CustomerSchema = z.object({ id: z.uuid(), firstName: z.string(), lastName: z.string(), email: z.email(), birthdate: z.iso.date(), address: CustomerAddressSchema.nullable(), billingAddress: CustomerAddressSchema.nullable(), paymentInfo: z .object({ paymentMethod: z.enum(paymentMethodTypes).nullable(), maskedBankAccount: z.string().nullable(), inNameOf: z.string().nullable(), creditcardExpirationDate: z.iso.date().nullable(), }) .nullable(), }); export type Customer = z.infer; export const CustomerPatchInputSchema = CustomerSchema.pick({ address: true, billingAddress: true, }).partial(); export type CustomerPatchInput = z.infer; export const CustomerHalSchema = CustomerSchema.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), }); export type CustomerHal = z.infer; export const CustomerHalListSchema = ListSchema.extend({ _embedded: z.object({ customers: z.array(CustomerHalSchema), }), }); export type CustomerHalList = z.infer;