# edifact-mapper

Bidirectional EDIFACT to BO4E conversion for the German energy market.

## Installation

```bash
cargo add edifact-mapper
cargo install edifact-data
```

## Data Setup

The mapping engine requires pre-built data bundles. Download them with the CLI:

```bash
# Fetch a specific format version
edifact-data fetch FV2504

# Or all available versions
edifact-data fetch --all

# List locally available bundles
edifact-data list
```

Data is stored in `~/.edifact/data/` by default. Override with `$EDIFACT_DATA_DIR`.

## Usage

### High-Level API

```rust,no_run
use edifact_mapper::{DataDir, Mapper};

let mapper = Mapper::from_data_dir(DataDir::auto()).unwrap();

// Get a conversion service for tree assembly
let service = mapper.conversion_service("FV2504", "UTILMD_Strom").unwrap();

// Get a mapping engine for a specific PID
let engine = mapper.engine("FV2504", "UTILMD_Strom", "55001").unwrap();
```

### Mid-Level Access

```rust,no_run
use edifact_mapper::{AssembledTree, ConversionService, MappingEngine, Mapper, DataDir};

let mapper = Mapper::from_data_dir(DataDir::auto()).unwrap();
let service = mapper.conversion_service("FV2504", "UTILMD_Strom").unwrap();
let tree = service.convert_to_assembled_tree(&edifact_input).unwrap();
```

### Standalone Parser

If you only need EDIFACT parsing without BO4E mapping:

```bash
cargo add edifact-parser
```

```rust
use edifact_parser::EdifactStreamParser;
```

## Environment Variables

| Variable | Default | Description |
|---|---|---|
| `EDIFACT_DATA_DIR` | `~/.edifact/data/` | Data bundle directory |
| `GITHUB_TOKEN` | — | GitHub token for private repo access (or use `--token`) |

## Supported Message Types

UTILMD (Strom/Gas), MSCONS, ORDERS, ORDRSP, REMADV, COMDIS, ORDCHG,
PRICAT, IFTSTA, UTILTS, INVOIC, INSRPT, PARTIN, APERAK, CONTRL

## Format Versions

FV2504, FV2510, FV2604

## License

MIT
