"""Main entry point for the vaultgen project."""

import argparse
from pathlib import Path

from .agent import initialize_agent
from .cli import cli
from .start import start


def chat() -> None:
    """Chat function for the vaultgen project."""
    vault = Path.cwd()
    if not vault.exists():
        raise FileNotFoundError(f"Vault not found in {vault}")

    agent = initialize_agent(vault)
    cli(agent, vault)


def init() -> None:
    """Init function for the vaultgen project."""
    vault = Path.cwd()
    if not vault.exists():
        raise FileNotFoundError(f"Vault not found in {vault}")

    start(vault)


def main() -> None:
    """Main function for the vaultgen project."""
    parser = argparse.ArgumentParser(description="Vaultgen project")
    subparsers = parser.add_subparsers(dest="command", required=True)

    subparsers.add_parser(
        "init", help="Initialize the vaultgen project (creates config.md)"
    )
    subparsers.add_parser("chat", help="Chat with the vaultgen agent")

    args = parser.parse_args()
    if args.command in ("init"):
        init()
    elif args.command == "chat":
        chat()
