#!/bin/bash

self="$(basename "$0")"
#echo "💡 You ran this using '$self'"
version="beta-1.0"

if [[ "$1" == "--version" ]]; then
    echo "$self version $version"
    exit 0
fi

file="$1"
shift || true

if [[ -z "$file" ]]; then
    echo "❌ Usage: $self <source-file>"
    exit 1
fi

name="${file%.*}"
ext="${file##*.}"

# Accepted source file extensions
SOURCE_EXTS=("💩" "poop" "poo" "shit" "caca" "crap"  "doo-doo");
find_real_source_file() {
  for alt in "${SOURCE_EXTS[@]}"; do
    candidate="$name.$alt"
    if [[ -f "$candidate" ]]; then
      echo "$candidate"
      return 0
    fi
  done
  return 1
}

# Normalize source file
if [[ ! -f "$file" ]]; then
  file=$(find_real_source_file)
  if [[ -z "$file" ]]; then
    echo "❌ Source file not found for base '$name'"
    exit 1
  else
    echo "💀 Substituted real file: $file"
  fi
fi

raku "$(dirname "$0")/☠️.raku" "$file" "$@"
