---
title: PacketManager
summary: API reference for PacketManager.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Domain
reference_type: package
---

# PacketManager

`PacketManager` is the entry point for [OP-DOM-19](../../operations-processes.md#op-dom-19): given a policy's candidate output documents, it excludes documents that must not be packeted for related child policies, groups the remainder by policy/document-date/release-date (and, for leftovers, additionally by policy-period effective date), and runs every configured `PacketDefinition` against each group via `PacketGenerator` to produce the final packeted and unpacketed document list ([DOM-BR-200](../../business-rules.md#dom-br-200-packet-creation), [DOM-BR-201](../../business-rules.md#dom-br-201-packet-creation)).

## Purpose
- Excludes specific document types (`312R`, `412R`, `AUDIT`, `312IR`) from packeting when they belong to a child policy in a non-`"WRAP"` relationship, before any grouping happens ([DOM-BR-200](../../business-rules.md#dom-br-200-packet-creation)).
- Groups the remaining documents and attempts to build a packet for each group against every packet definition, first without regard to policy period, then a second pass (grouped additionally by policy-period effective date) for documents left unpacketed after the first pass ([DOM-BR-201](../../business-rules.md#dom-br-201-packet-creation)).
- Retrieves the single `PacketDefinition` matching a given packet ID and uses it to select, from a candidate document list, exactly the documents that belong with a given primary document — the read-only counterpart to full packet creation.

## Context
- Namespace: `SAIF.Domain.Tasks.Documents.Packets`
- Assembly/package: `SAIF.Domain` (packaged in `SAIF.SAIFCode.Core`)
- Marked with a source-code comment about moving this class to a service, indicating this static class is considered a candidate for relocation into a service layer*.

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| CreatePackets | `public static IEnumerable<PolicyDocument> CreatePackets(IEnumerable<PolicyOutputDocument> docs, IPolicyOutputDocumentRepository policyOutputDocumentRepository, IUnitOfWork unitOfWork)` | Excludes ineligible child-policy documents, groups the remainder, runs every packet definition against each group in two passes (by date, then by policy period for leftovers), and returns both the resulting packets and any documents that were never packeted, mapped to `PolicyDocument` contracts ([DOM-BR-200](../../business-rules.md#dom-br-200-packet-creation), [DOM-BR-201](../../business-rules.md#dom-br-201-packet-creation)). |
| GetDocumentsForPacket | `public static IEnumerable<PolicyDocument> GetDocumentsForPacket(IEnumerable<PolicyOutputDocument> docs, string packetId, IUnitOfWork unitOfWork, PolicyOutputDocument primaryDocument)` | Loads the packet definition for `packetId` and returns the subset of `docs` that a `PacketGenerator` for that definition would include alongside `primaryDocument`, mapped to `PolicyDocument` contracts. |
| GetPacketDefinition | `public static PacketDefinition GetPacketDefinition(string packetId, IUnitOfWork unitOfWork)` | Retrieves the single `PacketDefinition` identified by `packetId`. |

## Behavioral notes
- `CreatePackets` runs a second grouping-and-generation pass, keyed additionally by policy-period effective date, only over documents left ungrouped after the first pass — so a document that already found a packet in the first pass is never reconsidered in the second*.
- Documents that remain in `DocumentGroupsByPeriod` after the second pass (i.e., never matched any packet definition) are still returned by `CreatePackets`, individually mapped rather than dropped, so the method's result mixes actual packets with leftover unpacketed documents*.

## Constraints and usage notes
- `CreatePackets` returns an empty list immediately if `docs` is empty, without constructing a `PacketRequest` or loading any definitions.

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Sources
- `Domain/SAIF.Domain/Tasks/Documents/Packets/PacketManager.cs`
- `Domain/SAIF.Domain/Tasks/Documents/Packets/PacketRequest.cs`
- `Domain/SAIF.Domain/Tasks/Documents/Packets/PacketGenerator.cs`
- `Domain/SAIF.Domain/Tasks/Documents/Packets/PacketDefinition.cs`
