#!/usr/bin/env python

import argparse
from stamper import Stamper


if __name__ == '__main__':

    parser = argparse.ArgumentParser(
        description='stamps: show recorded times information')
    parser.add_argument('customer', action="store", nargs='?',
                        help='Show times only for this customer')
    parser.add_argument('filter', action="store", nargs='?',
                        help='Filter the times by date range')
    parser.add_argument('-v', '--verbose', action="store_true",
                        help='Include detailed times information')
    parser.add_argument('-s', '--sum', action="store_true",
                        help='Include sum of times')
    parser.add_argument('-g', '--graph', action="store_true",
                        help='Generate a SVG graph')
    parser.add_argument('-t', '--timeline', action="store_true",
                        help='Show a timeline of recorded times')
    parser.add_argument('-d', '--delete', action="store", type=int,
                        help='Delete up to n recorded stamps')
    parser.add_argument('-i', '--import', action="store", dest="import_file",
                        help='Import stamps from the given file')

    args = parser.parse_args()

    s = Stamper()
    s.load_stamps()

    # Set proper arguments if they have passed a date-based filter without
    # a customer
    if args.customer not in s.customers and not args.filter:
        args.filter = args.customer
        args.customer = None

    # Call the proper methods, based on the given parameters
    if args.timeline:
        s.timeline(args.filter)
    elif args.delete:
        s.remove_stamps(args.delete)
    elif args.graph:
        s.graph_stamps(args.customer, args.filter)
    elif args.import_file:
        s.import_stamps(args.import_file)
    else:
        s.show_stamps(args.customer, args.filter, args.verbose, args.sum)
