# CLOUDYTE LOCK & KEY CARD INTEGRATION (part of Leakage Guard)
Goal: Cloudyte works with ANY hotel's locks from day one (brand-independent controls), and takes full control of card issuing when a brand driver is added.

RULES
- Inspect first: Key Manager, room status, housekeeping, room discrepancies, leakage radar (L1), night audit. Reuse; no duplicates.
- Each part its own small run, OFF by default, guarded install, full gate ALL PASS, money checksum unchanged, audit trail, own commit, HANDOVER.
- Never delete card or door records; corrections by void with reason.
- No lock credentials or SDK keys in code or database: .env / bridge config only.

K0 - GAP REPORT FIRST (no code): Built / Partial / Missing for each part, DB changes, risks, order. Stop for approval.

K1 - LOCK SETTINGS (per hotel)
- Mode: none (manual keys) / assisted (any brand) / full control (brand driver).
- Lock brand and model (free text + driver list), keys per room, card validity rule (until check-out time + grace minutes).

K2 - CARD LOG AND CONTROL (works with ANY lock, "assisted" mode)
- Record every card made: room, stay, card count, valid from/until, issued by, time, reason (new / duplicate / lost / room move / staff).
- REFUSE a guest card unless the room has an active, approved stay (in house or arriving today and checked in).
- Staff / master / maintenance cards: manager only, with reason; listed separately.
- Duplicate cards above N per stay need a supervisor.
- At check-out, room move, early departure, cancellation and no-show: "cancel cards" task appears and must be confirmed; open tasks show on the night audit.

K3 - CARD RECONCILIATION (leakage radar signal)
- Daily, with L1: cards issued vs stays. Flags: card for a room with no stay; card valid past check-out; more cards than guests; card not cancelled after room move/check-out; card issued then stay cancelled within N minutes.
- Feeds L1 flags with evidence (who issued, when).

K4 - DOOR EVENT IMPORT (works with most brands)
- Upload the lock software's audit export (CSV/Excel), map columns once per brand (room, date-time, card id / card type, event).
- Match door openings against stays; flag openings of rooms with no stay or outside the stay dates; flag staff/master card use at odd hours.
- Keep imported files and rows; re-import of the same rows is ignored (no duplicates).

K5 - FULL CONTROL DRIVER LAYER (when a brand SDK is available)
- One connector interface in Cloudyte: issue card, duplicate, cancel, read card, fetch door events (if supported).
- A small bridge app on the reception Windows PC talks to the encoder via the brand SDK; Cloudyte sends signed, time-limited requests; the bridge refuses unsigned ones.
- In full control mode the receptionist cannot make a guest card outside Cloudyte (policy + reconciliation flags any card the lock software made alone).
- First driver: the first client hotel's brand. Each further brand = one new driver only.
- If the bridge is offline: fall back to assisted mode with a logged reason.

ADDED SAFEGUARDS (apply to K2-K5)
1. Card security: every card issue/cancel has a unique transaction reference; failed attempts are recorded; exceptional issues record who approved.
2. Room moves: record old and new room; old card must be cancelled; new card issued for the new room; incomplete cancellation is flagged.
3. Staff and master cards: separate types, permissions, validity periods and approval records; never treated as guest cards.
4. Door events are SUPPORTING EVIDENCE for investigations only, never proof of a sale or stay on their own.
5. Bridge security (K5): device registration per hotel, signed requests with expiry, unique request IDs with replay protection, encrypted connection (HTTPS), offline status monitoring, full command/response log.
- Reuse the existing Key Manager and the L1 Leakage Radar; do not build a second card or leakage system.
- Never promise electronic control of a lock without a compatible vendor SDK/interface: assisted mode is universal, full control needs a driver.

ORDER: K0 -> K1 -> K2 -> K3 -> K4 -> K5 (K5 only when a brand SDK is in hand).
INFO NEEDED FOR K5: lock brand/model, encoder model, supplier SDK/DLL or developer docs, reception PC is Windows.
