ki#!/bin/bash

DEST=${1:/etc/skel}

# Install required tools
sudo apt-get install wget gpg

RELEASE="stable"
TRANSPORT="https"
MIRROR="windsurf-${RELEASE}"
DOMAIN="codeiumdata.com"
KEY_PATH="wVxQEIWkwPUEAGf3"
URI_PATH="${KEY_PATH}/apt"
URI="${TRANSPORT}://${MIRROR}.${DOMAIN}/${URI_PATH}"
ARCH="amd64"
TYPES="deb"
KEYRING="windsurf-${RELEASE}.gpg"
KEYRINGS="/etc/apt/keyrings"
ACTIVE="/etc/apt/sources.list.d"
AVAILABLE="/etc/apt/sources.list-available"

SUITE='stable'
COMPONENT="main"
ENABLED="yes"

mkdir -p "${AVAILABLE}"

# Download and process GPG key
wget -qO- "${TRANSPORT}://${MIRROR}.${DOMAIN}/${KEY_PATH}/windsurf.gpg" | gpg --dearmor > ${KEYRING}
sudo install -D -o root -g root -m 644 ${KEYRING} ${KEYRINGS}/${KEYRING}


# Create sources file in DEB822 format
cat << EOF | sudo tee ${AVAILABLE}/windsurf.sources > /dev/null
Types: ${TYPES}
URIs: ${URI}
Suites: ${SUITE}
Components: ${COMPONENT}
Architectures: ${ARCH}
Signed-By: ${KEYRINGS}/${KEYRING}
Enabled: ${ENABLED}
EOF

ln -sf "${AVAILABLE}"/windsurf.sources "${ACTIVE}"/windsurf.sources

# Clean up temporary key file
rm -f ${KEYRING}

sudo apt install apt-transport-https
sudo apt update

sudo apt install windsurf

# neovim codeium plugin
# https://github.com/Exafunction/windsurf.vim

# key bindings


# disable bindings
# vim.g.codeium_disable_bindings = 1

# using folke/lazy.nvim.

cat << 'EOF' | tee ${DEST}/.config/nvim/lua/plugins/windsurf.lua
return {
  {
    "Exafunction/windsurf.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "hrsh7th/nvim-cmp",
    },
    config = function()
      require("codeium").setup({
        accept_keymapping = "<C-g>",
        virtual_text = {
          enabled = true,
        },
        debug = false,
      })
    end,
  },
}
EOF
