# Model: ClinicProfile

**Table**: `clinic_profiles` (new) · **Extends**: `App\Models\Core\Branch` (table `branches`, reused as-is)

## Purpose

Holds every clinic-specific fact that doesn't belong on the generic, company-wide `branches`
table (which other ERP modules also use for non-medical branches). A `Branch` "is a clinic"
simply by having a matching `clinic_profiles` row.

## Fields

| Column | Type | Constraints | Notes |
|---|---|---|---|
| `id` | bigint | PK | |
| `branch_id` | bigint | `foreignId('branch_id')->unique()->constrained('branches')->cascadeOnDelete()` | 1:1, one profile per branch |
| `logo_path` | string | nullable | |
| `cover_image_path` | string | nullable | |
| `description` | text | nullable | short clinic description |
| `whatsapp` | string | nullable | separate from `branches.phone` |
| `working_hours` | json | nullable | `{ "sun": ["10:00","22:00"], "mon": [...], ... }` |
| `commission_percentage` | decimal(5,2) | default 0 | set by Super Admin |
| `settlement_details` | text | nullable, should be encrypted (`encrypted` cast) | bank/payout info, mirrors how `PaymentGateway.config` is stored encrypted |
| `avg_rating` | decimal(3,2) | default 0 | recomputed by `ReviewService` on new review |
| `is_active` | boolean | default true | independent of `branches.is_active` — lets Super Admin pause a clinic's bookings without disabling the whole branch record |
| `created_by` / `updated_by` | bigint | `foreignId(...)->nullable()->constrained('admins')->nullOnDelete()` | |
| `created_at` / `updated_at` | timestamp | | |

`branches.name`, `.address`, `.city`, `.phone`, `.email`, `.code` are reused directly from the
existing `Branch` model — not duplicated here.

## Relationships

| Relation | Type | Target |
|---|---|---|
| `branch()` | `belongsTo` | `Core\Branch` |
| `doctors()` | `belongsToMany` (through `clinic_doctor_branch`) | `Clinic\Doctor` |
| `specialties()` | derived (not a direct relation) | distinct `Specialty`s across `doctors()` — computed, not stored |
| `bookings()` | `hasMany` (via `branch_id` on `clinic_bookings`) | `Clinic\Booking` |
| `offers()` | `hasMany` (where `branch_id` is not null) | `Clinic\Offer` |

## Decisions

- Not a standalone `Clinic` model/table — deliberately a 1:1 extension of the existing `Branch`,
  per the reuse decision in `00-overview.md`.
- `is_active` here is separate from `branches.is_active` intentionally: a Super Admin pausing
  bookings for a clinic shouldn't disable the branch record for other ERP modules that might use
  the same branch for non-clinic purposes (inventory warehouse mapping, HR branch assignment, etc.).
