"""Download a file locally and mirror it to Azure Blob when configured."""

from __future__ import annotations

from pathlib import Path

from infra_core import download_asset
from infra_core.azure import AzureStorageSettings, get_client


def main() -> None:
    local_path = Path("artifacts/python-logo.png")
    result = download_asset("https://www.python.org/static/img/python-logo.png", local_path)
    print(f"downloaded to {result.path}")

    settings, mode = AzureStorageSettings.from_env_with_prefix("CRAWLER")
    client = get_client(settings, mode)
    if not client.is_configured():
        print("Azure storage is not configured; keeping the local file only.")
        return

    client.upload_file(result.path)
    blob_name = client.blob_name_for_path(result.path)
    print(f"mirrored to blob {blob_name}")
    print(client.blob_url_for_name(blob_name))


if __name__ == "__main__":
    main()
