# FYP2 — Virtual Legal Workflow Integration Guide

All new files are in this zip. Your FYP1 files are **completely untouched**.
Follow these steps to activate the new features.

---

## Step 1 — Add new models to database.py

Open `backend/services/database.py`.
In the `init_db()` function, add this import line alongside the existing imports:

```python
async def init_db():
    from ..models.models import User, Case, Lawyer, Appointment          # existing
    from ..models.fyp2_models import (                                    # ADD THIS
        Hearing, CourtFiling, CaseMessage, CaseDocument,
        DraftedPetition, LawyerNote, Notification, ChatMessage
    )
    Base.metadata.create_all(bind=engine)
    # ... rest of function unchanged
```

---

## Step 2 — Add ZOOM credentials to config.py

Add this one line at the bottom of `backend/config.py`:

```python
ZOOM credentials: str = os.getenv("ZOOM credentials", "")
```

Add to your `.env` file:
```
ZOOM_ACCOUNT_ID=your_zoom_account_id
ZOOM_CLIENT_ID=your_zoom_client_id
ZOOM_CLIENT_SECRET=your_zoom_client_secret
# Leave all three blank to use Jitsi Meet as free fallback
```

---

## Step 3 — Register new routers in main.py

Open `backend/main.py` and add these lines:

```python
# Existing imports
from .routers import auth_router, client_router, lawyer_router, api_router

# ADD THESE
from .routers import admin_router, office_router, hearing_router

# Existing router includes
app.include_router(auth_router.router,   prefix="/api/auth", tags=["Auth"])
app.include_router(client_router.router, prefix="/client",   tags=["Client"])
app.include_router(lawyer_router.router, prefix="/lawyer",   tags=["Lawyer"])
app.include_router(api_router.router,    prefix="/api",      tags=["AI API"])

# ADD THESE
app.include_router(office_router.router,  prefix="/lawyer",   tags=["Virtual Office"])
app.include_router(admin_router.router,   prefix="/admin",    tags=["Admin"])
app.include_router(hearing_router.router, prefix="/hearing",  tags=["Hearing"])
```

---

## Step 4 — Add new nav links to base.html (optional)

In `frontend/templates/base.html`, inside the navbar section, add:

For lawyer users:
```html
<a href="/lawyer/office" class="nav-link"><i class="fas fa-briefcase"></i> Virtual Office</a>
```

For admin users:
```html
<a href="/admin/dashboard" class="nav-link"><i class="fas fa-shield-alt"></i> Admin</a>
```

---

## Step 5 — Install new dependencies

```bash
pip install requests pymupdf pytesseract Pillow scikit-learn
```

For email notifications (optional):
```bash
pip install fastapi-mail
```

---

## Step 6 — Create one admin user

Run this in Python to set your test user as admin:

```python
from backend.services.database import SessionLocal
from backend.models.models import User

db = SessionLocal()
user = db.query(User).filter(User.email == "your@email.com").first()
user.role = "admin"
db.commit()
db.close()
```

---

## New Routes Added

| Route | Role | Description |
|-------|------|-------------|
| GET /lawyer/office | Lawyer | Virtual office case tray |
| GET /lawyer/office/case/{id} | Lawyer | Case workspace |
| POST /lawyer/office/case/{id}/draft-petition | Lawyer | AI petition drafting |
| POST /lawyer/office/case/{id}/file-in-court | Lawyer | Court filing |
| GET /lawyer/office/case/{id}/filing-package | Lawyer | View filing PDF |
| GET /admin/dashboard | Admin | Platform overview |
| GET /admin/court | Admin | Court management |
| POST /admin/schedule-hearing | Admin | Create video hearing room |
| POST /admin/hearing/{id}/complete | Admin | Mark hearing complete |
| POST /admin/hearing/{id}/adjourn | Admin | Adjourn to next date |
| GET /hearing/{id}/join | All | Join virtual hearing room |

---

## New Files Added

```
backend/
  models/
    fyp2_models.py          ← All new DB tables
  services/
    hearing_service.py      ← Zoom / Jitsi video rooms
    ocr_service.py          ← PDF & image OCR
    petition_service.py     ← AI petition drafting
    filing_service.py       ← Court filing management
    notification_service.py ← In-app notifications
  routers/
    admin_router.py         ← Admin + judge routes
    office_router.py        ← Lawyer virtual office
    hearing_router.py       ← Hearing room join

frontend/templates/
  lawyer/
    office.html             ← Virtual office dashboard
    case_workspace.html     ← Full case workspace
    filing_package.html     ← Filing package viewer
  admin/
    dashboard.html          ← Admin overview
    court.html              ← Court management
  hearing/
    hearing_room.html       ← Virtual hearing room (video embed)
```

---

## Pipeline Flow (for your demo)

1. Client submits case → `/client/submit-case`
2. Client books appointment → lawyer sees it in office tray
3. Lawyer opens case workspace → `/lawyer/office/case/{id}`
4. Lawyer drafts petition with AI → saves to DraftedPetition table
5. Lawyer files in court → CourtFiling record created, client notified
6. Admin schedules hearing → Zoom/Jitsi room created automatically
7. All parties join → `/hearing/{id}/join`
8. Admin records judgment → case marked resolved

