package store import ( "encoding/json" "fmt" "time" ) // R1 intake (0028, docgen#6 F01): the original capture of a security // notice, its supplements and what became of each downstream. Nothing is // ever changed. // Intake channels, what a report is about by the reporter's own account, and // the reporter's answer to "immediate danger to people?". const ( IntakeChannelPortal = "portal" IntakeAboutProduct = "product" IntakeAboutITOT = "it_ot" IntakeAboutUnknown = "unknown" IntakeEntryCapture = "capture" IntakeEntrySupplement = "supplement" IntakeWaiting = "waiting" IntakeDelivered = "delivered" IntakeProcessed = "processed" IntakeRefused = "refused" ) // IntakeReference is the Eingangsreferenz of a tenant's seq-th report, // received at. func IntakeReference(at time.Time, seq int) string { return fmt.Sprintf("SH-%04d-%05d", at.UTC().Year(), seq) } // IntakeReport is one report: its reference, the time of the first R1 // capture, the channel, the reporter and the reporter's own answers. type IntakeReport struct { TenantID string `json:"tenant_id"` Reference string `json:"reference"` ReceivedAt time.Time `json:"received_at"` Channel string `json:"channel"` ReporterSub string `json:"-"` About string `json:"about"` Danger string `json:"danger"` } // IntakeEntry is the capture or a supplement, with its receipts, oldest // first. Content is the original as entered. type IntakeEntry struct { ID int64 `json:"id"` TenantID string `json:"-"` Reference string `json:"-"` Kind string `json:"kind"` Content json.RawMessage `json:"-"` By string `json:"-"` At time.Time `json:"at"` Receipts []IntakeReceipt `json:"receipts"` } // Status is the newest receipt's status, "" before the first one. func (e IntakeEntry) Status() string { if len(e.Receipts) == 0 { return "" } return e.Receipts[len(e.Receipts)-1].Status } // IntakeReceipt is what became of an entry downstream. type IntakeReceipt struct { EntryID int64 `json:"-"` Status string `json:"status"` Reason string `json:"reason,omitempty"` HandoffID string `json:"handoff_id,omitempty"` RunID string `json:"run_id,omitempty"` By string `json:"-"` At time.Time `json:"at"` } // Settled: processed or refused, after which no receipt follows. func (r IntakeReceipt) Settled() bool { return r.Status == IntakeProcessed || r.Status == IntakeRefused } // IntakeCapture records a new report. type IntakeCapture struct { TenantID string Channel string ReporterSub string About string Danger string Original json.RawMessage At time.Time } // PendingIntake is an entry not settled yet, with what routing reads of its // report; never its content. type PendingIntake struct { EntryID int64 `json:"entry_id"` TenantID string `json:"tenant_id"` Reference string `json:"reference"` Kind string `json:"kind"` At time.Time `json:"at"` ReceivedAt time.Time `json:"received_at"` Channel string `json:"channel"` About string `json:"about"` Danger string `json:"danger"` Status string `json:"status,omitempty"` Reason string `json:"reason,omitempty"` HandoffID string `json:"handoff_id,omitempty"` // CaptureSettled: the report's capture is processed or refused. A // supplement is handed over only after its capture. CaptureSettled bool `json:"capture_settled"` }