#!/usr/bin/env python
"""Start script for {{ lab_name }}.

This script starts the MADSci lab manager in local mode.

Generated by: madsci new lab --template minimal
Template version: {{ template_version }}
"""

import logging
import os
from pathlib import Path

# Load environment from .env file if present
env_file = Path(__file__).parent / ".env"
if env_file.exists():
    from dotenv import load_dotenv
    load_dotenv(env_file)

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)


def main() -> None:
    """Start the lab manager."""
    logger.info("=" * 60)
    logger.info("Starting {{ lab_name }}")
    logger.info("{{ lab_description }}")
    logger.info("=" * 60)

    # Import here to allow environment to be loaded first
    from madsci.squid import SquidServer, SquidSettings

    settings = SquidSettings(
        name="{{ lab_name }}",
        server_url=os.getenv("LAB_SERVER_URL", "http://localhost:8000/"),
    )

    server = SquidServer(settings=settings)

    logger.info(f"Lab Manager URL: {settings.server_url}")
    logger.info("Press Ctrl+C to stop")

    server.start_server()


if __name__ == "__main__":
    main()
