# 02 — Tenant Setup & Clinic Settings

← [Back to index](README.md)

Covers one-time provisioning plus the two editable clinic settings (working hours, visit
types). Working hours & visit types are **doctor-only**.

---

## `POST /tenant/provision`
Submitted once after registration by the setup wizard. **Idempotent** (re-submit allowed).

**Request — `ClinicSettings`**
```json
{
  "schedule": {
    "days": [
      { "day": "sunday",    "isOpen": true,  "openMinute": 540, "closeMinute": 1020 },
      { "day": "monday",    "isOpen": true,  "openMinute": 540, "closeMinute": 1020 },
      { "day": "tuesday",   "isOpen": true,  "openMinute": 540, "closeMinute": 1020 },
      { "day": "wednesday", "isOpen": true,  "openMinute": 540, "closeMinute": 1020 },
      { "day": "thursday",  "isOpen": true,  "openMinute": 540, "closeMinute": 1020 },
      { "day": "friday",    "isOpen": false, "openMinute": 540, "closeMinute": 1020 },
      { "day": "saturday",  "isOpen": true,  "openMinute": 540, "closeMinute": 1020 }
    ]
  },
  "visitTypes": [
    { "id": "first", "name": "كشف أول", "feePiastres": 30000, "durationMinutes": 30 }
  ],
  "staffInvites": [
    { "id": "local-1", "email": "sara@example.com", "role": "receptionist" }
  ],
  "seedSampleData": true
}
```
- `openMinute`/`closeMinute` = minutes from midnight (`540` = 09:00, `1020` = 17:00).
- `schedule.days` always has exactly 7 entries, one per [Weekday](11-enums.md).
- `staffInvites[].id` is a client temp id — assign real ids server-side. `role` is always
  `receptionist`.
- `seedSampleData`: if true, seed demo patients/appointments for the tenant.

**Response `200`** — empty or the persisted settings (app only checks success).

---

## Working Hours (doctor only)

### `GET /tenant/working-hours`
**Response `200` — `WeeklySchedule`**
```json
{
  "days": [
    { "day": "sunday", "isOpen": true, "openMinute": 540, "closeMinute": 1020 }
    /* ...7 entries... */
  ]
}
```
If never set, return defaults: Sat–Thu open 09:00–17:00 (540–1020), Fri closed.

### `PUT /tenant/working-hours`
**Request** — same `WeeklySchedule`. **Response `200`** — the saved schedule.

**DayHours fields:** `day` ([Weekday](11-enums.md)), `isOpen` (bool), `openMinute` (int),
`closeMinute` (int). Validity rule the app enforces: `!isOpen || closeMinute > openMinute`.

---

## Visit Types (doctor only)

Feeds Settings editing **and** the booking visit-type picker.

### `GET /tenant/visit-types`
**Response `200`**
```json
[
  { "id": "vt_1", "name": "كشف أول", "feePiastres": 30000, "durationMinutes": 30 },
  { "id": "vt_2", "name": "متابعة",  "feePiastres": 15000, "durationMinutes": 20 }
]
```

### `PUT /tenant/visit-types`
Replaces the **whole** list (the app sends the entire array on save). New items may carry a
temp `id`; assign real ids and echo them back.
**Request** — array of `{ id, name, feePiastres, durationMinutes }`.
**Response `200`** — the saved array (with server ids).

> **Booking needs `kind` + `label` too.** `VisitTypeSetting` here has only
> `name/fee/duration`. The booking picker needs each option's `kind`
> (one of [VisitType](11-enums.md)) and a display `label`. Serve that via
> [`GET /appointments/visit-type-options`](07-appointments.md) (derive `kind` from each
> configured type, or fall back to the default catalogue).
