#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from __future__ import (absolute_import, unicode_literals, division,
                        print_function)

from maltpynt.mp_lcurve import mp_scrunch_lightcurves
from maltpynt.mp_io import MP_FILE_EXTENSION
import argparse
import logging

description = \
    'Sum lightcurves from different instruments or energy ranges'
parser = argparse.ArgumentParser(description=description)
parser.add_argument("files", help="List of files", nargs='+')
parser.add_argument("-o", "--out", type=str,
                    default="out_scrlc" + MP_FILE_EXTENSION,
                    help='Output file')
parser.add_argument("--loglevel",
                    help=("use given logging level (one between INFO, "
                          "WARNING, ERROR, CRITICAL, DEBUG; default:WARNING)"),
                    default='WARNING',
                    type=str)
parser.add_argument("--debug", help="use DEBUG logging level",
                    default=False, action='store_true')

if __name__ == '__main__':
    args = parser.parse_args()
    files = args.files

    if args.debug:
        args.loglevel = 'DEBUG'

    numeric_level = getattr(logging, args.loglevel.upper(), None)
    logging.basicConfig(filename='MPscrunchlc.log', level=numeric_level,
                        filemode='w')

    mp_scrunch_lightcurves(files, args.out)
