use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
pub struct ExportRequest {
    pub format: String,
    #[serde(default)]
    pub include_headers: bool,
    #[serde(default)]
    pub file_name: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct ExportResult {
    pub format: String,
    pub file_name: String,
    pub size_bytes: usize,
}

#[derive(Debug, Deserialize)]
pub struct RevenueReportRequest {
    #[serde(default)]
    pub from: Option<String>,
    #[serde(default)]
    pub to: Option<String>,
    #[serde(default)]
    pub group_by: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct RevenueReport {
    pub from: String,
    pub to: String,
    pub total_revenue: f64,
    pub total_invoices: i64,
    pub top_customers: Vec<CustomerRevenue>,
    pub by_subscription: Vec<SubscriptionRevenue>,
}

#[derive(Debug, Serialize)]
pub struct CustomerRevenue {
    pub customer_id: i32,
    pub customer_name: String,
    pub total_revenue: f64,
    pub invoice_count: i64,
}

#[derive(Debug, Serialize)]
pub struct SubscriptionRevenue {
    pub subscription_id: i32,
    pub subscription_name: String,
    pub total_revenue: f64,
}

#[derive(Debug, Deserialize)]
pub struct UsageReportRequest {
    #[serde(default)]
    pub from: Option<String>,
    #[serde(default)]
    pub to: Option<String>,
    #[serde(default)]
    pub subscription_id: Option<i32>,
}

#[derive(Debug, Serialize)]
pub struct UsageReport {
    pub from: String,
    pub to: String,
    pub by_subscription: Vec<SubscriptionUsage>,
    pub by_metric: Vec<MetricUsage>,
}

#[derive(Debug, Serialize)]
pub struct SubscriptionUsage {
    pub subscription_id: i32,
    pub subscription_name: String,
    pub metrics: serde_json::Value,
}

#[derive(Debug, Serialize)]
pub struct MetricUsage {
    pub metric_type: String,
    pub total_value: f64,
    pub unit: String,
}
