#!/usr/bin/env bash
set -euo pipefail

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
export BEAM_VLCKIT_PLATFORMS=ios
export BEAM_VLCKIT_OUTPUT_BASENAME=calibration-ios
# shellcheck source=common.sh
source "$script_dir/common.sh"

beam_assert_work_dir
trap beam_release_canonical_lock EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
beam_acquire_canonical_lock

"$script_dir/prepare_sources.sh"
"$script_dir/preflight.sh" ios

rm -rf "$beam_vlckit_staging_dir"
mkdir -p "$beam_vlckit_staging_dir/logs"
cp "$beam_vlckit_source_metadata" "$beam_vlckit_staging_dir/SOURCE-MANIFEST.txt"

"$script_dir/build_platform.sh" ios
python3 "$script_dir/audit_source_inputs.py" \
  --vlc-root "$beam_vlckit_source_dir/libvlc/vlc" \
  --output "$beam_vlckit_staging_dir/audit/source-inputs-sha512.tsv"

echo "Audited iOS-only calibration is ready at $beam_vlckit_staging_dir."
echo "No release package or VERIFIED marker was created."
