#!/usr/bin/env python
import argparse
import sys

from jwst_gtvt.find_tgt_info import main

if __name__ == '__main__':
    try:
        # see if there is a negative dec in sexagesimal coordinates
        dec_index = [':' in arg and arg.startswith('-') for arg in sys.argv].index(True)
        arg_list = sys.argv[1:]
        dec = arg_list.pop(dec_index-1)
        arg_list.append('--')
        arg_list.append(dec)

    except ValueError:
        arg_list = sys.argv[1:]

    parser = argparse.ArgumentParser(description='')
    parser.add_argument('ra', help='Right Ascension of target in either sexagesimal (hh:mm:ss.s) or degrees.')
    parser.add_argument('dec', help='Declination of target in either sexagesimal (dd:mm:ss.s) or degrees.')
    parser.add_argument('--v3pa', help='Specify a desired V3 (telescope frame) Position Angle.')
    parser.add_argument('--save_plot', help='Path of file to save plot output.')
    parser.add_argument('--save_table', help='Path of file to save table output.')
    parser.add_argument('--instrument', help='If specified plot shows only windows for this instrument.  Options: nircam, nirspec, niriss, miri, fgs, v3 (case insensitive).')
    parser.add_argument('--name', help='Target Name to appear on plots.  Names with space should use double quotes e.g. "NGC 6240".')
    parser.add_argument('--start_date', help='Start date for visibility search in yyyy-mm-dd format. Earliest available is 2020-01-01.')
    parser.add_argument('--end_date', help='End date for visibility search in yyyy-mm-dd format. Latest available is 2023-12-31.')
    args = parser.parse_args(arg_list)

    main(args)