# Validation Schemas (`Api/src/validations/`)

Zod validation schemas for API input validation. Each schema file corresponds to a domain entity.

## Files

| File | Domain | Description |
|------|--------|-------------|
| `appointment.schema.ts` | Appointments | Create/update appointment validation |
| `calendar.schema.ts` | Calendar | Calendar event validation |
| `clinic.schema.ts` | Clinics | Clinic CRUD validation |
| `common.schema.ts` | Shared | Common reusable schemas |
| `media.schema.ts` | Media | File upload validation |
| `notification.schema.ts` | Notifications | Notification payload validation |
| `patient.schema.ts` | Patients | Patient profile validation |
| `practitioner.schema.ts` | Practitioners | Practitioner profile validation |
| `procedure.schema.ts` | Procedures | Procedure CRUD validation |
| `procedure-product.schema.ts` | Products | Procedure product pricing validation |
| `profile-info.schema.ts` | Profiles | Shared profile info validation |
| **`resource.schema.ts`** | **Resources** | **Resource CRUD + blocking event validation** |
| `reviews.schema.ts` | Reviews | Patient review validation |
| `shared.schema.ts` | Shared | Cross-domain shared schemas |

## Resource Validation (`resource.schema.ts`)

Part of the [Clinic Resources System](../../../docs/RESOURCE_SYSTEM.md).

### `createResourceSchema`

Validates input for creating a new resource.

```typescript
{
  clinicBranchId: z.string().min(1),     // Required clinic branch ID
  name: z.string().min(1).max(200),      // Resource name (1-200 chars)
  category: z.nativeEnum(ResourceCategory), // Must be valid ResourceCategory
  description: z.string().max(1000).optional(), // Optional description
  quantity: z.number().int().min(1).max(100),    // 1-100 instances
}
```

### `updateResourceSchema`

Validates input for updating an existing resource. All fields are optional.

```typescript
{
  name: z.string().min(1).max(200).optional(),
  category: z.nativeEnum(ResourceCategory).optional(),
  description: z.string().max(1000).optional(),
  quantity: z.number().int().min(1).max(100).optional(),
  status: z.nativeEnum(ResourceStatus).optional(),
}
```

**Note on quantity updates:** Validation only ensures the value is within range. The business logic for quantity decrease (checking for active bookings on affected instances) is handled by `ResourceService.updateResource()`.

### `createResourceBlockingEventSchema`

Validates input for creating a blocking event on a resource instance.

```typescript
{
  clinicBranchId: z.string().min(1),
  resourceId: z.string().min(1),
  resourceInstanceId: z.string().min(1),
  eventName: z.string().min(1).max(200),      // Event name (1-200 chars)
  eventTime: z.object({
    start: z.any(),                            // Firestore Timestamp
    end: z.any(),                              // Firestore Timestamp
  }),
  description: z.string().max(1000).optional(), // Optional reason
}
```

### `updateResourceBlockingEventSchema`

Validates input for updating a blocking event. All fields except IDs are optional.

```typescript
{
  clinicBranchId: z.string().min(1),
  resourceId: z.string().min(1),
  resourceInstanceId: z.string().min(1),
  eventId: z.string().min(1),
  eventName: z.string().min(1).max(200).optional(),
  eventTime: z.object({ start: z.any(), end: z.any() }).optional(),
  description: z.string().max(1000).optional(),
}
```

## Export

All schemas are exported via `index.ts`.
