import { z } from 'zod'; import { planSchema, subscriptionStatusSchema } from './billing.js'; import { countryCodeSchema, DEFAULT_COUNTRY } from './country.js'; import { billingTypeSchema, groupAudienceSchema, weekdaySchema } from './enums.js'; import { GroupDtoSchema } from './groups.js'; export { countryCodeSchema } from './country.js'; export type { BillingType, GroupAudience, WeekDay } from './enums.js'; export { billingTypeSchema, groupAudienceSchema, weekdaySchema } from './enums.js'; // Step 4: create the teacher's first group. Linking Mercado Pago is step 2 and // is skippable, so nothing here may require a linked account. The country is // stored on the user and drives the currency of the payment links later. It // defaults to Argentina because the group form (also used outside onboarding) // has no country field: the country lives on the user, not on the group. export const CreateFirstGroupSchema = z.strictObject({ name: z .string() .trim() .min(3, 'group.nameMin') .max(60, 'group.nameMax'), days: z.array(weekdaySchema).min(1, 'group.daysMin'), time: z .string() .regex(/^([01]?\d|2[0-3]):[0-5]\d$/, 'group.timeInvalid'), capacity: z .number({ invalid_type_error: 'group.capacityInvalid' }) .int({ message: 'group.capacityInt' }) .min(1, 'group.capacityMin'), price: z .number({ invalid_type_error: 'group.priceInvalid' }) .min(0, 'group.priceMin'), billingType: billingTypeSchema, dueDay: z .number({ invalid_type_error: 'group.dueDayInvalid' }) .int({ message: 'group.dueDayInt' }) .min(1, 'group.dueDayRange') .max(28, 'group.dueDayRange'), country: countryCodeSchema.default(DEFAULT_COUNTRY), // A KIDS group needs the `kidsGroups` plan feature. audience: groupAudienceSchema.default('ADULTS'), }); export type CreateFirstGroup = z.output; // "Editar grupo" (`PATCH /groups/:id`): the same fields as the group form, any // subset. The country lives on the user, not on the group. Turning the group // into KIDS needs the `kidsGroups` plan feature; going back to ADULTS is blocked // while it has kids with no phone of their own. export const UpdateGroupSchema = CreateFirstGroupSchema.omit({ country: true, audience: true }) .extend({ audience: groupAudienceSchema }) .partial() .refine((value) => Object.keys(value).length > 0, 'update.empty'); export type UpdateGroup = z.output; export const OnboardingGroupDtoSchema = GroupDtoSchema.extend({ days: z.array(weekdaySchema).nullable(), time: z.string().nullable(), capacity: z.number().int().min(1).nullable(), price: z.number().min(0).nullable(), billingType: billingTypeSchema.nullable(), dueDay: z.number().int().min(1).max(28).nullable(), }); export type OnboardingGroupDto = z.output; export const CreateFirstGroupResultSchema = z.object({ group: OnboardingGroupDtoSchema, onboardingCompleted: z.boolean(), }); export type CreateFirstGroupResult = z.output; // Onboarding state, to resume the flow if it was interrupted. export const onboardingStepSchema = z.enum(['NOT_STARTED', 'PAYMENT_CONNECTED', 'COMPLETED']); export type OnboardingStep = z.output; export const OnboardingStatusDtoSchema = z.object({ step: onboardingStepSchema, paymentConnected: z.boolean(), // WhatsApp is its own skippable step and does not move `step`. whatsappConnected: z.boolean(), completed: z.boolean(), // The "Plan" step is mandatory: these survive the round trip to Mercado Pago // and a reload, so the flow resumes where it was. planSelected: z.boolean(), // PRO as soon as the professor chose it, even while the subscription is PENDING. selectedPlan: planSchema.nullable(), subscriptionStatus: subscriptionStatusSchema.nullable(), country: countryCodeSchema.nullable(), }); export type OnboardingStatusDto = z.output;