param(
    [switch]$SkipLarge1C,
    [switch]$SkipImage
)

$ErrorActionPreference = "Stop"
$env:PYTHONDONTWRITEBYTECODE = "1"

function Invoke-Step {
    param(
        [string]$Name,
        [scriptblock]$Block
    )

    Write-Host ""
    Write-Host "== $Name =="
    & $Block
}

Invoke-Step "text: qwen3-4b-instruct-2507" {
    python scripts/download_hf_model.py qwen3-4b-instruct-2507 `
        --local-dir models/base/qwen3-4b-instruct-2507
}

Invoke-Step "translation: lmt-60-4b" {
    python scripts/download_hf_model.py lmt-60-4b `
        --local-dir models/translation/lmt-60-4b
}

Invoke-Step "audio: whisper-large-v3-turbo" {
    python scripts/download_hf_model.py whisper-large-v3-turbo `
        --local-dir models/audio/whisper-large-v3-turbo
}

Invoke-Step "video: qwen2.5-vl-7b-instruct" {
    python scripts/download_hf_model.py qwen2_5-vl-7b-instruct `
        --local-dir models/video/qwen2.5-vl-7b-instruct
}

if (-not $SkipImage) {
    Invoke-Step "image: sdxl-base-1.0" {
        python scripts/download_hf_model.py sdxl-base-1_0 `
            --local-dir models/image/sdxl-base-1.0 `
            --allow-pattern README.md --allow-pattern LICENSE.md --allow-pattern model_index.json `
            --allow-pattern scheduler/*.json --allow-pattern tokenizer/* --allow-pattern tokenizer_2/* `
            --allow-pattern text_encoder/*.json --allow-pattern text_encoder/*fp16.safetensors `
            --allow-pattern text_encoder_2/*.json --allow-pattern text_encoder_2/*fp16.safetensors `
            --allow-pattern unet/*.json --allow-pattern unet/*fp16.safetensors `
            --allow-pattern vae/*.json --allow-pattern vae/*fp16.safetensors
    }

    Invoke-Step "image edit: sdxl-inpainting-1.0" {
        python scripts/download_hf_model.py sdxl-inpainting-1_0 `
            --local-dir models/image/sdxl-inpainting-1.0 `
            --allow-pattern README.md --allow-pattern LICENSE.md --allow-pattern model_index.json `
            --allow-pattern scheduler/*.json --allow-pattern tokenizer/* --allow-pattern tokenizer_2/* `
            --allow-pattern text_encoder/*.json --allow-pattern text_encoder/*fp16.safetensors `
            --allow-pattern text_encoder_2/*.json --allow-pattern text_encoder_2/*fp16.safetensors `
            --allow-pattern unet/*.json --allow-pattern unet/*fp16.safetensors `
            --allow-pattern vae/*.json --allow-pattern vae/*fp16.safetensors
    }
}

if (-not $SkipLarge1C) {
    Invoke-Step "1c: qwen3-coder-30b-a3b-instruct-q4_k_m" {
        python scripts/download_hf_model.py qwen3-coder-30b-a3b-instruct-q4_k_m `
            --local-dir models/gguf/1c/qwen3-coder-30b-a3b-instruct-q4_k_m `
            --allow-pattern Qwen3-Coder-30B-A3B-Instruct-Q4_K_M.gguf `
            --allow-pattern README.md
    }
}

Write-Host ""
Write-Host "Plugin model bundle download finished."
