#!/usr/bin/env python3
"""
Instagram Caption Generator for Etsy SVG Shop
Generates optimized captions with hashtag strategy
"""

import argparse
import json
from datetime import datetime
import random

# Hashtag pools by category
HASHTAGS = {
    "core": [
        "#SVGCutFile", "#CricutDesign", "#SilhouetteCameo", "#LaserCutDesign",
        "#VinylDecal", "#EtsySeller", "#DigitalDownload", "#CraftSupplies"
    ],
    "military": [
        "#MilitaryWife", "#ProudMarineMom", "#VeteranOwned", "#USMCLife",
        "#SemperFi", "#MilitaryFamily", "#MarineCorps", "#VeteranMade"
    ],
    "patriotic": [
        "#PatrioticDecor", "#AmericanPride", "#USAMade", "#4thOfJuly",
        "#AmericanFlag", "#ProudAmerican", "#RedWhiteBlue", "#USA"
    ],
    "christian": [
        "#ChristianArt", "#FaithDecor", "#ScriptureArt", "#ChurchCraft",
        "#BibleVerse", "#FaithBased", "#ChristianHome", "#PrayerWarrior"
    ],
    "outdoor": [
        "#HuntingDecor", "#CabinLife", "#WildlifeArt", "#OutdoorLiving",
        "#RusticDecor", "#HuntersOfInstagram", "#NatureArt", "#WoodlandDecor"
    ],
    "discovery": [
        "#EtsyFinds", "#ShopSmall", "#SmallBusinessOwner", "#CreativeEntrepreneur",
        "#MakerMom", "#CraftersOfInstagram", "#DIYHome", "#GiftIdeas",
        "#HandmadeWithLove", "#SupportSmallBusiness"
    ]
}

def generate_caption(title: str, niche: str, description: str = None, hashtag_count: int = 15) -> dict:
    """Generate an optimized Instagram caption with hashtags"""
    
    # Build hashtag set
    tags = []
    tags.extend(random.sample(HASHTAGS["core"], min(5, len(HASHTAGS["core"]))))
    
    niche_tags = HASHTAGS.get(niche, [])
    tags.extend(random.sample(niche_tags, min(5, len(niche_tags))))
    
    tags.extend(random.sample(HASHTAGS["discovery"], min(5, len(HASHTAGS["discovery"]))))
    
    # Limit to requested count
    tags = tags[:hashtag_count]
    random.shuffle(tags)
    
    # Build caption
    caption = f"""✨ {title} ✨

{description or "Perfect for your next craft project!"}

What you get:
📥 Instant digital download
🎨 SVG + PNG files included
⚡ Works with Cricut, Silhouette & laser cutters

🔗 Link in bio to shop!

.
.
.
{' '.join(tags)}
"""
    
    return {
        "caption": caption.strip(),
        "hashtags": tags,
        "hashtag_count": len(tags),
        "title": title,
        "niche": niche,
        "generated_at": datetime.now().isoformat()
    }

def main():
    parser = argparse.ArgumentParser(description="Generate Instagram captions for Etsy products")
    parser.add_argument("--title", required=True, help="Product title")
    parser.add_argument("--niche", choices=["military", "patriotic", "christian", "outdoor"], required=True)
    parser.add_argument("--description", help="Optional custom description")
    parser.add_argument("--hashtags", type=int, default=15, help="Number of hashtags (default: 15)")
    parser.add_argument("--json", action="store_true", help="Output as JSON")
    
    args = parser.parse_args()
    
    result = generate_caption(
        title=args.title,
        niche=args.niche,
        description=args.description,
        hashtag_count=args.hashtags
    )
    
    if args.json:
        print(json.dumps(result, indent=2))
    else:
        print(result["caption"])

if __name__ == "__main__":
    main()
