#!/usr/bin/env python3
"""Setup script for sinhala-mcp VS Code integration.

This script automatically creates .vscode/settings.json with the required
model sampling configuration for sinhala-mcp.
"""

import json
import os
from pathlib import Path


def setup_vscode_config():
    """Create .vscode/settings.json with sinhala-mcp model sampling config."""

    # Get current directory
    cwd = Path.cwd()
    vscode_dir = cwd / ".vscode"
    settings_file = vscode_dir / "settings.json"

    # Create .vscode directory if it doesn't exist
    vscode_dir.mkdir(exist_ok=True)
    print(f"✓ Created directory: {vscode_dir}")

    # Define the model sampling configuration
    mcp_config = {
        "chat.mcp.serverSampling": {
            "sinhala-mcp/.vscode/mcp.json: sinhala-mcp": {
                "allowedModels": [
                    "copilot/auto",
                    "gemini-2.5-flash",
                    "gemini-2.5-flash-lite",
                    "gemini-2.5-pro",
                    "gemini-1.5-flash",
                ]
            }
        }
    }

    # Read existing settings if they exist
    existing_settings = {}
    if settings_file.exists():
        with open(settings_file, "r", encoding="utf-8") as f:
            existing_settings = json.load(f)
        print(f"✓ Read existing settings from {settings_file}")

    # Merge configurations
    merged_settings = {**existing_settings, **mcp_config}

    # Write the merged settings
    with open(settings_file, "w", encoding="utf-8") as f:
        json.dump(merged_settings, f, indent=4)
    print(f"✓ Created/updated: {settings_file}")
    print(f"✓ Added sinhala-mcp model sampling configuration")

    print("\n✅ Setup complete! Your VS Code is now configured for sinhala-mcp.")
    print("\nAllowed models:")
    for model in mcp_config["chat.mcp.serverSampling"]["sinhala-mcp/.vscode/mcp.json: sinhala-mcp"]["allowedModels"]:
        print(f"  • {model}")


if __name__ == "__main__":
    setup_vscode_config()
