import click
from .sheet_utils import get_saas, get_all_saas
from .ascii_art import image_to_ascii

@click.group()
def cli():
    pass

@click.command()
@click.argument('name')
def show(name):
    saas = get_saas(name)
    if not saas:
        print("SaaS not found!")
        return
    print(f"Name: {saas['Name']}")
    print(f"Description: {saas['Description']}")
    print(f"Link: {saas['Link']}")
    print(f"Contact: {saas['Contact']}")
    if saas.get('ImagePath') and str(saas['ImagePath']).strip():
        image_to_ascii(saas['ImagePath'])

@click.command(name="all")
def show_all():
    all_saas = get_all_saas()
    for idx, saas in enumerate(all_saas, start=1):
        print(f"{idx}. {saas['Name']}")

cli.add_command(show)
cli.add_command(show_all)
