name: Windows

on: [push]

env:
  SDL2: 2.30.2
  SDL2_TTF: 2.22.0
  SDL2_MIXER: 2.8.0
  SDL2_IMAGE: 2.8.2
  SDL2_GFX: 1.0.4

permissions:
  contents: write

jobs:
  deploy:
    runs-on: windows-latest

    steps:
      - name: Checkout 
        uses: actions/checkout@v4

      - name: Download SDL2 Libraries
        run: |
          curl "https://github.com/libsdl-org/SDL/releases/download/release-$SDL2/SDL2-$SDL2-win32-x64.zip" -o "sdl2.zip"
          curl "https://github.com/libsdl-org/SDL_ttf/releases/download/release-$SDL2_TTF/SDL2_ttf-$SDL2_TTF-win32-x64.zip" -o "sdl2_ttf.zip"
          curl "https://github.com/libsdl-org/SDL_image/releases/download/release-$SDL2_IMAGE/SDL2_image-$SDL2_IMAGE-win32-x64.zip" -o "sdl2_image.zip"
          curl "https://github.com/libsdl-org/SDL_mixer/releases/download/release-$SDL2_MIXER/SDL2_mixer-$SDL2_MIXERwin32-x64.zip" -o "sdl2_mixer.zip"
          curl "https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-$SDL2_.tar.gz/download" -o "sdl2_gfx.tar.gz"
      
      - name: Debug Artifact
        uses: actions/upload-artifact@v4
        with:
          path: ./
          retention-days: 1
          if-no-files-found: error

      - name: Extract SDL2 DLLs
        run: |
          7z x ./sdl2.zip SDL2.dll
          7z x ./sdl2_image.zip SDL2_image.dll
          7z x ./sdl2_ttf.zip SDL2_ttf.dll
          7z x ./sdl2_mixer.zip SDL2_mixer.dll

      - name: Setup Rust (Windows)
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: x86_64-pc-windows-gnu
          override: true

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --release

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          path: ./target/pacman.exe
          retention-days: 7
          if-no-files-found: error