# Datagen - Test Data Generator

Pluggable test data generators for various domain models and external APIs.

## Purpose

- Generate realistic test data for Amar domain models
- Generate mock API responses for external services (MercadoPago, etc.)
- Can be plugged into any nest (test suites, mock veins, seeders)
- Domain-agnostic and reusable

## Structure

```
datagen/
├── __init__.py
├── amar.py           # Amar domain models (petowner, pet, cart, etc.)
├── mercadopago.py    # MercadoPago API responses
└── README.md         # This file
```

## Usage

### In Tests

```python
from ward.tools.datagen.amar import AmarDataGenerator

def test_petowner_creation():
    owner_data = AmarDataGenerator.petowner(address="Av. Corrientes 1234")
    assert owner_data["address"] == "Av. Corrientes 1234"
```

### In Mock Veins

```python
from ward.tools.datagen.mercadopago import MercadoPagoDataGenerator

@router.post("/v1/preferences")
async def create_preference(request: dict):
    # Generate mock response
    return MercadoPagoDataGenerator.preference(
        description=request["items"][0]["title"],
        total=request["items"][0]["unit_price"],
    )
```

### In Seeders

```python
from ward.tools.datagen.amar import AmarDataGenerator

# Create 10 test pet owners
for i in range(10):
    owner = AmarDataGenerator.petowner(is_guest=False)
    # Save to database...
```

## Design Principles

1. **Pluggable**: Can be used anywhere, not tied to specific frameworks
2. **Realistic**: Generated data matches real-world patterns
3. **Flexible**: Override any field via `**overrides` parameter
4. **Domain-focused**: Each generator focuses on a specific domain
5. **Stateless**: Pure functions, no global state

## Generators

### AmarDataGenerator (amar.py)

Generates data for Amar platform:

- `petowner()` - Pet owners (guest and registered)
- `pet()` - Pets with species, age, etc.
- `cart()` - Shopping carts
- `service_request()` - Service requests
- `filter_services()` - Service filtering by species/neighborhood
- `filter_categories()` - Category filtering
- `calculate_cart_summary()` - Cart totals with discounts

### MercadoPagoDataGenerator (mercadopago.py)

Generates MercadoPago API responses:

- `preference()` - Checkout Pro preference
- `payment()` - Payment (Checkout API/Bricks)
- `merchant_order()` - Merchant order
- `oauth_token()` - OAuth token exchange
- `webhook_notification()` - Webhook payloads

## Examples

### Generate a complete turnero flow

```python
from ward.tools.datagen.amar import AmarDataGenerator

# Step 1: Guest pet owner
owner = AmarDataGenerator.petowner(
    address="Av. Santa Fe 1234, Palermo",
    is_guest=True
)

# Step 2: Pet
pet = AmarDataGenerator.pet(
    owner_id=owner["id"],
    name="Luna",
    species="DOG",
    age_value=3,
    age_unit="years"
)

# Step 3: Cart
cart = AmarDataGenerator.cart(owner_id=owner["id"])

# Step 4: Add services to cart
services = AmarDataGenerator.filter_services(
    species="DOG",
    neighborhood_id=owner["neighborhood"]["id"]
)

cart_with_items = AmarDataGenerator.calculate_cart_summary(
    cart,
    items=[
        {"service_id": services[0]["id"], "price": services[0]["price"], "quantity": 1, "pet_id": pet["id"]},
    ]
)

# Step 5: Service request
request = AmarDataGenerator.service_request(cart_id=cart["id"])
```

### Generate a payment flow

```python
from ward.tools.datagen.mercadopago import MercadoPagoDataGenerator

# Create preference
pref = MercadoPagoDataGenerator.preference(
    description="Visita a domicilio",
    total=95000,
    external_reference="SR-12345"
)

# Simulate payment
payment = MercadoPagoDataGenerator.payment(
    transaction_amount=95000,
    description="Visita a domicilio",
    status="approved",
    application_fee=45000  # Platform fee (split payment)
)

# Webhook notification
webhook = MercadoPagoDataGenerator.webhook_notification(
    topic="payment",
    resource_id=str(payment["id"])
)
```

## Future Generators

- `google.py` - Google API responses (Calendar, Sheets)
- `whatsapp.py` - WhatsApp API responses
- `slack.py` - Slack API responses
