late-java-core 2.2.9

A Rust library for launching Minecraft Java Edition
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Opciones de lanzamiento - 100% compatible con la API original de TypeScript
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LaunchOptions {
    /// URL to the launcher backend
    pub url: Option<String>,
    /// Custom headers for HTTP requests (including Authorization token)
    pub headers: Option<HashMap<String, String>>,
    /// Authorization token for HTTP requests (alternative to headers)
    pub token: Option<String>,
    /// Something to Authenticate the player (Microsoft/Mojang/AZauth)
    pub authenticator: crate::auth::AuthResponse,
    /// Connection timeout in milliseconds
    pub timeout: Option<u64>,
    /// Absolute path to Minecraft's root directory
    pub path: String,
    /// Minecraft version ('latest_release', 'latest_snapshot', '1.21.1')
    pub version: String,
    /// Path to instance directory. Relative to absolute path to Minecraft's root directory
    pub instance: Option<String>,
    /// Should Minecraft process be independent of launcher?
    pub detached: Option<bool>,
    /// How many concurrent downloads can be in progress at once
    pub download_file_multiple: Option<u32>,
    /// Should the launcher bypass offline mode?
    pub bypass_offline: Option<bool>,
    /// Force Rosetta when running on Apple Silicon
    pub intel_enabled_mac: Option<bool>,
    /// Loader config
    pub loader: LoaderOptions,
    /// MCPatcher directory
    pub mcp: Option<String>,
    /// Should game files be verified each launch?
    pub verify: Option<bool>,
    /// Files to ignore from instance
    pub ignored: Vec<String>,
    /// Custom JVM arguments
    pub jvm_args: Vec<String>,
    /// Custom game arguments
    pub game_args: Vec<String>,
    /// Java options
    pub java: JavaOptions,
    /// Screen options
    pub screen: ScreenOptions,
    /// Memory limit options
    pub memory: MemoryOptions,
}

impl Default for LaunchOptions {
    fn default() -> Self {
        Self {
            url: None,
            headers: None,
            token: None,
            authenticator: crate::auth::AuthResponse {
                access_token: String::new(),
                client_token: String::new(),
                uuid: String::new(),
                name: String::new(),
                refresh_token: None,
                user_properties: "{}".to_string(),
                meta: crate::auth::AuthMeta {
                    auth_type: "Unknown".to_string(),
                    access_token_expires_in: 0,
                    demo: false,
                },
                xbox_account: None,
                profile: None,
            },
            timeout: Some(10000),
            path: ".Minecraft".to_string(),
            version: "latest_release".to_string(),
            instance: None,
            detached: Some(false),
            download_file_multiple: Some(5),
            bypass_offline: Some(false),
            intel_enabled_mac: Some(false),
            loader: LoaderOptions {
                path: Some("./loader".to_string()),
                r#type: None,
                build: Some("latest".to_string()),
                enable: false,
            },
            mcp: None,
            verify: Some(false),
            ignored: vec![],
            jvm_args: vec![],
            game_args: vec![],
            java: JavaOptions {
                path: None,
                version: None,
                r#type: "jre".to_string(),
            },
            screen: ScreenOptions {
                width: None,
                height: None,
                fullscreen: None,
            },
            memory: MemoryOptions {
                min: None,
                max: None,
            },
        }
    }
}

/// Opciones de memoria - 100% compatible con la API original de TypeScript
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryOptions {
    /// Sets the -Xms JVM argument. This is the initial memory usage
    pub min: Option<String>,
    /// Sets the -Xmx JVM argument. This is the limit of memory usage
    pub max: Option<String>,
}

impl Default for MemoryOptions {
    fn default() -> Self {
        Self {
            min: None,
            max: None,
        }
    }
}

/// Opciones de pantalla - 100% compatible con la API original de TypeScript
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScreenOptions {
    /// Width of game window
    pub width: Option<u32>,
    /// Height of game window
    pub height: Option<u32>,
    /// Should Minecraft be started in fullscreen mode?
    pub fullscreen: Option<bool>,
}

impl Default for ScreenOptions {
    fn default() -> Self {
        Self {
            width: None,
            height: None,
            fullscreen: None,
        }
    }
}

/// Opciones de Java - 100% compatible con la API original de TypeScript
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JavaOptions {
    /// Absolute path to Java binaries directory
    /// If set, expects Java to be already downloaded. If undefined, downloads Java and sets it automatically
    pub path: Option<String>,
    /// Java version number
    /// If set, fetched from https://api.adoptium.net
    /// If undefined, fetched from Mojang
    pub version: Option<String>,
    /// Java image type. Acceptable values: 'jdk', 'jre', 'testimage', 'debugimage', 'staticlibs', 'sources', 'sbom'
    /// Using jre is recommended since it only has what's needed
    pub r#type: String,
}

impl Default for JavaOptions {
    fn default() -> Self {
        Self {
            path: None,
            version: None,
            r#type: "jre".to_string(),
        }
    }
}

/// Opciones del loader - 100% compatible con la API original de TypeScript
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoaderOptions {
    /// Path to loader directory. Relative to absolute path to Minecraft's root directory
    /// If undefined, defaults to .minecraft/loader/<loader_type>
    pub path: Option<String>,
    /// Loader type. Acceptable values: 'forge', 'neoforge', 'fabric', 'legacyfabric', 'quilt'
    pub r#type: Option<String>,
    /// Loader build (version). Acceptable values: 'latest', 'recommended', actual version
    pub build: Option<String>,
    /// Should the launcher use a loader?
    pub enable: bool,
}

impl Default for LoaderOptions {
    fn default() -> Self {
        Self {
            path: Some("./loader".to_string()),
            r#type: None,
            build: Some("latest".to_string()),
            enable: false,
        }
    }
}