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

# Initialize a local Git repository with the branch pattern used by this project.
#
# Usage:
#   bash scripts/init_git_branches.sh git@github.com:OWNER/REPO.git

remote_url="${1:-}"

if [[ -z "$remote_url" ]]; then
  echo "Usage: bash scripts/init_git_branches.sh <github-remote-url>"
  echo "Example: bash scripts/init_git_branches.sh git@github.com:balimed/perawat.git"
  exit 1
fi

if [[ ! -d .git ]]; then
  git init
fi

git branch -M main

if ! git remote get-url origin >/dev/null 2>&1; then
  git remote add origin "$remote_url"
else
  git remote set-url origin "$remote_url"
fi

git add .
git commit -m "Initial clean perawat app structure" || true
git checkout -B develop
git checkout main

echo "Git repository prepared."
echo "Next:"
echo "  git push -u origin main"
echo "  git push -u origin develop"
