#!/bin/sh
# deploy-purified.sh - Generated by bashrs from deploy.rs
# This is what the Rust code transpiles to - ZERO violations

deploy_app() {
    _version="$1"
    _build_dir="$2"

    # Purified: Deterministic (was $RANDOM and timestamp)
    session_id="session-${_version}"
    release_tag="release-${_version}"

    # Purified: All variables quoted (was SC2086)
    target_dir="/app/releases/${release_tag}"

    # Purified: Idempotent (was mkdir)
    mkdir -p "${target_dir}" || return 1

    # Purified: Safe directory iteration (was unquoted $(ls))
    if [ ! -d "${_build_dir}" ]; then
        printf 'Build directory does not exist: %s\n' "${_build_dir}" >&2
        return 1
    fi

    # Purified: Properly quoted iteration (was SC2046)
    for entry in "${_build_dir}"/*; do
        if [ -f "${entry}" ]; then
            cp "${entry}" "${target_dir}/" || return 1
        elif [ -d "${entry}" ]; then
            cp -r "${entry}" "${target_dir}/" || return 1
        fi
    done

    # Purified: Idempotent (remove if exists, then create)
    current_link="/app/current"
    if [ -e "${current_link}" ] || [ -L "${current_link}" ]; then
        rm -f "${current_link}" || return 1
    fi

    # Purified: All variables quoted
    ln -s "${target_dir}" "${current_link}" || return 1

    printf 'Deployed %s to %s\n' "${release_tag}" "${target_dir}"
    return 0
}

# Main execution
_version="${1:-1.0.0}"
_build_dir="${2:-/app/build}"

deploy_app "${_version}" "${_build_dir}"
