"""Static docs deploy workflow templates by provider."""

from __future__ import annotations

from mcp_zen_of_docs.models import DocsDeployProvider


def render_docs_deploy_workflow(provider: DocsDeployProvider) -> str:  # noqa: PLR0911
    """Return deterministic docs deploy workflow content for a provider."""
    match provider:
        case DocsDeployProvider.GITHUB_PAGES:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: github-pages\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n"
                "  pages: write\n"
                "  id-token: write\n\n"
                "concurrency:\n"
                "  group: pages\n"
                "  cancel-in-progress: false\n\n"
                "jobs:\n"
                "  build:\n"
                "    runs-on: ubuntu-latest\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Configure GitHub Pages\n"
                "        uses: actions/configure-pages@v5\n"
                "      - name: Upload pages artifact\n"
                "        uses: actions/upload-pages-artifact@v3\n"
                "        with:\n"
                "          path: site\n\n"
                "  deploy:\n"
                "    needs: build\n"
                "    runs-on: ubuntu-latest\n"
                "    environment:\n"
                "      name: github-pages\n"
                "      url: ${{ steps.deployment.outputs.page_url }}\n"
                "    steps:\n"
                "      - name: Deploy to GitHub Pages\n"
                "        id: deployment\n"
                "        uses: actions/deploy-pages@v4\n"
            )
        case DocsDeployProvider.NETLIFY:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: netlify\n"
                "# Required secrets: NETLIFY_AUTH_TOKEN, NETLIFY_SITE_ID\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n\n"
                "jobs:\n"
                "  deploy:\n"
                "    runs-on: ubuntu-latest\n"
                "    env:\n"
                "      NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}\n"
                "      NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Validate Netlify configuration\n"
                "        run: |\n"
                '          test -n "${NETLIFY_AUTH_TOKEN}" || (echo "Missing secret: '
                'NETLIFY_AUTH_TOKEN" && exit 1)\n'
                '          test -n "${NETLIFY_SITE_ID}" || (echo "Missing secret: '
                'NETLIFY_SITE_ID" && exit 1)\n'
                "      - name: Deploy to Netlify\n"
                "        uses: nwtgck/actions-netlify@v3.0\n"
                "        with:\n"
                "          publish-dir: site\n"
                "          production-deploy: true\n"
                "          github-token: ${{ secrets.GITHUB_TOKEN }}\n"
                "          deploy-message: docs deploy from GitHub Actions\n"
                "          enable-pull-request-comment: false\n"
                "          enable-commit-comment: false\n"
            )
        case DocsDeployProvider.VERCEL:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: vercel\n"
                "# Required secrets: VERCEL_TOKEN\n"
                "# Required vars: VERCEL_ORG_ID, VERCEL_PROJECT_ID\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n\n"
                "jobs:\n"
                "  deploy:\n"
                "    runs-on: ubuntu-latest\n"
                "    env:\n"
                "      VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}\n"
                "      VERCEL_ORG_ID: ${{ vars.VERCEL_ORG_ID }}\n"
                "      VERCEL_PROJECT_ID: ${{ vars.VERCEL_PROJECT_ID }}\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Validate Vercel configuration\n"
                "        run: |\n"
                '          test -n "${VERCEL_TOKEN}" || (echo "Missing secret: '
                'VERCEL_TOKEN" && exit 1)\n'
                '          test -n "${VERCEL_ORG_ID}" || (echo "Missing var: VERCEL_ORG_ID" '
                "&& exit 1)\n"
                '          test -n "${VERCEL_PROJECT_ID}" || (echo "Missing var: '
                'VERCEL_PROJECT_ID" && exit 1)\n'
                "      - name: Install Vercel CLI\n"
                "        run: npm install --global vercel@latest\n"
                "      - name: Deploy to Vercel\n"
                '        run: vercel deploy --prod --yes --token "$VERCEL_TOKEN" site\n'
            )
        case DocsDeployProvider.CLOUDFLARE_PAGES:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: cloudflare-pages\n"
                "# Required secrets: CLOUDFLARE_API_TOKEN\n"
                "# Required vars: CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_PAGES_PROJECT_NAME\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n\n"
                "jobs:\n"
                "  deploy:\n"
                "    runs-on: ubuntu-latest\n"
                "    env:\n"
                "      CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}\n"
                "      CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}\n"
                "      CLOUDFLARE_PAGES_PROJECT_NAME: ${{ vars.CLOUDFLARE_PAGES_PROJECT_NAME }}\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Validate Cloudflare Pages configuration\n"
                "        run: |\n"
                '          test -n "${CLOUDFLARE_API_TOKEN}" || (echo "Missing secret: '
                'CLOUDFLARE_API_TOKEN" && exit 1)\n'
                '          test -n "${CLOUDFLARE_ACCOUNT_ID}" || (echo "Missing var: '
                'CLOUDFLARE_ACCOUNT_ID" && exit 1)\n'
                '          test -n "${CLOUDFLARE_PAGES_PROJECT_NAME}" || (echo "Missing '
                'var: CLOUDFLARE_PAGES_PROJECT_NAME" && exit 1)\n'
                "      - name: Install Wrangler\n"
                "        run: npm install --global wrangler@latest\n"
                "      - name: Deploy to Cloudflare Pages\n"
                "        run: |\n"
                "          wrangler pages deploy site \\\n"
                '            --project-name "$CLOUDFLARE_PAGES_PROJECT_NAME" \\\n'
                "            --branch main\n"
            )
        case DocsDeployProvider.SELF_HOSTED:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: self-hosted\n"
                "# Required secrets: DOCS_DEPLOY_SSH_KEY\n"
                "# Required vars: DOCS_DEPLOY_HOST, DOCS_DEPLOY_USER, DOCS_DEPLOY_PATH\n"
                "# Optional vars: DOCS_DEPLOY_PORT (default: 22)\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n\n"
                "jobs:\n"
                "  deploy:\n"
                "    runs-on: ubuntu-latest\n"
                "    env:\n"
                "      DOCS_DEPLOY_HOST: ${{ vars.DOCS_DEPLOY_HOST }}\n"
                "      DOCS_DEPLOY_USER: ${{ vars.DOCS_DEPLOY_USER }}\n"
                "      DOCS_DEPLOY_PATH: ${{ vars.DOCS_DEPLOY_PATH }}\n"
                "      DOCS_DEPLOY_PORT: ${{ vars.DOCS_DEPLOY_PORT || '22' }}\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Validate self-hosted configuration\n"
                "        run: |\n"
                '          test -n "${DOCS_DEPLOY_HOST}" || (echo "Missing var: '
                'DOCS_DEPLOY_HOST" && exit 1)\n'
                '          test -n "${DOCS_DEPLOY_USER}" || (echo "Missing var: '
                'DOCS_DEPLOY_USER" && exit 1)\n'
                '          test -n "${DOCS_DEPLOY_PATH}" || (echo "Missing var: '
                'DOCS_DEPLOY_PATH" && exit 1)\n'
                "      - name: Start ssh-agent\n"
                "        uses: webfactory/ssh-agent@v0.9.0\n"
                "        with:\n"
                "          ssh-private-key: ${{ secrets.DOCS_DEPLOY_SSH_KEY }}\n"
                "      - name: Deploy to self-hosted target\n"
                "        run: |\n"
                '          rsync -az --delete -e "ssh -p $DOCS_DEPLOY_PORT" site/ \\\n'
                '            "$DOCS_DEPLOY_USER@$DOCS_DEPLOY_HOST:$DOCS_DEPLOY_PATH"\n'
            )
        case DocsDeployProvider.CUSTOM:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                "# docs deploy provider: custom\n"
                "# Required vars: CUSTOM_DOCS_DEPLOY_COMMAND\n"
                "# Optional vars: CUSTOM_DOCS_DEPLOY_WORKDIR (default: site)\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  push:\n"
                "    branches:\n"
                "      - main\n"
                "  workflow_dispatch:\n\n"
                "permissions:\n"
                "  contents: read\n\n"
                "jobs:\n"
                "  deploy:\n"
                "    runs-on: ubuntu-latest\n"
                "    env:\n"
                "      CUSTOM_DOCS_DEPLOY_COMMAND: ${{ vars.CUSTOM_DOCS_DEPLOY_COMMAND }}\n"
                "      CUSTOM_DOCS_DEPLOY_WORKDIR: ${"
                "{ vars.CUSTOM_DOCS_DEPLOY_WORKDIR || 'site' }}\n"
                "    steps:\n"
                "      - name: Checkout\n"
                "        uses: actions/checkout@v4\n"
                "      - name: Setup Python\n"
                "        uses: actions/setup-python@v5\n"
                "        with:\n"
                "          python-version: '3.12'\n"
                "      - name: Install uv\n"
                "        uses: astral-sh/setup-uv@v3\n"
                "      - name: Install dependencies\n"
                "        run: uv sync --frozen\n"
                "      - name: Build docs\n"
                "        run: uv run mkdocs build --strict\n"
                "      - name: Validate custom deploy configuration\n"
                "        run: |\n"
                '          test -n "${CUSTOM_DOCS_DEPLOY_COMMAND}" || (echo "Missing var: '
                'CUSTOM_DOCS_DEPLOY_COMMAND" && exit 1)\n'
                "      - name: Run custom deploy command\n"
                "        run: |\n"
                '          cd "$CUSTOM_DOCS_DEPLOY_WORKDIR"\n'
                '          sh -eu -c "$CUSTOM_DOCS_DEPLOY_COMMAND"\n'
            )
        case _:
            return (
                "# Generated by mcp-zen-of-docs init_project.\n"
                f"# docs deploy provider: {provider.value}\n"
                "# TODO: provider workflow template not implemented yet.\n"
                "name: docs-deploy\n\n"
                "on:\n"
                "  workflow_dispatch:\n\n"
                "jobs:\n"
                "  placeholder:\n"
                "    runs-on: ubuntu-latest\n"
                "    steps:\n"
                "      - name: Pending provider integration\n"
                "        run: |\n"
                '          echo "Provider template is not implemented yet for '
                f'{provider.value}."\n'
                "          exit 1\n"
            )


__all__ = ["render_docs_deploy_workflow"]
