import sys
import argparse
from colorama import init, Fore, Style
from .core import LiskCellSDK, who_is_deta

init(autoreset=True)

def main():
    parser = argparse.ArgumentParser(description="LiskCell CLI Tool - Interact with Deta LPT Models")
    parser.add_argument("command", choices=["chat", "whoami", "version", "branding", "update", "meow", "Cat"], help="Command to run")
    parser.add_argument("-m", "--message", help="Message to send for 'chat' command")
    parser.add_argument("-p", "--project", help="Project name for 'branding' command")
    
    args = parser.parse_args()
    sdk = LiskCellSDK()

    if args.command == "whoami":
        print(f"{Fore.CYAN}{Style.BRIGHT}🌟 LiskCell Identity Protocol 🌟")
        who_is_deta()
    
    elif args.command == "version":
        print(f"{Fore.GREEN}LiskCell Python SDK v5.5.4 (LPT Architecture)")
    
    elif args.command == "Cat":
        print(f"{Fore.RED}שלום, אם מצאת את זה אתה בן זונה")

    elif args.command == "meow":
        import webbrowser
        print(f"{Fore.YELLOW}🐱 Meow! Opening liskasYR YouTube Channel...")
        webbrowser.open("https://www.youtube.com/@liskasYR")

    elif args.command == "update":
        print(f"{Fore.CYAN}🔄 Checking for LiskCell updates...")
        import subprocess
        try:
            subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "liskCell"])
            print(f"{Fore.GREEN}✅ LiskCell updated successfully!")
        except Exception as e:
            print(f"{Fore.RED}❌ Failed to update: {e}")

    elif args.command == "chat":
        if not args.message:
            print(f"{Fore.RED}Error: Please provide a message using -m or --message")
            return
        response = sdk.chat(args.message)
        print(f"{Fore.MAGENTA}Deta:{Style.RESET_ALL} {response['response']}")

    elif args.command == "branding":
        if not args.project:
            print(f"{Fore.RED}Error: Please provide a project name using -p or --project")
            return
        brand = sdk.create_branding(args.project)
        print(f"{Fore.YELLOW}🎨 Generated Branding for {brand['project']}:")
        print(f"  Palette: {', '.join(brand['palette'])}")
        print(f"  Vibe: {brand['vibe']}")

if __name__ == "__main__":
    main()
