name: Build and Deploy Documentation

on:
  push:
    branches:
      - main  # Triggers the build whenever you push to the main branch

permissions:
  contents: write  # Allows the action to push the built HTML to the gh-pages branch

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Configure Git Credentials
        run: |
          git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.9'  # Matching your pyproject.toml requirement

      - name: Install documentation dependencies
        run: |
          python -m pip install --upgrade pip
          pip install mkdocs-material
          pip install "mkdocstrings[python]"
          
      - name: Install caltib (Crucial Step)
        # mkdocstrings must be able to import your library to read the docstrings.
        # We install the full bundle so the ephemeris and tools modules don't crash on import.
        run: pip install -e .[full]

      - name: Deploy to GitHub Pages
        run: mkdocs gh-deploy --force