#!/usr/bin/env python3
# encoding: utf-8

#    Copyright 2021 Google LLC
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
"""
Script to convert Autosys JIL files into dag-factory yaml format
"""

import argparse
import re
from parsimonious.grammar import Grammar
from parsimonious.nodes import NodeVisitor
import yaml


class JilVisitor(NodeVisitor):
    """
    Instance of Class inhereting the library's Class to customize each element of
    what the parser found.
    """

    def visit_expr(self, _node, visited_children):
        """ Returns the overall output. """
        value = None
        key = None

        def setup_default_args():
            """ Add the default args section to the result dictionary"""
            default_arg_keys = ["owner"]
            if "default_args" not in value.keys():
                value["default_args"] = dict()
                value["default_args"]["start_date"] = "1 days"
            for def_arg in default_arg_keys:
                if def_arg in value.keys():
                    value["default_args"][def_arg] = value[def_arg]