// Copyright 2025 SkyReels SDK Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Test environment variable loading
//!
//! This example verifies that environment variables are correctly loaded
//! from the .env file. Useful for debugging setup issues.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== SkyReels SDK Environment Test ===\n");

    // Try to load .env file
    match dotenv::dotenv() {
        Ok(path) => println!("✅ Loaded .env file from: {}\n", path.display()),
        Err(e) => println!("⚠️  Could not load .env file: {}\n", e),
    }

    // Check for API key
    println!("Checking environment variables...\n");

    match std::env::var("SKYREELS_API_KEY") {
        Ok(key) => {
            if key.is_empty() {
                println!("❌ SKYREELS_API_KEY is set but empty!");
            } else if key.starts_with("your_") || key.contains("example") {
                println!("⚠️  SKYREELS_API_KEY looks like a placeholder value");
                println!("   Current value: {}...{}\n", &key[..8.min(key.len())], "****");
                println!("   Please set your actual API key in .env file");
            } else {
                println!("✅ SKYREELS_API_KEY is set!");
                println!("   Key prefix: {}...****\n", &key[..8.min(key.len())]);
            }
        }
        Err(_) => println!("❌ SKYREELS_API_KEY is not set!\n"),
    }

    // Check for optional base URL
    match std::env::var("SKYREELS_BASE_URL") {
        Ok(url) => println!("✅ SKYREELS_BASE_URL: {}", url),
        Err(_) => println!("ℹ️  SKYREELS_BASE_URL not set (using default)"),
    }

    println!("\n=== Test Summary ===");
    println!("If all checks passed ✅, you can run other examples:");
    println!("  cargo run --example basic_usage");
    println!("  cargo run --example complete_workflow");
    println!("  cargo run --example error_handling");
    println!("  cargo run --example custom_client");

    Ok(())
}
