# SWIFT MT/MX to DBIS Nostro/Vostro API Mapping

## Overview

This document provides mapping guidance for converting SWIFT messages to DBIS Nostro/Vostro API requests.

## Message Types

### MT103 (Customer Credit Transfer)

**SWIFT Format**:
```
{1:F01BANKUS33AXXX1234567890}
{2:O1031200240115BANKUS33AXXX123456789012345678901234567890}
{3:{108:TRF123}}
{4:
:20:TRF123
:23B:CRED
:32A:240115USD1000,00
:50K:/1234567890
JOHN DOE
:59:/GB82WEST12345698765432
JANE SMITH
:70:PAYMENT REFERENCE
-}
```

**DBIS API Request**:
```json
{
  "fromAccountId": "1234567890",
  "toAccountId": "GB82WEST12345698765432",
  "amount": "1000.00",
  "currency": "USD",
  "valueDate": "2024-01-15",
  "reference": "TRF123",
  "metadata": {
    "swiftMessageType": "103",
    "swiftReference": "TRF123"
  }
}
```

### MT202 (General Financial Institution Transfer)

Similar to MT103 but for interbank transfers.

### MX (ISO 20022) Messages

See [ISO 20022 Mapping Guide](./iso20022-mapping.md) for MX message handling.

## Field Mappings

| SWIFT Field | DBIS API Field | Notes |
|-------------|----------------|-------|
| `:20:` | `reference` | Transaction reference |
| `:32A:` (date) | `valueDate` | Value date (YYMMDD format) |
| `:32A:` (currency) | `currency` | Currency code |
| `:32A:` (amount) | `amount` | Transfer amount |
| `:50K:` or `:50A:` | `fromAccountId` | Ordering customer account |
| `:59:` | `toAccountId` | Beneficiary account |
| `:52A:` | `fromParticipantId` | Sender BIC |
| `:56A:` | `toParticipantId` | Receiver BIC |
| `:70:` | `reference` | Remittance information |

## Implementation

Use the `SwiftAdapter` class:

```typescript
import { SwiftAdapter } from '@/integration/plugins/swift-adapter';

const adapter = new SwiftAdapter();
const swiftMessage = adapter.parseSwiftMessage(mt103String);
const transferRequest = adapter.mapTransfer(swiftMessage);
```

## Date Format Conversion

SWIFT uses YYMMDD format, DBIS uses ISO 8601:

```typescript
// SWIFT: 240115
// DBIS: 2024-01-15
```

## Error Handling

SWIFT errors map to DBIS error codes:

| SWIFT Error | DBIS Error Code |
|-------------|-----------------|
| Invalid message format | `VALIDATION_ERROR` |
| Account not found | `NOT_FOUND` |
| Invalid BIC | `VALIDATION_ERROR` |

