pleme-codegen 0.1.2

Code generation macros for Pleme services with Brazilian market features
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! BrazilianPaymentEntity derive macro implementation
//!
//! Enhanced Brazilian market features for payments including PIX integration,
//! tax calculations (ICMS, PIS/COFINS), Brazilian document validation,
//! and currency formatting.

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, format_ident};
use syn::{parse_macro_input, DeriveInput, Data, Fields, Field, Attribute, Meta, NestedMeta, Lit};

/// Brazilian payment configuration
#[derive(Default)]
struct BrazilianConfig {
    pix_support: bool,
    boleto_support: bool,
    tax_calculation: bool,
    tax_type: Option<String>,
    currency: String,
    tax_rate_icms: f64,
    tax_rate_pis: f64,
    tax_rate_cofins: f64,
}

impl BrazilianConfig {
    fn from_attrs(attrs: &[Attribute]) -> Self {
        let mut config = BrazilianConfig {
            pix_support: true,
            boleto_support: true,
            tax_calculation: true,
            currency: "BRL".to_string(),
            tax_rate_icms: 0.18,    // 18% ICMS default
            tax_rate_pis: 0.0165,   // 1.65% PIS
            tax_rate_cofins: 0.076, // 7.6% COFINS
            ..Default::default()
        };
        
        for attr in attrs {
            if attr.path.is_ident("brazilian_payment") {
                if let Ok(Meta::List(meta_list)) = attr.parse_meta() {
                    for nested_meta in meta_list.nested {
                        match nested_meta {
                            NestedMeta::Meta(Meta::NameValue(name_value)) => {
                                match name_value.path.get_ident().map(|i| i.to_string()).as_deref() {
                                    Some("tax_type") => {
                                        if let Lit::Str(lit_str) = name_value.lit {
                                            config.tax_type = Some(lit_str.value());
                                        }
                                    }
                                    Some("currency") => {
                                        if let Lit::Str(lit_str) = name_value.lit {
                                            config.currency = lit_str.value();
                                        }
                                    }
                                    Some("icms_rate") => {
                                        if let Lit::Float(lit_float) = name_value.lit {
                                            config.tax_rate_icms = lit_float.base10_parse().unwrap_or(0.18);
                                        }
                                    }
                                    Some("pis_rate") => {
                                        if let Lit::Float(lit_float) = name_value.lit {
                                            config.tax_rate_pis = lit_float.base10_parse().unwrap_or(0.0165);
                                        }
                                    }
                                    Some("cofins_rate") => {
                                        if let Lit::Float(lit_float) = name_value.lit {
                                            config.tax_rate_cofins = lit_float.base10_parse().unwrap_or(0.076);
                                        }
                                    }
                                    _ => {}
                                }
                            }
                            NestedMeta::Meta(Meta::Path(path)) => {
                                if path.is_ident("no_pix") {
                                    config.pix_support = false;
                                } else if path.is_ident("no_boleto") {
                                    config.boleto_support = false;
                                } else if path.is_ident("no_tax") {
                                    config.tax_calculation = false;
                                }
                            }
                            _ => {}
                        }
                    }
                }
            }
        }
        
        config
    }
}

