#!/usr/bin/env python3
"""
Example 1: Basic Token Ingestion

Shows how to ingest design tokens from different sources.
"""

import asyncio
import sys
from pathlib import Path

# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))


async def main():
    print("=" * 60)
    print("EXAMPLE 1: Basic Token Ingestion")
    print("=" * 60)

    # 1. CSS Token Ingestion
    print("\n1. CSS Custom Properties")
    print("-" * 40)
    from tools.ingest.css import CSSTokenSource

    css_content = """
    :root {
        --color-primary: #3B82F6;
        --color-secondary: #10B981;
        --spacing-sm: 8px;
        --spacing-md: 16px;
        --spacing-lg: 24px;
    }
    """

    css_parser = CSSTokenSource()
    css_result = await css_parser.extract(css_content)

    print(f"✅ Extracted {len(css_result.tokens)} CSS tokens:")
    for token in css_result.tokens[:3]:
        print(f"   {token.name} = {token.value} ({token.type.value})")

    # 2. SCSS Token Ingestion
    print("\n2. SCSS Variables")
    print("-" * 40)
    from tools.ingest.scss import SCSSTokenSource

    scss_content = """
    $primary-color: #3B82F6;
    $secondary-color: #10B981;
    $font-family-sans: 'Inter', sans-serif;
    $font-size-base: 16px;
    """

    scss_parser = SCSSTokenSource()
    scss_result = await scss_parser.extract(scss_content)

    print(f"✅ Extracted {len(scss_result.tokens)} SCSS tokens:")
    for token in scss_result.tokens[:3]:
        print(f"   {token.name} = {token.value}")

    # 3. JSON Tokens (W3C Format)
    print("\n3. JSON Design Tokens (W3C)")
    print("-" * 40)
    from tools.ingest.json_tokens import JSONTokenSource
    import json

    json_content = {
        "color": {
            "primary": {
                "500": {"value": "#3B82F6", "type": "color"},
                "600": {"value": "#2563EB", "type": "color"}
            }
        },
        "spacing": {
            "md": {"value": "16px", "type": "dimension"}
        }
    }

    json_parser = JSONTokenSource()
    json_result = await json_parser.extract(json.dumps(json_content))

    print(f"✅ Extracted {len(json_result.tokens)} JSON tokens:")
    for token in json_result.tokens:
        print(f"   {token.name} = {token.value} ({token.type.value})")

    print("\n" + "=" * 60)
    print(f"Total tokens extracted: {len(css_result.tokens) + len(scss_result.tokens) + len(json_result.tokens)}")
    print("=" * 60)


if __name__ == "__main__":
    asyncio.run(main())
