#!/usr/bin/env python3
"""LICENSE
Copyright 2019 Hermann Krumrey <hermann@krumreyh.com>

This file is part of footballbot.

footballbot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

footballbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with footballbot.  If not, see <http://www.gnu.org/licenses/>.
LICENSE"""

import os
import argparse
import logging
from kudubot.exceptions import ConfigurationError
from footballbot.footballbotBot import footballbotBot
from bokkichat.connection.impl.TelegramBotConnection import \
    TelegramBotConnection


def main():
    """
    The main method of this program
    :return: None
    """
    default_config_path = os.path.join(
        os.path.expanduser("~"),
        ".config/footballbot"
    )

    parser = argparse.ArgumentParser()
    parser.add_argument("--initialize", action="store_true",
                        help="Initializes the footballbot bot")
    parser.add_argument("--verbose", "-v", action="store_true",
                        help="Shows more output")
    parser.add_argument("--custom-dir", default=default_config_path,
                        help="Specifies a custom configuration directory")
    args = parser.parse_args()

    config_path = args.custom_dir

    if args.verbose:
        logging.basicConfig(level=logging.INFO)

    if args.initialize:
        footballbotBot.create_config(TelegramBotConnection, config_path)

    else:
        try:
            bot = footballbotBot.load(TelegramBotConnection, config_path)
            bot.start()
        except ConfigurationError as e:
            print("Invalid Configuration: {}".format(e))


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass
