#!/usr/bin/env bash
# Entry point for skills. Emits all vars needed for daily workflow use.
# repos/teams are always bundled (shared team config).
# local-config.json is the only user-local file (maps repo names to local paths).
# Usage: eval "$(bash "${CLAUDE_SKILL_DIR}/../../scripts/workflow-setup.sh" [workspace_root])"
set -euo pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
plugin_root="$(cd "$script_dir/.." && pwd)"
workspace_root="${1:-$PWD}"
workspace_root="$(cd "$workspace_root" && pwd)"

state_home="${HUMAND_WORKFLOW_STATE_HOME:-${XDG_STATE_HOME:-$HOME/.local/state}/humand-tech-workflow}"
config_home="${HUMAND_WORKFLOW_CONFIG_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/humand-tech-workflow}"

bundled_config_dir="$plugin_root/config/workflow"

if [ -f "$config_home/local-config.json" ]; then
  local_config_file="$config_home/local-config.json"
else
  local_config_file=""
  echo "⚠️  local-config.json not found. Run /initial-setup to configure your local repo paths before using other skills." >&2
fi

emit_var() {
  local key="$1"
  local value="$2"
  printf '%s=%q\n' "$key" "$value"
}

emit_var "PLUGIN_ROOT" "$plugin_root"
emit_var "WORKSPACE_ROOT" "$workspace_root"
emit_var "STATE_HOME" "$state_home"
emit_var "CONFIG_HOME" "$config_home"
emit_var "REPOS_FILE" "$bundled_config_dir/repos.json"
emit_var "TEAMS_FILE" "$bundled_config_dir/teams.json"
emit_var "LOCAL_CONFIG_FILE" "$local_config_file"
emit_var "BUNDLED_LOCAL_CONFIG_EXAMPLE_FILE" "$bundled_config_dir/local-config.example.json"
