use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize)]
pub struct OtpRequestPayload<'a> {
    pub email: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub device_fp: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub platform: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub app_version: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub product_key: Option<&'a str>,
}

#[derive(Debug, Clone, Serialize)]
pub struct OtpVerifyPayload<'a> {
    pub email: &'a str,
    pub code: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub device_fp: Option<&'a str>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OtpVerifyResponse {
    pub access_token: String,
    pub customer: OtpCustomer,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OtpCustomer {
    pub id: String,
    pub email: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Customer {
    pub id: String,
    pub email: String,
    pub name: Option<String>,
    pub trial_ends_at: Option<String>,
    pub plan: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct EntitlementCustomer {
    pub id: String,
    pub email: String,
    pub name: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct EntitlementsResponse {
    pub customer: EntitlementCustomer,
    pub entitlements: serde_json::Value,
    pub devices: serde_json::Value,
}

#[derive(Debug, Clone, Deserialize)]
pub struct CustomerFeaturesResponse {
    pub product: String,
    #[serde(default)]
    pub features: Vec<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct PortalLink {
    pub url: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Invoice {
    pub id: String,
    pub number: Option<String>,
    pub amount: i64,
    pub currency: String,
    pub date: String,
    pub period_start: String,
    pub period_end: String,
    pub pdf_url: Option<String>,
    pub hosted_url: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct InvoicesPage {
    pub invoices: Vec<Invoice>,
    pub has_more: bool,
    pub next_cursor: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct DowngradePayload<'a> {
    pub product: &'a str,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_plan: Option<&'a str>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct DowngradeResponse {
    pub cancel_at_period_end: bool,
    pub cancel_at: Option<String>,
    pub plan: Option<String>,
    pub valid_until: Option<String>,
    pub signature: Option<String>,
    pub target_plan: Option<String>,
}
