#!/usr/bin/env python
import yaml
import os
import argparse

if __name__ == '__main__':
    script_dir = os.path.dirname(os.path.realpath(__file__))
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-f", "--filename",
        default='led.yaml',
        help="Input File Name")
    parser.add_argument(
        "-i", "--input-dir",
        dest='inputdir',
        default=script_dir,
        help="Input directory")
    parser.add_argument(
        '-o', '--output-dir',
        dest='outputdir',
        default='.',
        help='Output directory.')

    args = parser.parse_args()

    # Default to the one that is in the current.
    yaml_dir = script_dir
    yaml_file = os.path.join(yaml_dir, 'led.yaml')

    if args.inputdir:
        yaml_dir = args.inputdir

    if args.filename:
        yaml_file = os.path.join(yaml_dir, args.filename)

    with open(yaml_file, 'r') as f:
        ifile = yaml.safe_load(f)

    with open(os.path.join(args.outputdir, 'led-gen.hpp'), 'w') as ofile:
        ofile.write('/* !!! WARNING: This is a GENERATED Code..')
        ofile.write('Please do NOT Edit !!! */\n\n')

        ofile.write('static const std::map<std::string,')
        ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
        ofile.write(' systemLedMap = {\n\n')
        for group in ifile.iterkeys():
            # This section generates an std::map of LedGroupNames to std::set
            # of LEDs containing the name and properties
            ledset = ifile[group]
            ofile.write(
                '   {\"' +
                "/xyz/openbmc_project/ledmanager/groups/" +
                group +
                '\",{\n')

            for led_dict, list_dict in ledset.iteritems():
                # Need this to make sure the LED name is printed once
                name_printed = False
                for name, value in list_dict.iteritems():
                    if group and led_dict and name:
                        if name_printed is False:
                            ofile.write('        {\"' + led_dict + '\",')
                            name_printed = True
                        if name == 'Action':
                            ofile.write('phosphor::led::Layout::')
                        ofile.write(str(value) + ',')
                ofile.write('},\n')
            ofile.write('   }},\n')
        ofile.write('};\n')
