---
source: crates/normalize-typegen/tests/codegen.rs
assertion_line: 314
expression: output
---
//! Auto-generated by normalize-typegen

use serde::{Deserialize, Serialize};

/// A domain event with discriminated payload
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "camelCase")]
pub enum Event {
    #[serde(rename = "user.created")]
    UserCreated {
        payload: UserCreatedPayload,
        timestamp: Timestamp,
    },
    #[serde(rename = "user.deleted")]
    UserDeleted {
        payload: UserDeletedPayload,
        timestamp: Timestamp,
    },
    #[serde(rename = "order.placed")]
    OrderPlaced {
        payload: OrderPlacedPayload,
        timestamp: Timestamp,
    },
}

/// An item in an order
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderItem {
    pub price: f64,
    pub product_id: String,
    pub quantity: i64,
}

/// Payload for order placement events
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderPlacedPayload {
    pub items: Vec<OrderItem>,
    pub order_id: String,
    pub total: f64,
    pub user_id: String,
}

/// A result type that can be success or error
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status")]
#[serde(rename_all = "camelCase")]
pub enum Result {
    Success {
        data: serde_json::Value,
    },
    Error {
        error: serde_json::Value,
    },
}

/// ISO 8601 timestamp
pub type Timestamp = String;

/// Payload for user creation events
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserCreatedPayload {
    pub email: String,
    pub name: String,
    pub user_id: String,
}

/// Payload for user deletion events
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserDeletedPayload {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
    pub user_id: String,
}
