# InventoryPlus ServiceAgent - macOS End-User Installation & Operational Manual

This manual provides clear, step-by-step instructions for end users and system administrators on how to install, configure, verify, and troubleshoot **InventoryPlus ServiceAgent** on Apple macOS computers (Apple Silicon M1/M2/M3/M4 and Intel Macs).

---

## 📋 Prerequisites & Hardware Requirements

1. **macOS Version**: macOS 10.15 (Catalina) or newer.
2. **Web Browser (Google Chrome / Microsoft Edge / Safari)**:
   - For pixel-perfect PDF rendering of bills and invoices, ensure Google Chrome, Microsoft Edge, or Chromium is installed in `/Applications/`.
3. **Printers**:
   - Ensure your printer (Thermal Receipt Printer, Laser, Inkjet, or Barcode Label Printer) is connected via USB, Wi-Fi, or Local Network, and added under **System Settings → Printers & Scanners**.

---

## 🛠️ Step-by-Step Installation Guide

### Option A: Standard Terminal Installer (Recommended)

1. Copy the `Output_macOS` folder to your Mac (e.g., Downloads or Desktop).
2. Open **Terminal** (Press `Cmd + Space`, type `Terminal`, and press `Enter`).
3. Navigate to the `Output_macOS` directory:
   ```bash
   cd ~/Downloads/Output_macOS
   ```
4. Run the installer script with administrative privileges:
   ```bash
   sudo bash install_mac.sh
   ```
5. When prompted, enter your macOS user password.

The installer will automatically:
- Detect whether your Mac runs on **Apple Silicon (M1/M2/M3/M4 `arm64`)** or **Intel (`x64`)**.
- Copy binaries to `/Library/Application Support/InventoryPlus/ServiceAgent/`.
- Set execute permissions and register a system-wide `launchd` background daemon (`com.inventoryplus.serviceagent.plist`).
- Configure the service to run automatically on system startup and recover if terminated.

---

## 🔒 Registering & Trusting the Local HTTPS Certificate

To enable secure HTTPS communication between your InventoryPlus PWA and the local ServiceAgent without browser warnings:

1. Open Terminal and run:
   ```bash
   dotnet dev-certs https --trust
   ```
2. When the macOS dialog prompts for permission, enter your Mac administrator password to install the certificate into the **macOS System Keychain**.

---

## ✅ Verifying Installation & Service Health

1. **Check Service Status**:
   Run in Terminal:
   ```bash
   sudo launchctl list | grep com.inventoryplus.serviceagent
   ```
   *If active, it will display a process ID number.*

2. **Test Health Endpoint in Web Browser**:
   Open Chrome or Safari and navigate to:
   - `https://localhost:9123/healthcheck` (or `http://localhost:9122/healthcheck`)

   *Response:* `{"status":"Healthy","version":"1.0.0"}`

3. **Test Local Printer Discovery**:
   Navigate to: `https://localhost:9123/print/printers`
   *Response:* List of all connected macOS printers (e.g., EPSON, HP, TSP100, etc.).

---

## ⚙️ Service Control Commands

| Task | Command |
|---|---|
| **Check Daemon Status** | `sudo launchctl list \| grep com.inventoryplus.serviceagent` |
| **Start Service** | `sudo launchctl load -w /Library/LaunchDaemons/com.inventoryplus.serviceagent.plist` |
| **Stop Service** | `sudo launchctl unload -w /Library/LaunchDaemons/com.inventoryplus.serviceagent.plist` |
| **View Live Logs** | `tail -f "/Library/Application Support/InventoryPlus/ServiceAgent/logs/"*.log` |

---

## 🗑️ How to Uninstall

To remove ServiceAgent from your Mac cleanly:
```bash
sudo launchctl unload -w /Library/LaunchDaemons/com.inventoryplus.serviceagent.plist
sudo rm -f /Library/LaunchDaemons/com.inventoryplus.serviceagent.plist
sudo rm -rf "/Library/Application Support/InventoryPlus/ServiceAgent"
```
