#!/usr/bin/env python3
"""
Etsy Listing Optimizer
Generate SEO-optimized titles, tags, and descriptions for Etsy SVG listings
"""

import argparse
import json
from datetime import datetime

NICHE_KEYWORDS = {
    "military": {
        "primary": ["usmc svg", "marine corps svg", "military svg", "veteran svg"],
        "secondary": ["semper fi", "military wife", "marine mom", "armed forces"],
        "use_cases": ["tumbler design", "shirt svg", "decal", "wall art", "cricut"],
        "tags": [
            "usmc svg", "marine corps svg", "military svg", "veteran svg",
            "semper fi svg", "military wife tumbler", "usmc decal",
            "marine mom shirt", "veteran gift svg", "military cricut",
            "patriotic cut file", "armed forces svg", "usmc png"
        ]
    },
    "patriotic": {
        "primary": ["usa svg", "american flag svg", "patriotic svg", "4th of july svg"],
        "secondary": ["american eagle", "stars and stripes", "freedom", "liberty"],
        "use_cases": ["tumbler", "shirt", "decal", "wall art", "cricut design"],
        "tags": [
            "usa svg", "american flag svg", "patriotic svg", "4th of july svg",
            "eagle svg", "american patriot", "usa tumbler design", "flag decal",
            "independence day", "american pride svg", "red white blue svg",
            "usa cricut", "patriotic shirt"
        ]
    },
    "christian": {
        "primary": ["faith svg", "scripture svg", "bible verse svg", "christian svg"],
        "secondary": ["reformed", "church", "prayer", "cross"],
        "use_cases": ["wall art", "shirt", "tumbler", "gift", "decor"],
        "tags": [
            "faith svg", "scripture svg", "bible verse svg", "christian svg",
            "church svg", "religious decor", "prayer svg", "jesus svg",
            "cross svg", "christian gift", "church shirt", "faith tumbler",
            "scripture art"
        ]
    },
    "outdoor": {
        "primary": ["hunting svg", "deer svg", "wildlife svg", "outdoor svg"],
        "secondary": ["cabin", "forest", "nature", "wilderness"],
        "use_cases": ["tumbler", "shirt", "decal", "wall art", "wood burning"],
        "tags": [
            "hunting svg", "deer svg", "wildlife svg", "cabin svg",
            "outdoor svg", "hunter gift", "elk svg", "buck svg",
            "hunting tumbler", "outdoor decor", "nature svg", "forest svg",
            "hunting shirt svg"
        ]
    }
}

def generate_title(product_name: str, niche: str) -> str:
    """Generate SEO-optimized Etsy title (max 140 chars)"""
    keywords = NICHE_KEYWORDS.get(niche, NICHE_KEYWORDS["patriotic"])
    
    # Build title components
    primary = keywords["primary"][0].upper()
    secondary = keywords["secondary"][0].title()
    use_case = keywords["use_cases"][0].title()
    
    title = f"{product_name} | {primary.replace(' svg', '')} SVG | {secondary} {use_case} Design | Cut File for Cricut Silhouette"
    
    # Truncate if too long
    if len(title) > 140:
        title = title[:137] + "..."
    
    return title

def generate_tags(niche: str) -> list:
    """Generate 13 SEO tags for listing"""
    keywords = NICHE_KEYWORDS.get(niche, NICHE_KEYWORDS["patriotic"])
    return keywords["tags"][:13]

def generate_description(product_name: str, niche: str) -> str:
    """Generate listing description"""
    return f"""✨ {product_name} - Instant Digital Download ✨

Transform your craft projects with this high-quality {niche} design!

📦 WHAT'S INCLUDED:
• SVG file (for Cricut, Silhouette, laser cutters)
• PNG file (300 DPI, transparent background)
• PDF file (for reference)

💡 PERFECT FOR:
• T-shirts & apparel
• Tumblers & drinkware  
• Wall art & signs
• Car decals & stickers
• Wood burning & engraving
• And so much more!

⚙️ COMPATIBLE WITH:
• Cricut Design Space
• Silhouette Studio
• Brother ScanNCut
• Laser cutting software
• Adobe Illustrator
• Inkscape

📥 HOW IT WORKS:
1. Purchase and download instantly
2. Unzip the files
3. Upload to your cutting software
4. Create something amazing!

⚠️ PLEASE NOTE:
• This is a DIGITAL FILE - no physical item will be shipped
• Colors may vary slightly based on your monitor and materials
• Personal and small commercial use included

❓ QUESTIONS?
Message me anytime! I typically respond within 24 hours.

Thank you for supporting RoyalStylesCreations! 💕
"""

def generate_listing(product_name: str, niche: str, price: float = 2.99) -> dict:
    """Generate complete listing data"""
    return {
        "title": generate_title(product_name, niche),
        "tags": generate_tags(niche),
        "description": generate_description(product_name, niche),
        "price": price,
        "niche": niche,
        "product_name": product_name,
        "generated_at": datetime.now().isoformat()
    }

def main():
    parser = argparse.ArgumentParser(description="Generate Etsy listing content")
    parser.add_argument("--name", required=True, help="Product name")
    parser.add_argument("--niche", choices=["military", "patriotic", "christian", "outdoor"], required=True)
    parser.add_argument("--price", type=float, default=2.99, help="Price (default: 2.99)")
    parser.add_argument("--output", help="Output JSON file")
    
    args = parser.parse_args()
    
    listing = generate_listing(args.name, args.niche, args.price)
    
    if args.output:
        with open(args.output, "w") as f:
            json.dump(listing, f, indent=2)
        print(f"Listing saved to {args.output}")
    else:
        print("=" * 60)
        print("TITLE:")
        print(listing["title"])
        print("\n" + "=" * 60)
        print("TAGS:")
        print(", ".join(listing["tags"]))
        print("\n" + "=" * 60)
        print("DESCRIPTION:")
        print(listing["description"])

if __name__ == "__main__":
    main()
