# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.15.0

EAPI=8

if [[ "${PV}" != "9999" ]]; then
	declare -A GIT_CRATES=(
		[curve25519-dalek-derive]='https://github.com/signalapp/curve25519-dalek;7c6d34756355a3566a704da84dce7b1c039a6572;curve25519-dalek-%commit%/curve25519-dalek-derive'
		[curve25519-dalek]='https://github.com/signalapp/curve25519-dalek;7c6d34756355a3566a704da84dce7b1c039a6572;curve25519-dalek-%commit%/curve25519-dalek'
		[libsignal-core]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/core'
		[libsignal-protocol]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/protocol'
		[libsignal-service]='https://github.com/whisperfish/libsignal-service-rs;f94d55bf8d742699024c26ca3965e85fc9946e23;libsignal-service-rs-%commit%'
		[poksho]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/poksho'
		[presage-store-sqlite]='https://github.com/whisperfish/presage;0da7b57746b827bfb310f98a10a29e73d508e742;presage-%commit%/presage-store-sqlite'
		[presage]='https://github.com/whisperfish/presage;0da7b57746b827bfb310f98a10a29e73d508e742;presage-%commit%/presage'
		[signal-crypto]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/crypto'
		[zkcredential]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/zkcredential'
		[zkgroup]='https://github.com/signalapp/libsignal;e46841ea2c1ad03bc5113eba267ac1543689d031;libsignal-%commit%/rust/zkgroup'
	)
fi

inherit cargo check-reqs

DESCRIPTION="Signal messenger client for terminal"
HOMEPAGE="https://github.com/boxdot/gurk-rs/"

if [[ "${PV}" = "9999" ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/boxdot/gurk-rs.git"
else
	SRC_URI="
		https://github.com/boxdot/gurk-rs/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
		https://github.com/beatussum/gentoo-tarballs/releases/download/latest/gurk-${PV}-crates.tar.xz
		${CARGO_CRATE_URIS}
	"

	KEYWORDS="~amd64"
fi

LICENSE="AGPL-3"

# Dependent crate licenses
LICENSE+="
	AGPL-3
	Apache-2.0
	BSD-2
	BSD
	Boost-1.0
	ISC
	MIT
	MPL-2.0
	Unicode-3.0
	ZLIB
"

SLOT="0"

DOCS=(
	CHANGELOG.md
	README.md
	chat-qr.png
	screenshot.png
)

RUST_MIN_VER="1.85.0"
CHECKREQS_DISK_BUILD="2400M"

pkg_setup() {
	check-reqs_pkg_setup
	rust_pkg_setup
}

src_unpack() {
	if [[ "${PV}" = "9999" ]]; then
		git-r3_src_unpack
		cargo_live_src_unpack
	else
		cargo_src_unpack

		local crate_patches

		for crate in curve25519-dalek{,-derive}; do
			IFS=';' read -r crate_uri commit crate_dir host \
				<<< "${GIT_CRATES["${crate}"]}"

			: "${crate_dir:=${crate}-%commit%}"
			crate_patches+="${crate} = { path = \"${WORKDIR}/${crate_dir//%commit%/${commit}}\" };;"
		done

		printf -- "[patch.crates-io]\\n%s" "${crate_patches//;;/$'\n'}" \
			>> "${CARGO_HOME}/config.toml"
	fi
}

src_configure() {
	cargo_src_configure --frozen
}

src_install() {
	einstalldocs
	cargo_src_install
}
