# AOT Printer Agent Windows Installation

This guide installs the native AOT Printer Agent on a customer Windows machine.

## What Gets Installed

- Windows service name: `AOTPrinterAgent`
- Executable path: chosen during deployment
- Config path: `C:\ProgramData\AOTPrinterAgent\config.json`
- Log path: `C:\ProgramData\AOTPrinterAgent\logs\agent.log`

The agent uses outbound HTTPS to Laravel and raw TCP to the LAN printer.

## Build on Developer or CI Machine

Build the Windows executable before going to the customer machine:

```powershell
cd printer-agent
go mod download
go build -o .\dist\aot-printer-agent.exe .\cmd\agent
```

The customer machine does not need Go installed when you deploy the compiled `.exe`.

## Prepare Customer Machine

Requirements:

- Windows 10/11 or Windows Server.
- Administrator access for installation.
- Customer LAN can reach the printer IP and port, usually `9100`.
- Customer machine can reach Laravel cloud over HTTPS.
- One approved printer agent token from Laravel admin.
- One configured `network_raw` printer in Laravel or reported through heartbeat.

## Create Config

Create:

```text
C:\ProgramData\AOTPrinterAgent\config.json
```

Example:

```json
{
  "agent_uuid": "9f8b0b72-4f57-48d6-9e32-3e6dfc3fca01",
  "agent_name": "Kitchen Agent",
  "cloud": {
    "base_url": "https://example.com",
    "token": "replace-with-approved-agent-token",
    "timeout_seconds": 15
  },
  "runtime": {
    "heartbeat_interval_seconds": 30,
    "claim_interval_seconds": 5,
    "batch_size": 5,
    "lease_seconds": 60
  },
  "printers": [
    {
      "local_printer_id": "kitchen-lan-9100",
      "name": "Kitchen LAN",
      "connection_type": "network_raw",
      "ip_address": "192.168.1.50",
      "port": 9100
    }
  ],
  "logging": {
    "file": "C:\\ProgramData\\AOTPrinterAgent\\logs\\agent.log"
  }
}
```

## Test Before Installing Service

Run from PowerShell:

```powershell
.\aot-printer-agent.exe -config C:\ProgramData\AOTPrinterAgent\config.json -once
```

Expected:

- Config loads.
- Heartbeat request is sent.
- Claim endpoint is called once.
- Logs are written.

## Install Service

Open PowerShell as Administrator:

```powershell
cd C:\AOTPrinterAgent
.\scripts\install-service.ps1 `
  -ExePath .\aot-printer-agent.exe `
  -ConfigPath C:\ProgramData\AOTPrinterAgent\config.json
```

Verify:

```powershell
Get-Service AOTPrinterAgent
Get-Content C:\ProgramData\AOTPrinterAgent\logs\agent.log -Tail 50
```

## Dry Run Install

Use this when validating paths without creating the service:

```powershell
.\scripts\install-service.ps1 `
  -ExePath .\aot-printer-agent.exe `
  -ConfigPath C:\ProgramData\AOTPrinterAgent\config.json `
  -DryRun
```

## Stop, Start, Restart

```powershell
Stop-Service AOTPrinterAgent
Start-Service AOTPrinterAgent
Restart-Service AOTPrinterAgent
```

## Uninstall

Open PowerShell as Administrator:

```powershell
.\scripts\uninstall-service.ps1
```

Remove local config and logs too:

```powershell
.\scripts\uninstall-service.ps1 -RemoveProgramData
```

## First Customer-Site E2E Check

1. Approve the agent in Laravel and issue token.
2. Put the token and cloud URL in `config.json`.
3. Configure one `network_raw` printer with the LAN IP and port `9100`.
4. Run `-once` and confirm heartbeat in Laravel.
5. Create one print job with `payload_format = escpos_base64`.
6. Start service.
7. Confirm the job changes to `sent`.
8. Confirm physical receipt output.

`confirmed` is not expected for MVP `network_raw` unless the specific printer supports reliable status confirmation.
