#!/usr/bin/env bash
# Quick license entry helper for pass
# Following prime directive: streamlined license management

if [[ $# -ne 1 ]]; then
    echo "Usage: new-license <app-name>"
    echo "Example: new-license BBEdit"
    exit 1
fi

APP_NAME="$1"
TEMPLATE="$HOME/dotfiles/pass-templates/license-template.txt"

# Check if template exists
if [[ ! -f "$TEMPLATE" ]]; then
    echo "❌ Template not found: $TEMPLATE"
    exit 1
fi

# Create temp file with template
TEMP_FILE=$(mktemp)
cp "$TEMPLATE" "$TEMP_FILE"

# Open in editor
${EDITOR:-vim} "$TEMP_FILE"

# Add to pass
pass insert --multiline "licenses/$APP_NAME" < "$TEMP_FILE"

# Cleanup
rm "$TEMP_FILE"

echo "✅ License for $APP_NAME added to pass"
echo "📋 View with: pass licenses/$APP_NAME"
echo "✏️  Edit with: pass edit licenses/$APP_NAME"