## Authors:
##   Ajrat Makhmutov <rauty@altlinux.org>
##
## Copyright (C) 2025-2026  Basealt LLC
##
## This file is part of alterator-kopidel.
##
## alterator-kopidel is free software: you can redistribute it and/or modify it under the terms
## of the GNU General Public License as published by the Free Software Foundation,
## either version 3 of the License, or (at your option) any later version.
##
## alterator-kopidel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with alterator-kopidel.
## If not, see <https://www.gnu.org/licenses/>.

if [ -n "${__included_kopidel_alterator_mailbox_functions-}" ]; then
	return 0
fi
readonly __included_kopidel_alterator_mailbox_functions=1

alterator_mailbox_send_wrapper() {
	if [ -S /tmp/.private/root/alterator/browser-sock ]; then
		TMPDIR=/tmp/.private/root/ alterator-mailbox-send "$1"
	else
		alterator-mailbox-send "$1"
	fi
}

step_percentage_mailbox_sender() (
	alterator_mailbox_send_wrapper "step_progress: 0"
	while read -r line; do
		alterator_mailbox_send_wrapper "$line"
	done
	alterator_mailbox_send_wrapper "step_progress: 100"
)

send_build_error() {
	alterator_mailbox_send_wrapper \
		"build_error: \"$(echo "$1" | tr -d '"' | tr '\n' ' ')\""
}