pub fn derive_brazilian_payment_entity(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let struct_name = &input.ident;
    let config = BrazilianConfig::from_attrs(&input.attrs);
    
    let pix_methods = if config.pix_support {
        quote! {
            /// Generate PIX QR Code for payment
            pub fn generate_pix_qr_code(&self) -> Result<String, BrazilianPaymentError> {
                if let Some(amount) = self.get_amount() {
                    let pix_data = PixData {
                        merchant_name: "Pleme Payment",
                        merchant_city: "São Paulo",
                        transaction_id: self.get_id().to_string(),
                        amount: amount,
                        currency: &#config.currency,
                    };
                    
                    let qr_code = generate_pix_qr(&pix_data)?;
                    
                    tracing::info!(
                        entity = %stringify!(#struct_name),
                        transaction_id = %self.get_id(),
                        amount = %amount,
                        "PIX QR Code generated"
                    );
                    
                    Ok(qr_code)
                } else {
                    Err(BrazilianPaymentError::InvalidAmount("Amount is required for PIX".to_string()))
                }
            }
            
            /// Validate PIX key format and type
            pub fn validate_pix_key(key: &str, key_type: PixKeyType) -> Result<(), BrazilianPaymentError> {
                match key_type {
                    PixKeyType::Cpf => {
                        if !Self::validate_cpf(key) {
                            return Err(BrazilianPaymentError::InvalidPixKey(
                                format!("Invalid CPF: {}", key)
                            ));
                        }
                    }
                    PixKeyType::Cnpj => {
                        if !Self::validate_cnpj(key) {
                            return Err(BrazilianPaymentError::InvalidPixKey(
                                format!("Invalid CNPJ: {}", key)
                            ));
                        }
                    }
                    PixKeyType::Email => {
                        if !Self::validate_email(key) {
                            return Err(BrazilianPaymentError::InvalidPixKey(
                                format!("Invalid email: {}", key)
                            ));
                        }
                    }
                    PixKeyType::Phone => {
                        if !Self::validate_brazilian_phone(key) {
                            return Err(BrazilianPaymentError::InvalidPixKey(
                                format!("Invalid Brazilian phone: {}", key)
                            ));
                        }
                    }
                    PixKeyType::Random => {
                        if !Self::validate_uuid_key(key) {
                            return Err(BrazilianPaymentError::InvalidPixKey(
                                format!("Invalid random PIX key: {}", key)
                            ));
                        }
                    }
                }
                
                tracing::debug!(
                    entity = %stringify!(#struct_name),
                    key_type = ?key_type,
                    "PIX key validation passed"
                );
                
                Ok(())
            }
            
            /// Validate UUID format for random PIX keys
            fn validate_uuid_key(key: &str) -> bool {
                uuid::Uuid::parse_str(key).is_ok()
            }
            
            /// Process PIX instant payment confirmation
            pub fn process_pix_confirmation(&mut self, end_to_end_id: &str, psp_reference: &str) -> Result<(), BrazilianPaymentError> {
                if end_to_end_id.len() != 32 {
                    return Err(BrazilianPaymentError::InvalidPixData(
                        "Invalid end-to-end ID format".to_string()
                    ));
                }
                
                self.set_status(PaymentStatus::Completed);
                self.set_updated_at(chrono::Utc::now());
                
                tracing::info!(
                    entity = %stringify!(#struct_name),
                    transaction_id = %self.get_id(),
                    end_to_end_id = %end_to_end_id,
                    psp_reference = %psp_reference,
                    "PIX payment confirmed"
                );
                
                Ok(())
            }
        }
    } else {
        quote! {}
    };
    
    let boleto_methods = if config.boleto_support {
        quote! {
            /// Generate Boleto bancário for payment
            pub fn generate_boleto(&self) -> Result<BoletoData, BrazilianPaymentError> {
                if let Some(amount) = self.get_amount() {
                    let due_date = chrono::Utc::now() + chrono::Duration::days(3);
                    
                    let boleto = BoletoData {
                        bank_code: "341", // Itaú default
                        agency: "1234",
                        account: "12345-6",
                        wallet: "109",
                        our_number: format!("{:013}", self.get_id().as_u128() % 10_000_000_000_000),
                        document_number: self.get_id().to_string(),
                        due_date,
                        amount,
                        payer_name: "Cliente".to_string(), // Would be extracted from customer data
                        payer_document: "000.000.000-00".to_string(),
                        instructions: vec![
                            "Não receber após o vencimento".to_string(),
                            "Pagamento via PIX disponível".to_string(),
                        ],
                    };
                    
                    tracing::info!(
                        entity = %stringify!(#struct_name),
                        transaction_id = %self.get_id(),
                        due_date = %due_date,
                        amount = %amount,
                        "Boleto generated"
                    );
                    
                    Ok(boleto)
                } else {
                    Err(BrazilianPaymentError::InvalidAmount("Amount is required for Boleto".to_string()))
                }
            }
            
            /// Calculate Boleto verification digit
            pub fn calculate_boleto_dv(code: &str) -> String {
                // Implement modulo 11 verification digit calculation
                let weights = [2, 3, 4, 5, 6, 7, 8, 9];
                let mut sum = 0;
                
                for (i, digit) in code.chars().rev().enumerate() {
                    if let Some(d) = digit.to_digit(10) {
                        sum += (d as usize) * weights[i % weights.len()];
                    }
                }
                
                let remainder = sum % 11;
                let dv = match remainder {
                    0 | 1 => 0,
                    _ => 11 - remainder,
                };
                
                dv.to_string()
            }
        }
    } else {
        quote! {}
    };
    
    let tax_methods = if config.tax_calculation {
        let icms_rate = config.tax_rate_icms;
        let pis_rate = config.tax_rate_pis;
        let cofins_rate = config.tax_rate_cofins;
        
        quote! {
            /// Calculate Brazilian taxes (ICMS, PIS, COFINS)
            pub fn calculate_brazilian_taxes(&self) -> Result<BrazilianTaxBreakdown, BrazilianPaymentError> {
                if let Some(gross_amount) = self.get_amount() {
                    let icms = gross_amount * rust_decimal::Decimal::from_f64(#icms_rate)
                        .ok_or(BrazilianPaymentError::TaxCalculationError("Invalid ICMS rate".to_string()))?;
                    
                    let pis = gross_amount * rust_decimal::Decimal::from_f64(#pis_rate)
                        .ok_or(BrazilianPaymentError::TaxCalculationError("Invalid PIS rate".to_string()))?;
                    
                    let cofins = gross_amount * rust_decimal::Decimal::from_f64(#cofins_rate)
                        .ok_or(BrazilianPaymentError::TaxCalculationError("Invalid COFINS rate".to_string()))?;
                    
                    let total_taxes = icms + pis + cofins;
                    let net_amount = gross_amount - total_taxes;
                    
                    let breakdown = BrazilianTaxBreakdown {
                        gross_amount,
                        icms_amount: icms,
                        icms_rate: rust_decimal::Decimal::from_f64(#icms_rate).unwrap(),
                        pis_amount: pis,
                        pis_rate: rust_decimal::Decimal::from_f64(#pis_rate).unwrap(),
                        cofins_amount: cofins,
                        cofins_rate: rust_decimal::Decimal::from_f64(#cofins_rate).unwrap(),
                        total_taxes,
                        net_amount,
                        currency: #config.currency.to_string(),
                    };
                    
                    tracing::debug!(
                        entity = %stringify!(#struct_name),
                        gross_amount = %gross_amount,
                        total_taxes = %total_taxes,
                        net_amount = %net_amount,
                        "Brazilian taxes calculated"
                    );
                    
                    Ok(breakdown)
                } else {
                    Err(BrazilianPaymentError::InvalidAmount("Amount is required for tax calculation".to_string()))
                }
            }
            
            /// Apply tax exemptions based on Brazilian regulations
            pub fn apply_tax_exemptions(&self, exemptions: Vec<TaxExemption>) -> Result<BrazilianTaxBreakdown, BrazilianPaymentError> {
                let mut base_taxes = self.calculate_brazilian_taxes()?;
                
                for exemption in exemptions {
                    match exemption.tax_type {
                        TaxType::Icms => {
                            base_taxes.icms_amount = base_taxes.icms_amount * 
                                (rust_decimal::Decimal::ONE - exemption.exemption_rate);
                        }
                        TaxType::Pis => {
                            base_taxes.pis_amount = base_taxes.pis_amount * 
                                (rust_decimal::Decimal::ONE - exemption.exemption_rate);
                        }
                        TaxType::Cofins => {
                            base_taxes.cofins_amount = base_taxes.cofins_amount * 
                                (rust_decimal::Decimal::ONE - exemption.exemption_rate);
                        }
                    }
                    
                    tracing::info!(
                        entity = %stringify!(#struct_name),
                        tax_type = ?exemption.tax_type,
                        exemption_rate = %exemption.exemption_rate,
                        "Tax exemption applied"
                    );
                }
                
                base_taxes.total_taxes = base_taxes.icms_amount + base_taxes.pis_amount + base_taxes.cofins_amount;
                base_taxes.net_amount = base_taxes.gross_amount - base_taxes.total_taxes;
                
                Ok(base_taxes)
            }
        }
    } else {
        quote! {}
    };
    
    let expanded = quote! {
        impl #struct_name {
            #pix_methods
            #boleto_methods
            #tax_methods
            
            /// Format amount in Brazilian Real (BRL) with proper formatting
            pub fn format_brl_amount(amount: rust_decimal::Decimal) -> String {
                // Format as R$ 1.234,56
                let amount_str = amount.to_string();
                let parts: Vec<&str> = amount_str.split('.').collect();
                
                let integer_part = parts[0];
                let decimal_part = parts.get(1).unwrap_or(&"00");
                
                // Add thousand separators
                let mut formatted_integer = String::new();
                for (i, char) in integer_part.chars().rev().enumerate() {
                    if i > 0 && i % 3 == 0 {
                        formatted_integer.push('.');
                    }
                    formatted_integer.push(char);
                }
                
                let formatted_integer: String = formatted_integer.chars().rev().collect();
                format!("R$ {},{:0<2}", formatted_integer, &decimal_part[..2.min(decimal_part.len())])
            }
            
            /// Parse BRL formatted amount to Decimal
            pub fn parse_brl_amount(formatted: &str) -> Result<rust_decimal::Decimal, BrazilianPaymentError> {
                let cleaned = formatted
                    .replace("R$", "")
                    .replace(" ", "")
                    .replace(".", "")
                    .replace(",", ".");
                
                cleaned.parse::<rust_decimal::Decimal>()
                    .map_err(|e| BrazilianPaymentError::InvalidAmount(
                        format!("Failed to parse BRL amount '{}': {}", formatted, e)
                    ))
            }
            
            /// Validate email format for PIX keys
            fn validate_email(email: &str) -> bool {
                let email_regex = regex::Regex::new(
                    r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
                ).unwrap();
                email_regex.is_match(email)
            }
            
            /// Generate payment receipt in Portuguese
            pub fn generate_brazilian_receipt(&self) -> Result<BrazilianReceipt, BrazilianPaymentError> {
                let receipt = BrazilianReceipt {
                    transaction_id: self.get_id().to_string(),
                    date: chrono::Utc::now().with_timezone(&chrono_tz::America::Sao_Paulo),
                    amount: self.get_amount().ok_or(BrazilianPaymentError::InvalidAmount(
                        "Amount is required".to_string()
                    ))?,
                    formatted_amount: Self::format_brl_amount(self.get_amount().unwrap()),
                    payment_method: self.get_payment_method_description(),
                    status: self.get_payment_status_portuguese(),
                    merchant_name: "Pleme Tecnologia Ltda".to_string(),
                    merchant_cnpj: "12.345.678/0001-90".to_string(),
                    customer_document: self.get_customer_document().unwrap_or_default(),
                };
                
                tracing::info!(
                    entity = %stringify!(#struct_name),
                    transaction_id = %receipt.transaction_id,
                    "Brazilian receipt generated"
                );
                
                Ok(receipt)
            }
            
            /// Get payment status in Portuguese
            fn get_payment_status_portuguese(&self) -> String {
                match self.get_status() {
                    PaymentStatus::Pending => "Pendente".to_string(),
                    PaymentStatus::Processing => "Processando".to_string(),
                    PaymentStatus::Completed => "Concluído".to_string(),
                    PaymentStatus::Failed => "Falhou".to_string(),
                    PaymentStatus::Refunded => "Estornado".to_string(),
                    PaymentStatus::Cancelled => "Cancelado".to_string(),
                }
            }
            
            /// Get payment method description in Portuguese
            fn get_payment_method_description(&self) -> String {
                // This would be implemented based on the actual payment method field
                "PIX".to_string() // Default to PIX as primary Brazilian payment method
            }
            
            /// Check if payment complies with Brazilian Central Bank regulations
            pub fn validate_bcb_compliance(&self) -> Result<ComplianceResult, BrazilianPaymentError> {
                let mut issues = Vec::new();
                let mut warnings = Vec::new();
                
                // Check amount limits (PIX has instant transfer limits)
                if let Some(amount) = self.get_amount() {
                    if amount > rust_decimal::Decimal::from(20000) { // R$ 20,000 daily limit
                        warnings.push("Amount exceeds PIX daily limit".to_string());
                    }
                    
                    if amount > rust_decimal::Decimal::from(100000) { // R$ 100,000 monthly limit  
                        issues.push("Amount exceeds PIX monthly limit".to_string());
                    }
                }
                
                // Check business hours for larger amounts
                let now = chrono::Utc::now().with_timezone(&chrono_tz::America::Sao_Paulo);
                let hour = now.hour();
                
                if let Some(amount) = self.get_amount() {
                    if amount > rust_decimal::Decimal::from(1000) && (hour < 6 || hour > 20) {
                        warnings.push("Large amount transfer outside business hours".to_string());
                    }
                }
                
                let compliance = ComplianceResult {
                    is_compliant: issues.is_empty(),
                    issues,
                    warnings,
                    checked_at: chrono::Utc::now(),
                    regulations: vec![
                        "BCB Resolution 4,488/2016".to_string(),
                        "BCB Circular 4,027/2020".to_string(),
                    ],
                };
                
                tracing::info!(
                    entity = %stringify!(#struct_name),
                    is_compliant = %compliance.is_compliant,
                    issues_count = %compliance.issues.len(),
                    warnings_count = %compliance.warnings.len(),
                    "BCB compliance check completed"
                );
                
                Ok(compliance)
            }
            
            // Abstract methods that implementing structs must provide
            fn get_id(&self) -> uuid::Uuid;
            fn get_amount(&self) -> Option<rust_decimal::Decimal>;
            fn get_status(&self) -> PaymentStatus;
            fn set_status(&mut self, status: PaymentStatus);
            fn set_updated_at(&mut self, timestamp: chrono::DateTime<chrono::Utc>);
            fn get_customer_document(&self) -> Option<String>;
        }
        
        /// PIX QR Code data structure
        #[derive(Debug, Clone)]
        pub struct PixData {
            pub merchant_name: &'static str,
            pub merchant_city: &'static str,
            pub transaction_id: String,
            pub amount: rust_decimal::Decimal,
            pub currency: &'static str,
        }
        
        /// PIX key types supported in Brazil
        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
        pub enum PixKeyType {
            Cpf,
            Cnpj,
            Email,
            Phone,
            Random,
        }
        
        /// Boleto bancário data structure
        #[derive(Debug, Clone)]
        pub struct BoletoData {
            pub bank_code: &'static str,
            pub agency: &'static str,
            pub account: &'static str,
            pub wallet: &'static str,
            pub our_number: String,
            pub document_number: String,
            pub due_date: chrono::DateTime<chrono::Utc>,
            pub amount: rust_decimal::Decimal,
            pub payer_name: String,
            pub payer_document: String,
            pub instructions: Vec<String>,
        }
        
        /// Brazilian tax breakdown
        #[derive(Debug, Clone)]
        pub struct BrazilianTaxBreakdown {
            pub gross_amount: rust_decimal::Decimal,
            pub icms_amount: rust_decimal::Decimal,
            pub icms_rate: rust_decimal::Decimal,
            pub pis_amount: rust_decimal::Decimal,
            pub pis_rate: rust_decimal::Decimal,
            pub cofins_amount: rust_decimal::Decimal,
            pub cofins_rate: rust_decimal::Decimal,
            pub total_taxes: rust_decimal::Decimal,
            pub net_amount: rust_decimal::Decimal,
            pub currency: String,
        }
        
        /// Tax exemption configuration
        #[derive(Debug, Clone)]
        pub struct TaxExemption {
            pub tax_type: TaxType,
            pub exemption_rate: rust_decimal::Decimal,
            pub reason: String,
        }
        
        /// Brazilian tax types
        #[derive(Debug, Clone, Copy)]
        pub enum TaxType {
            Icms,  // State tax on goods and services
            Pis,   // Social contribution on revenue  
            Cofins, // Social contribution on revenue
        }
        
        /// Brazilian payment receipt
        #[derive(Debug, Clone)]
        pub struct BrazilianReceipt {
            pub transaction_id: String,
            pub date: chrono::DateTime<chrono_tz::Tz>,
            pub amount: rust_decimal::Decimal,
            pub formatted_amount: String,
            pub payment_method: String,
            pub status: String,
            pub merchant_name: String,
            pub merchant_cnpj: String,
            pub customer_document: String,
        }
        
        /// BCB compliance check result
        #[derive(Debug, Clone)]
        pub struct ComplianceResult {
            pub is_compliant: bool,
            pub issues: Vec<String>,
            pub warnings: Vec<String>,
            pub checked_at: chrono::DateTime<chrono::Utc>,
            pub regulations: Vec<String>,
        }
        
        /// Brazilian payment specific errors
        #[derive(Debug, thiserror::Error)]
        pub enum BrazilianPaymentError {
            #[error("Invalid amount: {0}")]
            InvalidAmount(String),
            
            #[error("Invalid PIX key: {0}")]
            InvalidPixKey(String),
            
            #[error("Invalid PIX data: {0}")]
            InvalidPixData(String),
            
            #[error("Tax calculation error: {0}")]
            TaxCalculationError(String),
            
            #[error("Compliance violation: {0}")]
            ComplianceViolation(String),
        }
        
        /// Generate PIX QR code (placeholder implementation)
        fn generate_pix_qr(data: &PixData) -> Result<String, BrazilianPaymentError> {
            // In a real implementation, this would generate the actual PIX QR code format
            // following the Brazilian Central Bank specifications
            Ok(format!("pix://pay?amount={}&id={}", data.amount, data.transaction_id))
        }
    };
    
    eprintln!("[pleme-codegen] BrazilianPaymentEntity pattern applied to {}", struct_name);
    TokenStream::from(expanded)
}