#!/bin/bash
# ap-intent: 快速创建 .autopush-intent 文件
# 用法:
#   ap-intent "feat(ui): 添加暗黑模式切换" done
#   ap-intent "fix(nav): 修复移动端菜单展开问题" wip
#   ap-intent "feat(auth): 添加登录" done --skip-review

set -e

SKIP_REVIEW=false
args=()
for arg in "$@"; do
    case "$arg" in
        --skip-review)
            SKIP_REVIEW=true
            ;;
        *)
            args+=("$arg")
            ;;
    esac
done

MSG="${args[0]:-}"
STATUS="${args[1]:-wip}"
REPO_DIR="${args[2]:-$(pwd)}"
INTENT_FILE="$REPO_DIR/.autopush-intent"
SKIP_REVIEW_FILE="$REPO_DIR/.autopush-skip-review"

if [ -z "$MSG" ] || [ "${MSG#--}" != "$MSG" ]; then
    echo "Usage: ap-intent \"type(scope): description\" [done|wip] [repo_dir] [--skip-review]"
    echo ""
    echo "Examples:"
    echo '  ap-intent "feat(auth): 添加 GitHub OAuth 登录支持" wip'
    echo '  ap-intent "fix(layout): 修复 BaseLayout 的 FOUC 问题" done'
    echo '  ap-intent "refactor(cv): 抽离 CVLayout 组件" wip  /path/to/repo'
    echo '  ap-intent "feat(auth): 添加登录" done --skip-review'
    exit 1
fi

printf '%s\n%s\n' "$MSG" "$STATUS" > "$INTENT_FILE"

if [ "$SKIP_REVIEW" = true ]; then
    touch "$SKIP_REVIEW_FILE"
    echo "🔓 Review skip marker created"
fi

echo "📝 Intent saved: $MSG ($STATUS)"
echo "   文件: $INTENT_FILE"
