use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct App {
    pub account_display_name: String,
    pub account_handle: String,
    pub account_id: String,
    pub account_profile_picture: String,
    pub allow_client_side_execution: bool,
    pub created_at: String,
    pub is_license_required: bool,
    pub name: String,
    pub public_id: String,
    pub state: String,
    pub resource_uri: String,
    #[serde(rename = "type")]
    pub app_type: String,
    #[serde(flatten)]
    pub extra: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppVersion {
    pub created_at: String,
    pub public_id: String,
    pub major: u64,
    pub minor: u64,
    pub patch: u64,
    pub description: Option<String>,
    pub is_runnable_by_user: Option<bool>,
    pub source_code_license: Option<String>,
    pub stdout_render_type: Option<String>,
    pub main_output_file: Option<String>,
    pub app_uri: Option<String>,
    #[serde(flatten)]
    pub extra: serde_json::Value,
}

impl AppVersion {
    pub fn semantic_version(&self) -> String {
        format!("{}.{}.{}", self.major, self.minor, self.patch)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppGetResponse {
    pub app: App,
    pub app_uri: String,
    pub app_version: AppVersion,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppsListResponse {
    pub results: Vec<AppListItem>,
    pub count: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppListItem {
    pub resource_uri: String,
    #[serde(flatten)]
    pub extra: serde_json::Value,
}
