Files
playzer/packages/api-contract/src/plan.ts
Jose Selesan 4544911f0e refactor(onboarding): restructure onboarding routes and components
- Removed obsolete onboarding routes: complete, create-complex, index, verify-email, and verify.
- Introduced new setup stepper page for onboarding process.
- Created a multi-step setup component to handle complex creation with validation.
- Added new schemas for complex creation and plan features.
- Implemented detailed steps for complex name, location, plan selection, and court setup.
- Enhanced error handling and user feedback during the onboarding process.
2026-06-02 10:02:28 -03:00

74 lines
2.3 KiB
TypeScript

import { z } from 'zod'
const nonNegativeInt = z.int().nonnegative()
const positiveInt = z.int().positive()
export const planFeatureFlagsSchema = z.object({
onlinePayments: z.boolean().default(false),
publicBookingPage: z.boolean().default(false),
advancedReports: z.boolean().default(false),
whatsappReminders: z.boolean().default(false),
})
export const planRulesV1Schema = z.object({
version: z.literal('v1'),
limits: z.object({
maxCourts: positiveInt,
maxBookingsPerDay: positiveInt,
maxActiveUsers: positiveInt.optional(),
maxConcurrentBookingsPerSlot: positiveInt.optional(),
}),
policies: z
.object({
maxAdvanceBookingDays: positiveInt.optional(),
minCancellationNoticeHours: nonNegativeInt.optional(),
allowOverbooking: z.boolean().default(false),
})
.default({ allowOverbooking: false }),
features: planFeatureFlagsSchema.default({
onlinePayments: false,
publicBookingPage: false,
advancedReports: false,
whatsappReminders: false,
}),
})
export const planRulesSchema = z.discriminatedUnion('version', [planRulesV1Schema])
export const planSchema = z.object({
code: z.string().trim().min(1).max(10),
name: z.string().trim().min(1).max(30),
price: z.number().nonnegative(),
lastUpdatedAt: z.string().datetime(),
rules: planRulesSchema,
})
export const planSummarySchema = z.object({
code: z.string().trim().min(1).max(10),
name: z.string().trim().min(1).max(30),
price: z.number().nonnegative(),
})
export const planLimitsSchema = z.object({
maxCourts: positiveInt,
maxBookingsPerDay: positiveInt,
maxActiveUsers: positiveInt.optional(),
maxConcurrentBookingsPerSlot: positiveInt.optional(),
})
export const planWithFeaturesSchema = z.object({
code: z.string().trim().min(1).max(10),
name: z.string().trim().min(1).max(30),
price: z.number().nonnegative(),
features: planFeatureFlagsSchema,
limits: planLimitsSchema,
})
export type PlanFeatureFlags = z.infer<typeof planFeatureFlagsSchema>
export type PlanRulesV1 = z.infer<typeof planRulesV1Schema>
export type PlanRules = z.infer<typeof planRulesSchema>
export type Plan = z.infer<typeof planSchema>
export type PlanSummary = z.infer<typeof planSummarySchema>
export type PlanWithFeatures = z.infer<typeof planWithFeaturesSchema>
export type PlanLimits = z.infer<typeof planLimitsSchema>