import argparse
from dataclasses import dataclass

from src.log import get_logger
from src.server import GrpcServer


@dataclass
class Args:
    stage: str
    port: int


def parse_args():
    parser = argparse.ArgumentParser(description="Logger stage selection")
    parser.add_argument(
        "--stage", choices=["dev", "prod"], default="dev", help="Set the stage of the application (dev or prod)"
    )
    parser.add_argument("--port", type=int, default=50051, help="Set the port to listen on")
    parsed_args = parser.parse_args()
    return Args(stage=parsed_args.stage, port=parsed_args.port)


if __name__ == "__main__":
    args = parse_args()
    logger = get_logger(stage=args.stage, port=args.port)
    server = GrpcServer(port=args.port, logger=logger)
    server.start()
