{
  "ursId": "URS-004",
  "title": "Admin approve or reject a sales representative",
  "timestamp": "2026-09-29T02:24:37.412Z",
  "durationMs": 164423,
  "config": {
    "inboxUrl": "http://localhost:41859",
    "dbHost": "localhost",
    "dbPort": 38529,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Admin navigates to rep management",
      "status": "pass",
      "description": "Step 1: Admin navigates to rep management",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-01-admin-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-01-rep-list.png"
      ],
      "explanation": "Proves that a Vantis admin (Alex) can authenticate and reach the Representatives management page. Both Corveta reps — Blair (pending approval) and Rana (active) — appear in the roster, establishing admin context for the approve/reject actions that follow.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:25:14.535Z",
      "finishedAt": "2026-09-29T02:25:20.054Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-01-admin-navigate.webm"
    },
    {
      "name": "Step 2: Admin rejects Blair",
      "status": "pass",
      "description": "Step 2: Admin rejects Blair",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-02-bob-detail-pending.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-02-reject-dialog.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-02-bob-detail-rejected.png"
      ],
      "explanation": "Alex opens Blair's detail page, clicks Reject Representative, supplies a rejection reason, and confirms. Proves that an admin has an in-app control to deny a rep onboarding. The relationship row moves to status='rejected', active=false, and a rep_creation_request_rejected notification is dispatched to the distributor.",
      "expectedEmailTemplates": [
        "Representative Request Rejected"
      ],
      "expectedAuditActions": [
        "user_log:rep_onboarding_request_rejected"
      ],
      "startedAt": "2026-09-29T02:25:29.218Z",
      "finishedAt": "2026-09-29T02:25:33.094Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-02-admin-rejects.webm"
    },
    {
      "name": "Step 3: Blair blocked from creating orders",
      "status": "pass",
      "description": "Step 3: Blair blocked from creating orders",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-03-bob-no-vantis.png"
      ],
      "explanation": "Blair logs in after being rejected and opens the order creation page. Vantis is filtered out of the manufacturer dropdown because `getAvailableFulfillingOrganizations` requires an active representation relationship. Proves the admin action is a hard restriction on downstream order creation — not just a cosmetic UI change.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:25:42.871Z",
      "finishedAt": "2026-09-29T02:25:42.871Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-03-bob-blocked.webm"
    },
    {
      "name": "Step 4: Rana (control) can still create orders",
      "status": "pass",
      "description": "Step 4: Rana (control) can still create orders",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-04-ryan-order-form.png"
      ],
      "explanation": "Rana, an unrelated Corveta rep, is unaffected by the action taken on Blair. He reaches Step 2 of the order form as normal, proving that admin decisions are scoped to the rep under review and do not inadvertently strip privileges from other reps.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:25:51.741Z",
      "finishedAt": "2026-09-29T02:25:51.741Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-04-ryan-control.webm"
    },
    {
      "name": "Step 5: Admin approves Blair",
      "status": "pass",
      "description": "Step 5: Admin approves Blair",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-05-bob-detail-pending-again.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-05-approve-dialog.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-05-bob-detail-approved.png"
      ],
      "explanation": "After the test harness returns Blair's status to 'proposed', Alex approves him through the UI's Approve Representative flow. The manufacturer requires a certification of all reps and Blair has no completion record, so approval lands the relationship in status='pending_certification', active=false — approval alone no longer grants full access. A rep_created notification is dispatched to Corveta announcing the approval.",
      "expectedEmailTemplates": [
        "Representative Account Approved"
      ],
      "expectedAuditActions": [
        "user_log:rep_onboarding_request_approved",
        "decision:representatives.require_certification_on_approval"
      ],
      "startedAt": "2026-09-29T02:26:39.497Z",
      "finishedAt": "2026-09-29T02:26:43.283Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-05-admin-approves.webm"
    },
    {
      "name": "Step 6: Blair completes the certification",
      "status": "pass",
      "description": "Step 6: Blair completes the certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-06-identity-verified.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-06-doc-acknowledged.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-06-quiz-answers.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-06-signature.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-06-completed.png"
      ],
      "explanation": "Approval yields pending certification; the rep must certify before acting. Blair logs in, opens the required certification, acknowledges the training document (timestamped server-side), passes the knowledge check, and signs. Completion activates the relationship (status='active', active=true) with reason_code='certification_completed'.",
      "expectedAuditActions": [
        "certification:completed"
      ],
      "startedAt": "2026-09-29T02:26:53.195Z",
      "finishedAt": "2026-09-29T02:27:04.314Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-06-bob-certifies.webm"
    },
    {
      "name": "Step 7: Blair submits an order after certification",
      "status": "pass",
      "description": "Step 7: Blair submits an order after certification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-07-order-step2.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-07-order-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/step-07-order-submitted.png"
      ],
      "explanation": "Now-certified Blair reaches the order form, picks a delivery location, adds a product, and submits. Proves the restriction lifts immediately when the certification completes — no further admin action is needed. The order request persists in the database for the DB-validation phase to confirm.",
      "expectedAuditActions": [
        "user_log:user:login",
        "decision:order_request_created"
      ],
      "startedAt": "2026-09-29T02:27:13.585Z",
      "finishedAt": "2026-09-29T02:27:18.382Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/videos/step-07-bob-orders.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Blair's relationship ended the run as active",
      "query": "SELECT id, status, active, rejection_reason\n                   FROM organization_representation_relationships\n                  WHERE id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "84c5d6e7-f8a9-0123-8901-234567890123",
          "status": "active",
          "active": true,
          "rejection_reason": null
        }
      ],
      "assertion": "After approval and certification completion Blair's relationship should be status='active', active=true."
    },
    {
      "name": "Rejection status transition recorded",
      "query": "SELECT from_status, to_status, reason, created_at\n                   FROM organization_representation_request_status_changes\n                  WHERE relationship_id = $1\n                    AND to_status = 'rejected'\n                    AND created_at > NOW() - INTERVAL '30 minutes'\n                  ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "from_status": "proposed",
          "to_status": "rejected",
          "reason": "URS-004 validation test: admin rejecting rep to verify order-creation is blocked.",
          "created_at": "2026-09-29T02:25:32.433Z"
        }
      ],
      "assertion": "A proposed→rejected transition should have been recorded during the test run."
    },
    {
      "name": "Two-stage approval transitions recorded",
      "query": "SELECT from_status, to_status, reason_code, created_at\n                   FROM organization_representation_request_status_changes\n                  WHERE relationship_id = $1\n                    AND created_at > NOW() - INTERVAL '30 minutes'\n                  ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "from_status": "pending_certification",
          "to_status": "active",
          "reason_code": "certification_completed",
          "created_at": "2026-09-29T02:27:04.189Z"
        },
        {
          "from_status": "proposed",
          "to_status": "pending_certification",
          "reason_code": "certification_required_on_approval",
          "created_at": "2026-09-29T02:26:40.918Z"
        },
        {
          "from_status": "proposed",
          "to_status": "rejected",
          "reason_code": null,
          "created_at": "2026-09-29T02:25:32.433Z"
        }
      ],
      "assertion": "Approval should record a transition to 'pending_certification' with reason_code 'certification_required_on_approval', followed by a later transition to 'active' with reason_code 'certification_completed'."
    },
    {
      "name": "Blair's certification record created on completion",
      "query": "SELECT rep_user_id, certification_id, certification_version_id,\n                        completed_at, signature_ref\n                   FROM certification_records\n                  WHERE rep_user_id = $1 AND certification_id = $2",
      "status": "pass",
      "rows": [
        {
          "rep_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "certification_id": "ce000100-0000-4000-8000-000000000001",
          "certification_version_id": "ce000200-0000-4000-8000-000000000002",
          "completed_at": "2026-09-29T02:27:04.199Z",
          "signature_ref": "01a0eafc-b187-72fb-802c-f9e2abffd9fb"
        }
      ],
      "assertion": "Exactly one certification record should exist for Blair, on the current version, with a completion timestamp and a signature reference."
    },
    {
      "name": "Approved and certified rep successfully submitted an order",
      "query": "SELECT id, request_number, status, order_type, created_at\n                   FROM order_requests\n                  WHERE requested_by_user_id = $1\n                    AND notes LIKE $2\n                  ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eafc-e86a-79b6-b898-909bc2869d83",
          "request_number": "OR-1",
          "status": "submitted",
          "order_type": "dropship",
          "created_at": "2026-09-29T02:27:18.220Z"
        }
      ],
      "assertion": "At least one order_requests row should exist, tagged with the URS-004 marker."
    },
    {
      "name": "Audit events logged for approve and reject",
      "query": "SELECT event_type, action, created_at\n                   FROM audit_events\n                  WHERE event_type = 'user_log'\n                    AND action IN ('rep_onboarding_request_approved', 'rep_onboarding_request_rejected')\n                    AND created_at > NOW() - INTERVAL '30 minutes'\n                  ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "event_type": "user_log",
          "action": "rep_onboarding_request_approved",
          "created_at": "2026-09-29T02:26:40.978Z"
        },
        {
          "event_type": "user_log",
          "action": "rep_onboarding_request_rejected",
          "created_at": "2026-09-29T02:25:32.747Z"
        }
      ],
      "assertion": "audit_events should include both rep_onboarding_request_approved and rep_onboarding_request_rejected actions from this run."
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z",
  "auditStartTime": "2026-09-29T02:24:36.063Z",
  "emailEvidence": [
    {
      "subject": "Representative Request Rejected - Vantis",
      "template": "Representative_Request_Rejected_-_Vantis",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/emails/2026-09-29T02-25-33-164Z-Representative_Request_Rejected_-_Vantis.png"
    },
    {
      "subject": "Representative Account Approved - Vantis",
      "template": "Representative_Account_Approved_-_Vantis",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/emails/2026-09-29T02-26-43-026Z-Representative_Account_Approved_-_Vantis.png"
    },
    {
      "subject": "Your signing code for LiraLock Implant System Certification",
      "template": "Your_signing_code_for_LiraLock_Implant_System_Certification",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-004-admin-approve-reject-rep/2026-09-29T02-24-37-412Z/screenshots/emails/2026-09-29T02-26-51-561Z-Your_signing_code_for_LiraLock_Implant_System_Certification.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:24:39.386Z",
      "eventType": "decision",
      "action": "return_overdue_sweep",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "wms_feature_flag_disabled",
        "returns": [
          {
            "status": "submitted",
            "returnId": "ca000002-0000-4000-8000-000000000002",
            "daysWaiting": 14,
            "returnNumber": "VRI-RET-2025-002",
            "shipmentStatus": "with_rep"
          },
          {
            "status": "submitted",
            "returnId": "ca000003-0000-4000-8000-000000000003",
            "daysWaiting": 30,
            "returnNumber": "VRI-RET-2025-003",
            "shipmentStatus": "with_rep"
          }
        ],
        "performed": false,
        "entityType": "organization",
        "overdueAfterDays": 14
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:24:40.546Z",
      "eventType": "decision",
      "action": "ensure_lot_expiration_cycle_counter_assignment",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "a6e7f8a9-b0c1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_latest_cycle_counter",
        "performed": false,
        "entityType": "real_world_location",
        "checklistItemId": "fa000009-0000-4000-8000-000000000009"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:24:40.831Z",
      "eventType": "decision",
      "action": "ensure_lot_expiration_cycle_counter_assignment",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b7f8a9b0-c1d2-3456-1234-567890123456",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_latest_cycle_counter",
        "performed": false,
        "entityType": "real_world_location"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:24:41.024Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafa-8244-75bd-b7bd-dfdb309d854e",
      "secondaryObjectId": null,
      "payload": {
        "title": "Lot expiration review (1 location needs attention)",
        "source": {
          "type": "lot_expiration",
          "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:24:41.634Z",
      "eventType": "decision",
      "action": "upgrade_lot_expiration_checklist_priority",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_open_checklists_below_high",
        "performed": false,
        "entityType": "organization"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:24:42.145Z",
      "eventType": "decision",
      "action": "ensure_lot_expiration_checklist",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "reason": "created_1_reopened_0_already_open_1_refreshed_1",
        "performed": true,
        "entityType": "organization"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:25:08.895Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:24.076Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:32.433Z",
      "eventType": "organization_representation",
      "action": "status_change",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": null,
      "payload": {
        "reason": "URS-004 validation test: admin rejecting rep to verify order-creation is blocked.",
        "toStatus": "rejected",
        "fromStatus": "proposed",
        "reasonCode": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:25:32.747Z",
      "eventType": "user_log",
      "action": "rep_onboarding_request_rejected",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "payload": {
        "userName": "Blair Bennett",
        "userEmail": "blair.bennett@corvetasurgical.com",
        "rejectionReason": "URS-004 validation test: admin rejecting rep to verify order-creation is blocked."
      },
      "route": "/representatives/[userId]",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:33.482Z",
      "eventType": "transactional_email",
      "action": "rep_creation_request_rejected",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafb-4e2c-7906-b065-9e81273c2204/",
        "subject": "Representative Request Rejected - Vantis",
        "messageId": "dev-console-log",
        "relatedEntityId": "84c5d6e7-f8a9-0123-8901-234567890123",
        "relatedEntityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:25:36.809Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:47.720Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "rana.reyes@corvetasurgical.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "rana.reyes@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:25:56.223Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:40.918Z",
      "eventType": "organization_representation",
      "action": "status_change",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Certification required",
        "toStatus": "pending_certification",
        "fromStatus": "proposed",
        "reasonCode": "certification_required_on_approval",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:40.918Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-56f9-7161-86e8-69370ca781b7",
      "secondaryObjectId": null,
      "payload": {
        "title": "Complete certification for Vantis",
        "source": {
          "scope": "certification",
          "feature": "representatives"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:40.918Z",
      "eventType": "decision",
      "action": "representatives.require_certification_on_approval",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "secondaryObjectId": null,
      "payload": {
        "reason": "mandatory_certifications_outstanding",
        "performed": true,
        "entityType": "user",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "outstandingMandatoryCount": 1
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:40.978Z",
      "eventType": "user_log",
      "action": "rep_onboarding_request_approved",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "payload": {
        "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
        "userName": "Blair Bennett",
        "userEmail": "blair.bennett@corvetasurgical.com",
        "resultingStatus": "pending_certification",
        "distributorOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": "/representatives/[userId]",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:43.090Z",
      "eventType": "transactional_email",
      "action": "rep_created",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eafc-5ee1-7ad3-81d1-4f04bba0910c/",
        "subject": "Representative Account Approved - Vantis",
        "messageId": "dev-console-log",
        "relatedEntityId": "84c5d6e7-f8a9-0123-8901-234567890123",
        "relatedEntityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:46.541Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:26:49.891Z",
      "eventType": "decision",
      "action": "certifications.signing_challenge.send_sms",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-79e8-7187-a6dc-8faa8047c673",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_phone_channel",
        "performed": false,
        "entityType": "certification_signing_challenge"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:49.891Z",
      "eventType": "certification",
      "action": "signing_code_issued",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-79e8-7187-a6dc-8faa8047c673",
      "payload": {
        "expiresAt": "2026-10-13T02:26:49.960Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:51.582Z",
      "eventType": "transactional_email",
      "action": "certification_signing_code",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-79e8-7187-a6dc-8faa8047c673",
      "secondaryObjectId": null,
      "payload": {
        "to": "blair.bennett@corvetasurgical.com",
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/01a0eafc-8031-79ac-bab1-5e862872fd76/",
        "subject": "Your signing code for LiraLock Implant System Certification",
        "messageId": "dev-console-log",
        "relatedEntityType": "certification_signing_challenge"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:26:53.141Z",
      "eventType": "certification",
      "action": "signing_code_verified",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-79e8-7187-a6dc-8faa8047c673",
      "payload": {
        "signingWindowExpiresAt": "2026-09-29T06:26:53.145Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:00.150Z",
      "eventType": "decision",
      "action": "forms.grade_submission",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000300-0000-4000-8000-000000000002",
      "secondaryObjectId": null,
      "payload": {
        "reason": "all_answers_correct",
        "stepId": "final",
        "performed": true,
        "entityType": "form_definition",
        "gradedCount": 3,
        "incorrectCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "certification",
      "action": "signing_code_consumed",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "ce000100-0000-4000-8000-000000000001",
      "secondaryObjectId": "01a0eafc-79e8-7187-a6dc-8faa8047c673",
      "payload": {
        "signatureId": "01a0eafc-b187-72fb-802c-f9e2abffd9fb"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "decision",
      "action": "tickets.checklist_item_resolve.auto_resolve_ticket",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eafc-56fe-71d9-a174-d792d884e668",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Checklist item is not linked to any ticket.",
        "newState": "completed",
        "oldState": "ready",
        "performed": false,
        "entityType": "checklist_item"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "organization_representation",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Certification completed",
        "toStatus": "active",
        "fromStatus": "pending_certification",
        "reasonCode": "certification_completed",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "certification",
      "action": "completed",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-b187-72fb-802c-f9e13f6eed4f",
      "secondaryObjectId": "ce000100-0000-4000-8000-000000000001",
      "payload": {
        "repUserId": "17b8c9d0-e1f2-3456-1234-567890123456",
        "versionNumber": 2
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "decision",
      "action": "certifications.complete_certification.issue_certificate",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-b187-72fb-802c-f9e13f6eed4f",
      "secondaryObjectId": "01a0eafc-b1b3-703b-8013-29a2a170110a",
      "payload": {
        "reason": "quiz_backed_completion",
        "performed": true,
        "entityType": "certification_record"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.189Z",
      "eventType": "decision",
      "action": "certifications.complete_certification.mark_relationship_certified",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "secondaryObjectId": "01a0eafc-b187-72fb-802c-f9e13f6eed4f",
      "payload": {
        "reason": "relationship_pending_certification",
        "performed": true,
        "entityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:04.230Z",
      "eventType": "user_log",
      "action": "rep_relationship_certified",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "reason": "Certification completed",
        "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
        "userName": "Blair Bennett",
        "userEmail": "blair.bennett@corvetasurgical.com",
        "relationshipId": "84c5d6e7-f8a9-0123-8901-234567890123",
        "distributorOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": "/onboarding/[orgshortname]/certification",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:27:06.358Z",
      "eventType": "certification_certificate",
      "action": "issued",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-b1b3-703b-8013-29a2a170110a",
      "secondaryObjectId": "84c5d6e7-f8a9-0123-8901-234567890123",
      "payload": null,
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:06.366Z",
      "eventType": "certification_completion_record",
      "action": "issued",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-b1b6-7841-ba76-75b3ddcb2d3e",
      "secondaryObjectId": "01a0eafc-b187-72fb-802c-f9e13f6eed4f",
      "payload": {
        "relationshipId": "84c5d6e7-f8a9-0123-8901-234567890123"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:07.212Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:27:18.220Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e879-7036-bce7-20222dab3919",
      "secondaryObjectId": null,
      "payload": {
        "title": "Order OR-1",
        "source": {
          "type": "order_request",
          "orderRequestId": "01a0eafc-e86a-79b6-b898-909bc2869d83"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.220Z",
      "eventType": "decision",
      "action": "order_request_created",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eafc-e86a-79b6-b898-909bc2869d83",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order request OR-1 created (importSource=manual)",
        "priority": "normal",
        "itemCount": 1,
        "orderType": "dropship",
        "performed": true,
        "entityType": "order_request",
        "importSource": "manual",
        "requestNumber": "OR-1",
        "selfFulfilled": false,
        "resolvedLocationId": "6ea3b4c5-d6e7-8901-6789-012345678901",
        "resolvedSalesAccountId": "fea7b8c9-d0e1-2345-0123-456789012345",
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:27:18.220Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": "dropship",
        "performed": false,
        "entityType": "organization",
        "gatedAction": "order_request",
        "isOwnTrunkDestination": false,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [
    {
      "stepName": "Step 1: Admin navigates to rep management",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 2: Admin rejects Blair",
      "expectedAction": "user_log:rep_onboarding_request_rejected",
      "found": true
    },
    {
      "stepName": "Step 3: Blair blocked from creating orders",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 4: Rana (control) can still create orders",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 5: Admin approves Blair",
      "expectedAction": "user_log:rep_onboarding_request_approved",
      "found": true
    },
    {
      "stepName": "Step 5: Admin approves Blair",
      "expectedAction": "decision:representatives.require_certification_on_approval",
      "found": true
    },
    {
      "stepName": "Step 6: Blair completes the certification",
      "expectedAction": "certification:completed",
      "found": true
    },
    {
      "stepName": "Step 7: Blair submits an order after certification",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 7: Blair submits an order after certification",
      "expectedAction": "decision:order_request_created",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 2: Admin rejects Blair",
      "expectedTemplate": "Representative Request Rejected",
      "found": true
    },
    {
      "stepName": "Step 5: Admin approves Blair",
      "expectedTemplate": "Representative Account Approved",
      "found": true
    }
  ]
}