import asyncio

import click
import uvloop  # type: ignore
from aiohttp_micro.cli.server import server  # type: ignore
from aiohttp_storage.management.storage import storage  # type: ignore
from config import EnvValueProvider, load  # type: ignore
from config.providers import ValueProvider

from wallet.app import init
from wallet.config import AppConfig, VaultConfig, VaultProvider


@click.group()
@click.option("--debug", is_flag=True, default=False)
@click.pass_context
def cli(ctx, debug: bool = False) -> None:
    uvloop.install()
    loop = asyncio.get_event_loop()

    providers: list[ValueProvider] = [EnvValueProvider()]

    vault_config = VaultConfig()
    load(vault_config, providers=providers)

    if vault_config.enabled:
        providers = [VaultProvider(config=vault_config, mount_point="credentials"), *providers]

    config = AppConfig(defaults={"debug": debug, "db": {"user": "wallet", "password": "<PASSWORD>", "database": "wallet"}})
    load(config, providers=providers)

    app = init("wallet", config)

    if config.debug:
        app["logger"].debug("Application config", db=config.db.uri, sentry=config.sentry_dsn)

    ctx.obj["app"] = app
    ctx.obj["config"] = config
    ctx.obj["loop"] = loop


cli.add_command(server, name="server")
cli.add_command(storage, name="storage")


if __name__ == "__main__":
    cli(obj={})

import asyncio

import click
import uvloop  # type: ignore
from aiohttp_micro.cli.server import server  # type: ignore
from aiohttp_storage.management.storage import storage  # type: ignore
from config import EnvValueProvider, load  # type: ignore
from config.providers import ValueProvider

from wallet.app import init
from wallet.config import AppConfig, VaultConfig, VaultProvider


@click.group()
@click.option("--debug", is_flag=True, default=False)
@click.pass_context
def cli(ctx, debug: bool = False) -> None:
    uvloop.install()
    loop = asyncio.get_event_loop()

    providers: list[ValueProvider] = [EnvValueProvider()]

    vault_config = VaultConfig()
    load(vault_config, providers=providers)

    if vault_config.enabled:
        providers = [VaultProvider(config=vault_config, mount_point="credentials"), *providers]

    config = AppConfig(defaults={"debug": debug, "db": {"user": "wallet", "password": "<PASSWORD>", "database": "wallet"}})
    load(config, providers=providers)

    app = init("wallet", config)

    if config.debug:
        app["logger"].debug("Application config", db=config.db.uri, sentry=config.sentry_dsn)

    ctx.obj["app"] = app
    ctx.obj["config"] = config
    ctx.obj["loop"] = loop


cli.add_command(server, name="server")
cli.add_command(storage, name="storage")


if __name__ == "__main__":
    cli(obj={})

# type: ignore # type: ignore # type: ignore # type: ignore