import { z } from 'zod'; import { createPageSchema, createPageSizeSchema, createPaginationSchema } from './pagination.js'; const isoDateTimeSchema = z.string().datetime(); const pageSchema = createPageSchema(); const pageSizeSchema = createPageSizeSchema(10); const paginationSchema = createPaginationSchema(); export const paymentStatusSchema = z.enum(['PENDING', 'PAID', 'OVERDUE', 'CANCELLED']); export type PaymentStatus = z.output; export const PaymentDtoSchema = z.object({ id: z.string(), groupId: z.string(), groupName: z.string(), attendeeId: z.string(), attendeeName: z.string(), amount: z.coerce.number().positive(), currency: z.string(), status: paymentStatusSchema, description: z.string().nullable(), checkoutUrl: z.string().nullable(), dueDate: isoDateTimeSchema, paidAt: isoDateTimeSchema.nullable(), createdAt: isoDateTimeSchema, updatedAt: isoDateTimeSchema, }); export type PaymentDto = z.output; export const PaymentQuerySchema = z.object({ page: pageSchema, pageSize: pageSizeSchema, groupId: z.string().min(1).optional(), status: paymentStatusSchema.optional(), }); export type PaymentQuery = z.output; export const PaymentListSchema = z.object({ data: z.array(PaymentDtoSchema), pagination: paginationSchema, }); export type PaymentList = z.output; // Creates one payment link per active attendee of a group. The professor // triggers it from the group page for a period (e.g. June's monthly fee). export const CreatePaymentsBatchSchema = z.strictObject({ dueDate: isoDateTimeSchema, description: z.string().trim().max(120, 'payment.descriptionMax').optional(), attendeeIds: z.array(z.string().min(1)).min(1).optional(), }); export type CreatePaymentsBatch = z.output; export const paymentBatchOutcomeSchema = z.enum(['CREATED', 'LINKED', 'FAILED']); export const PaymentBatchItemSchema = z.object({ paymentId: z.string(), attendeeId: z.string(), attendeeName: z.string(), amount: z.number().positive(), currency: z.string(), checkoutUrl: z.string().nullable(), outcome: paymentBatchOutcomeSchema, reason: z.string().nullable(), }); export type PaymentBatchItem = z.output; export const CreatePaymentsBatchResultSchema = z.object({ groupId: z.string(), total: z.number().int().min(0), linked: z.number().int().min(0), failed: z.number().int().min(0), items: z.array(PaymentBatchItemSchema), }); export type CreatePaymentsBatchResult = z.output;