import argparse

from multiplayer_crosswords.server.websocket_crossword_server import WebsocketCrosswordServer
from multiplayer_crosswords.server.server_config import (
    ServerConfig,
    DEFAULT_WEBSOCKET_HOST,
    DEFAULT_WEBSOCKET_PORT,
    DEFAULT_MIN_GRID_SIZE,
    DEFAULT_MAX_GRID_SIZE,
    DEFAULT_MAX_SESSION_IDLE_TIME_SECONDS,
    DEFAULT_GRID_BLOCK_RATIO
)

def main():
    parser = argparse.ArgumentParser(description="Multiplayer Crossword WebSocket Server")
    parser.add_argument("--host", type=str, default=DEFAULT_WEBSOCKET_HOST, help="WebSocket server host")
    parser.add_argument("--port", type=int, default=DEFAULT_WEBSOCKET_PORT, help="WebSocket server port")
    parser.add_argument("--min-grid-size", type=int, default=DEFAULT_MIN_GRID_SIZE, help="Minimum grid size")
    parser.add_argument("--max-grid-size", type=int, default=DEFAULT_MAX_GRID_SIZE, help="Maximum grid size")
    parser.add_argument("--max-session-idle-time-seconds", type=int, default=DEFAULT_MAX_SESSION_IDLE_TIME_SECONDS, help="Maximum session idle time in seconds")
    parser.add_argument("--grid-block-ratio", type=float, default=DEFAULT_GRID_BLOCK_RATIO, help="Grid block ratio")

    args = parser.parse_args()

    ServerConfig.setup(
        min_grid_size=args.min_grid_size,
        max_grid_size=args.max_grid_size,
        max_session_idle_time_seconds=args.max_session_idle_time_seconds,
        grid_block_ratio=args.grid_block_ratio,
        host=args.host,
        port=args.port
    )

    config = ServerConfig.get_config()
    websocket_server = WebsocketCrosswordServer(host=config.HOST, port=config.PORT)

    websocket_server.run()

if __name__ == "__main__":
    main()
