# HotelFinder & Aahar Direct Integration Plan

## 1. Executive Summary
This document outlines the architecture for a **Direct Peer-to-Peer Integration** between the HotelFinder application (Aggregator/Cloud OTA) and Aahar (Restaurant POS). This bypasses the AAthitya PMS middleware, enabling a direct digital food ordering pipeline from guest to kitchen.

## 2. Configuration & Tenancy Mode
Aahar can be run as a central Cloud instance (Multi-Tenant) or installed locally at individual restaurants (Single-Tenant). 

### 2.1 Multi-Tenant Mode
* **Aahar Config:** `AAHAR_IS_MULTITENANT = 1`
* **Workflow:** HotelFinder uses the `Master API Token` to authenticate with Aahar. HotelFinder calls `GET /apis/backend/web/get-all-restaurants` to dynamically discover all restaurants inside the Aahar instance. Orders pushed to Aahar include the `restaurant_service_id` to route KOTs to the correct kitchen.

### 2.2 Single-Tenant Mode
* **Aahar Config:** `AAHAR_IS_MULTITENANT = 0`
* **Workflow:** HotelFinder uses a `Service Category Token`. No discovery is needed. HotelFinder maps to this single Aahar IP directly. Orders are routed directly via the fixed `service_category` mapping without needing a dynamic tenant ID.

## 3. Component Architecture

### 3.1 HotelFinder Backend (Django)
* **Model Upgrades:** `AaharConfig` now stores `aahar_api_token` and `is_multitenant`.
* **Endpoints:** 
    * `GET /api/hotelfinder/restaurants/` (Returns cached Aahar restaurant list)
    * `GET /api/hotelfinder/restaurants/{id}/menu/` (Proxies to Aahar `export-menu`)
    * `POST /api/hotelfinder/restaurants/{id}/order/` (Receives guest cart, proxies to Aahar)

### 3.2 HotelFinder Frontend (React)
* **Integration Settings UI:** A glassmorphism component (`AaharIntegrationSettings.jsx`) allowing Admins to:
    * Toggle between Multi-Tenant and Single-Tenant modes.
    * Paste the Aahar Domain URL.
    * Paste the secure Aahar Master API Token.
* **Guest UI:** A new "Food Ordering" module to browse restaurants, view digital menus, add items to cart, and checkout.

### 3.3 Aahar Backend (PHP - `ApiController.php`)
* **New Endpoints Needed:**
    * `export-menu`: Dumps the full category/item JSON tree.
    * `get-all-restaurants`: (Multi-tenant only) Returns active tenants.
    * `receive-external-order`: Accepts the cart payload from HotelFinder and triggers the physical KOT printer.
* **Existing Endpoints Reused:**
    * `update-hotel-order-payment-status`: Used by HotelFinder to mark the Aahar order as PAID once the online gateway clears.

## 4. Execution Phases

### Phase 1: Setup & Settings
- [x] Add DB fields (`aahar_api_token`, `is_multitenant`) to HotelFinder.
- [x] Create React configuration UI in HotelFinder admin.
- [x] Add configuration constants to Aahar's `config.php`.

### Phase 2: Aahar API Exposure
- [ ] Build `export-menu` logic in Aahar's `ApiController.php`.
- [ ] Build `receive-external-order` in Aahar.
- [ ] Add `source = 'HOTELFINDER'` flag handling to differentiate from POS orders.

### Phase 3: HotelFinder Gateway & Ordering UI
- [ ] Build HotelFinder proxy views to fetch the menu from Aahar securely.
- [ ] Build Guest Cart and Checkout UI in HotelFinder React.

### Phase 4: Real-Time Tracking
- [ ] Configure Aahar to trigger WebSockets or Webhooks back to HotelFinder when kitchen status changes (Preparing -> Out for Delivery).
