#!/usr/bin/env python3

# This file is part of tf-plan.

# tf-plan is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# tf-plan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with tf-plan. If not, see <http://www.gnu.org/licenses/>.


import argparse


def parse_args():
    description = 'Planning via gradient-based optimization in TensorFlow.'
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('rddl', type=str, help='RDDL filepath')
    parser.add_argument(
        '-b', '--batch_size',
        type=int, default=64,
        help='number of trajectories in a batch (default=64)'
    )
    parser.add_argument(
        '-v', '--verbose',
        action='store_true',
        help='verbosity mode'
    )
    return parser.parse_args()


def read_file(path):
    with open(path, 'r') as f:
        return f.read()


def compile(rddl):
    from pyrddl.parser import RDDLParser
    from tfrddlsim.compiler import Compiler

    # parse RDDL
    parser = RDDLParser()
    parser.build()
    rddl = parser.parse(rddl)

    # build RDDL2TensorFlow compiler
    return Compiler(rddl, batch_mode=True)


if __name__ == '__main__':

    # parse CLI arguments
    args = parse_args()

    # read RDDL file
    rddl = read_file(args.rddl)

    # compile RDDL to TensorFlow
    rddl2tf = compile(rddl)
