# terraback/cli/gcp/compute/images.py
import typer
from pathlib import Path
from typing import Optional

app = typer.Typer(name="image", help="Scan and import GCP Compute Engine images.")

@app.command("scan")
def scan_images(
    output_dir: Path = typer.Option("generated", "-o", "--output-dir"),
    project_id: Optional[str] = typer.Option(None, "--project-id", "-p"),
    with_deps: bool = typer.Option(False, "--with-deps")
):
    """Scans GCP Compute Engine images and generates Terraform code."""
    typer.echo("GCP image scanning not yet implemented.")
    # TODO: Implement GCP image scanning

@app.command("list")
def list_images(
    output_dir: Path = typer.Option("generated", "-o", "--output-dir")
):
    """List all GCP image resources previously generated."""
    typer.echo("GCP image listing not yet implemented.")

@app.command("import")
def import_image(
    image_id: str = typer.Argument(..., help="GCP image ID to import"),
    output_dir: Path = typer.Option("generated", "-o", "--output-dir")
):
    """Run terraform import for a specific GCP image."""
    typer.echo("GCP image import not yet implemented.")

# Scan function for cross-scan registry
def scan_gcp_instances(
    output_dir: Path,
    project_id: str = None,
    zone: Optional[str] = None,
    **kwargs
):
    """Scan function to be registered with cross-scan registry."""
    if not project_id:
        project_id = get_default_project_id()
    
    typer.echo(f"[Cross-scan] Scanning GCP instances in project {project_id}")
    
    instance_data = get_instance_data(project_id, zone)
    
    if instance_data:
        output_file = output_dir / "gcp_instance.tf"
        generate_tf(instance_data, "gcp_instance", output_file, provider="gcp")
        generate_imports_file(
            "gcp_instance",
            instance_data,
            remote_resource_id_key="id",
            output_dir=output_dir
        )
        typer.echo(f"[Cross-scan] Generated Terraform for {len(instance_data)} GCP instances")