#!/usr/bin/env python3
"""
Example: Tokenize SWIFT FIN message
"""

import os
import sys
import json

# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from parsers.swift_fin_parser import SWIFTFINParser
from financial_tokenization_service import FireflyClient, FinancialTokenizationService

# Configuration
FIREFLY_API_URL = os.getenv('FIREFLY_API_URL', 'http://firefly-api:5000')
FIREFLY_API_KEY = os.getenv('FIREFLY_API_KEY', '')

# Sample SWIFT FIN MT103 message
SAMPLE_MT103 = """{1:F01BANKUS33AXXX1234567890}
{2:O1031200240101BANKUS33AXXX1234567890123456789012345678901234567890}
{3:{108:MT103}}
{4:
:20:REF123
:23B:CRED
:32A:240101USD1000,00
:50A:/US1234567890
BANK US
:59:/US9876543210
CREDITOR NAME
:70:Payment for services
:71A:SHA
-}
{5:{MAC:12345678}{CHK:ABCDEF123456}{TNG:}{PDE:}}
{S:{COP:P}}"""

def main():
    """Main function"""
    print("Tokenizing SWIFT FIN message...")
    
    # Initialize clients
    firefly_client = FireflyClient(FIREFLY_API_URL, FIREFLY_API_KEY)
    tokenization_service = FinancialTokenizationService(firefly_client)
    
    # Tokenize message
    try:
        result = tokenization_service.tokenize_swift_fin(
            SAMPLE_MT103,
            "mt103_001.txt"
        )
        
        print(f"✅ Tokenization successful!")
        print(f"Message Type: {result['messageType']}")
        print(f"NFT ID: {result['nft']['id']}")
        print(f"IPFS ID: {result['ipfsId']}")
        print(f"Parsed data: {json.dumps(result['parsed'], indent=2)}")
    except Exception as e:
        print(f"❌ Tokenization failed: {e}")
        sys.exit(1)

if __name__ == '__main__':
    main()

