#!/usr/bin/env python

import argparse

import everest


def _build_argument_parser() -> argparse.ArgumentParser:
    description = (
        "Filters the well entries in WELL_DATA based on the properties "
        '"drill_time" and "completion_time". In particular, it filters out '
        "any entry violating the following constraint: "
        "START_DATE <= COMPLETION_DATE-DRILL_TIME <= COMPLETION_DATA <= END_DATA."
        "All input files are expected to be formatted as JSON or YAML. All input "
        "dates are expected to be on the format dd.mm.yyyy."
        "The output file will be written as JSON."
    )
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        "--output",
        required=True,
        help="file to output filtered well data to",
    )
    parser.add_argument(
        "--well_data",
        required=True,
        help="the well data as json or yaml",
    )
    parser.add_argument(
        "--start_date",
        required=True,
        help="the start date of operations (dd.mm.yyyy)",
    )
    parser.add_argument(
        "--end_date",
        required=True,
        help="the end date of operations (dd.mm.yyyy)",
    )
    return parser


def main():
    arg_parser = _build_argument_parser()
    args = arg_parser.parse_args()

    everest.jobs.well_tools.well_opdate_filter(
        args.well_data,
        args.start_date,
        args.end_date,
        args.output,
    )


if __name__ == "__main__":
    main()
