# PostAccountingEvent

## Permission Scope

accountingEvent

## Overview

postAccountingEvent records an immutable accounting event emitted by a source module. It validates company scope, stores eventKind and schemaVersion as top-level routing and parsing keys, and persists the typed payload as payloadJson. It does not create journal entries, select an accounting destination, or invoke resolver execution.

## Business Rules

- Creates one append-only AccountingEvent record
- Requires an existing company
- Requires eventKind and schemaVersion
- Sets occurredAt when the event is posted
- Stringifies the typed payload into payloadJson before insert
- Source document references, accounting date, currency, amount, and event-specific facts belong inside payload
- payloadJson is stored as an immutable resolver-neutral snapshot
- Destination selection, journal posting, external API payloads, and resolver execution are out of scope

## Process Flow

```mermaid
flowchart TD
    A[Receive post accounting event request] --> B{Company exists?}
    B -->|No| C[Return error: company not found]
    B -->|Yes| D[Stringify payload]
    D --> E[Insert AccountingEvent]
    E --> F[Return created AccountingEvent]
```

## External Dependencies

- None

## Error Scenarios

- **COMPANY_NOT_FOUND**: Referenced company does not exist

## Test Cases

- posts accounting event with typed payload
- stringifies the typed payload before insert
- returns error when company does not exist
