use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// Module available in the marketplace
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Module {
    pub id: Uuid,
    pub slug: String,
    pub name: String,
    pub description: Option<String>,
    pub category: Option<String>,
    pub price_usd: rust_decimal::Decimal,
    pub preview_image_url: Option<String>,
    pub screenshots: Option<serde_json::Value>,
    pub features: Option<serde_json::Value>,
    pub version: String,
    pub plugin_file_url: Option<String>,
    pub created_at: chrono::DateTime<chrono::Utc>,
}

/// Module with ownership flag for catalog display
#[derive(Debug, Clone, Serialize)]
pub struct ModuleWithOwnership {
    #[serde(flatten)]
    pub module: Module,
    pub is_purchased: bool,
    pub installation_status: Option<String>,
}

/// Module purchase record
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct ModulePurchase {
    pub id: Uuid,
    pub license_id: Uuid,
    pub module_id: Uuid,
    pub purchased_at: chrono::DateTime<chrono::Utc>,
    pub transaction_id: Option<String>,
    pub amount_paid: Option<rust_decimal::Decimal>,
}

/// Module installation status
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct ModuleInstallation {
    pub id: Uuid,
    pub license_id: Uuid,
    pub module_id: Uuid,
    pub status: String,
    pub installed_at: Option<chrono::DateTime<chrono::Utc>>,
    pub error_message: Option<String>,
}

/// Module with installation details for user's purchased modules
#[derive(Debug, Clone, Serialize)]
pub struct PurchasedModule {
    #[serde(flatten)]
    pub module: Module,
    pub purchased_at: chrono::DateTime<chrono::Utc>,
    pub installation_status: Option<String>,
    pub installed_at: Option<chrono::DateTime<chrono::Utc>>,
    pub error_message: Option<String>,
}
