# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=aichat
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.30.0
pkgrel=1
pkgdesc="All-in-one AI CLI tool featuring Chat-REPL, Shell Assistant, RAG, AI tools & agents (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sigoden/aichat'
msys2_references=(
  'archlinux: aichat'
)
license=('spdx:MIT OR Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e194cc89afc213a6e3169738221cae641c347421c4f2aacd5d6f4f7cc6edb387')

prepare() {
  cd "${_realname}-${pkgver}"
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"
  cargo build --frozen --release --all-features
}

package() {
  cd "${_realname}-${pkgver}"
  install -vDm755 -t "${pkgdir}${MINGW_PREFIX}/bin" target/release/aichat
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}" README.md
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE-APACHE
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE-MIT

  install -vDm644 scripts/completions/aichat.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/aichat"
  install -vDm644 scripts/completions/aichat.fish "${pkgdir}${MINGW_PREFIX}/share/fish/completions/aichat.fish"
  install -vDm644 scripts/completions/aichat.nu "${pkgdir}${MINGW_PREFIX}/share/nu/completions/aichat.nu"
  install -vDm644 scripts/completions/aichat.ps1 "${pkgdir}${MINGW_PREFIX}/share/powershell/completions/aichat.ps1"
  install -vDm644 scripts/completions/aichat.zsh "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_aichat"

  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.bash
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.nu
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.zsh
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.fish
  install -vDm644 -t "${pkgdir}${MINGW_PREFIX}/share/aichat" scripts/shell-integration/integration.ps1
}
