File size: 1,530 Bytes
d7d8e9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# validator.py
import re
from datetime import datetime

class DataValidator:
    @staticmethod
    def validate_email(email):
        """Validate email format"""
        pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
        return bool(re.match(pattern, email))


    @staticmethod
    def validate_workflow_state(workflow_state_dict):
        """Validate workflow state data"""
        errors = []
        
        # Customer data validation
        customer = workflow_state_dict.get('customer', {})
        if not customer.get('cust_unique_id'):
            errors.append("Customer ID is required")
        if not customer.get('cust_tax_id'):
            errors.append("Tax ID is required")
        if not customer.get('cust_email'):
            errors.append("Email is required")
        elif not DataValidator.validate_email(customer['cust_email']):
            errors.append("Invalid email format")

        # Invoice data validation
        invoice = workflow_state_dict.get('invoice', {})
        if not invoice.get('billed_amount'):
            errors.append("Billed amount is required")
        else:
            try:
                if float(invoice['billed_amount']) <= 0:
                    errors.append("Billed amount must be positive")
            except ValueError:
                errors.append("Invalid billed amount")

        if not invoice.get('currency'):
            errors.append("Currency is required")

        return errors if errors else None