#!/usr/bin/python3

import argparse
import sys

from erimp import Erimp
from grund import Grund

desc = 'feed alfits from an issuedate into the grund'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-v', action='store_true', help='raise verbosity')
parser.add_argument('-l', action='store_true', help='only produce vemLis')
parser.add_argument('-s', action='store_true', help='show papids')
parser.add_argument('-u', action='store_true', help='update')
parser.add_argument('-r', action='store_true', help='only reload data')
parser.add_argument('-f', action='store_true', help='start with fill')
parser.add_argument('-a', action='store_true', help='alfit file')
parser.add_argument('-y', type=str, help='stYle')
parser.add_argument('bapis', metavar='bnp', type=str, nargs='*',
                    help='bits and pieces arguments')
args = parser.parse_args()

e = Erimp(args.bapis, do_verbose=args.v)
# # we only need to do this if we have grund
if int(e.conf['grund_size']) == 0:
    sys.exit()

grund = Grund(erimp=e, style=args.y)

if args.s:
    grund.show()
    sys.exit()

if args.a:
    grund.alfit_file()
    sys.exit()

if args.r:
    grund.reload_alfits()
    sys.exit()

if args.l:
    grund.vemli()
    sys.exit()

if args.u:
    grund.feed_issue(e.max_issuedate)
    grund.vemli()
    sys.exit()

if e.given_issuedate is None:
    print("I need an issuedate.")
    sys.exit()

if args.f:
    grund.fill_sered()
grund.load()
grund.feed_issue(e.given_issuedate)
# grund.fill_eval()
# grund.sort()
