"""Application entry point."""

from __future__ import annotations

import sys
from datetime import datetime

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication

from app.config import APP_NAME, LOG_DIR
from app.logging_setup import setup_logging


def main() -> None:
    session_id = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    log_path = setup_logging(LOG_DIR, session_id)

    # Import after logging is ready so module-level loggers work correctly
    import logging  # noqa: PLC0415

    from app.ui.main_window import MainWindow  # noqa: PLC0415

    logger = logging.getLogger(__name__)
    logger.info("Application starting (session: %s)", session_id)

    app = QApplication(sys.argv)
    app.setApplicationName(APP_NAME)
    app.setHighDpiScaleFactorRoundingPolicy(
        Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
    )

    window = MainWindow(log_path=log_path)
    window.show()

    logger.info("Application shutting down")
    sys.exit(app.exec())


if __name__ == "__main__":
    main()
