# Copyright 2026 ReK2 - Chris F.N. <rek2@hispagatos.org>
# https://rek2.hispagatos.org
# Distributed under the terms of the GNU General Public License v3

EAPI=8

inherit cargo git-r3

DESCRIPTION="Terminal-based Usenet/NNTP client (TUI)"
HOMEPAGE="https://sr.ht/~rek2/Usenet_Reborn"
EGIT_REPO_URI="https://git.sr.ht/~rek2/usenet_reborn"

LICENSE="GPL-3+"
# Dependent crate licenses
LICENSE+="
	0BSD Apache-2.0 Apache-2.0-with-LLVM-exceptions Boost-1.0 BSD CC0-1.0
	ISC LGPL-2.1+ MIT MIT-0 MPL-2.0 Unicode-3.0 Unicode-DFS-2016
	Unlicense WTFPL-2 ZLIB openssl
"
SLOT="0"
KEYWORDS=""

RDEPEND="dev-libs/openssl:="
DEPEND="${RDEPEND}"
BDEPEND="
	dev-build/cmake
	virtual/pkgconfig
"

QA_FLAGS_IGNORED="usr/bin/usenet_reborn"

src_unpack() {
	git-r3_src_unpack

	# Build against rek2_nntp from its git HEAD; no version or commit pin.
	sed -i -E 's|^rek2_nntp[[:space:]]*=.*$|rek2_nntp = { git = "https://git.sr.ht/~rek2/rek2_nntp" }|' "${S}"/Cargo.toml || die
	grep -q 'git.sr.ht/~rek2/rek2_nntp' "${S}"/Cargo.toml || die "failed to switch rek2_nntp to git"

	cargo_live_src_unpack
}

src_install() {
	cargo_src_install

	dodoc README.md LICENSE

	docinto examples
	dodoc configs/config.toml configs/subscriptions
}

pkg_postinst() {
	elog "usenet_reborn runs as your user and reads ~/.config/usenet_reborn/"
	elog "Example configs were installed under /usr/share/doc/${PF}/examples/"
	elog "  mkdir -p ~/.config/usenet_reborn"
	elog "  cp /usr/share/doc/${PF}/examples/config.toml ~/.config/usenet_reborn/"
	elog "  cp /usr/share/doc/${PF}/examples/subscriptions ~/.config/usenet_reborn/"
	elog "Set EDITOR (default: nano); signature: ~/.signature or \$SIGNATURE_FILE."
}