# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

import click
from rich.console import Console
from rich.table import Table

from ..load_provider_confs import load_provider_configs


@click.command(name="list-providers")
def list_providers_command():
    """List all available providers."""

    provider_configs = load_provider_configs()
    console = Console()

    table = Table(title="Available Providers", title_style="bold yellow")
    table.add_column("Provider", style="magenta")
    table.add_column("Base URL", style="cyan")
    table.add_column("API Key Env Var", style="cyan")

    provider_list = sorted(provider_configs.values(), key=lambda x: x.provider)

    for provider in provider_list:
        if provider.provider in ["model_card"]:
            continue
        table.add_row(provider.provider, provider.base_url, provider.api_key_var)

    console.print(table)
