import argparse

from maps_adv.common.config_loader import ConfigLoader, Option, converters
from maps_adv.common.lasagna import setup_logging
from maps_adv.geosmb.marksman.server.lib import Application

config = ConfigLoader(
    Option("DATABASE_URL"),
    Option("TVM_DAEMON_URL", load_from="DEPLOY_TVM_TOOL_URL"),
    Option("TVM_TOKEN", load_from="TVMTOOL_LOCAL_AUTHTOKEN"),
    Option(
        "TVM_WHITELIST", default=None, converter=converters.Tuple(element_converter=int)
    ),
    Option("BVM_URL"),
    Option("GEOSEARCH_URL"),
    Option("CDP_URL"),
    Option("YQL_TOKEN"),
    Option("YT_CLUSTER", default="hahn"),
    Option("DOORMAN_CLIENTS_TABLE"),
    Option("PROMOTER_LEADS_TABLE"),
    Option("WARDEN_URL", default=None),
    Option("WARDEN_TASKS", default=(), converter=converters.Tuple()),
)

arg_parser = argparse.ArgumentParser("Marksman")
arg_parser.add_argument("--host")
arg_parser.add_argument("--port", type=int)


def main():
    setup_logging()
    config.init()

    args = arg_parser.parse_args()

    app = Application(config)
    app.run(host=args.host, port=args.port)


if __name__ == "__main__":
    main()
