#!/usr/bin/env python

# oio-billing-buckets
# Copyright (C) 2022 OVH SAS
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import argparse

from oio.billing.agent import BillingAgent
from oio.common.configuration import read_conf
from oio.common.logger import get_logger


def make_arg_parser():
    descr = """
        Scan all buckets to fetch storage statistics
        and send billing messages to a RabbitMQ.
    """
    parser = argparse.ArgumentParser(description=descr)
    parser.add_argument(
        'config',
        help="""
        A file containing an oio-billing-agent configuration file.
        Any arguments passed alongside a configuration file will be ignored.
        """)
    parser.add_argument(
        '--verbose', '-v',
        action='store_true',
        help="More verbose output")
    return parser


if __name__ == '__main__':
    args = make_arg_parser().parse_args()
    verbose = args.verbose
    config = args.config

    conf = read_conf(config, 'billing-agent')
    logger = get_logger(conf, 'billing-agent', verbose=verbose)

    agent = BillingAgent(conf)
    agent.start()
