import ast


def _parse_route_settings(cli_route_settings):
    """
    Parses ``--set`` route settings for the ``msdss-data`` command line tool.

    Parameters
    ----------
    cli_route_settings : list(tuple)
        List of tuples of length 3, representing the route, key setting and value setting in order.

    Returns
    -------
    dict
        A dictionary that can be passed to parameter ``route_settings`` in :func:`msdss_data_api.routers.get_data_router`

    Author
    ------
    Richard Wen <rrwen.dev@gmail.com>

    Example
    -------

    .. jupyter-execute::
        :hide-output:

        from msdss_data_api.cli import _parse_route_settings
        from pprint import pprint

        cli_route_settings = [
            ('create', '_restricted_tables', '["user", "data"]'),
            ('create', '_enable', 'True'),
            ('create', '_get_user', '{"superuser": True}'),
            ('delete', 'path', '/{dataset}'),
            ('delete', 'tags', '["data"]')
        ]
        route_settings = _parse_route_settings(cli_route_settings)
        pprint(route_settings)
    """
    out = {route: {} for route, k, v in cli_route_settings}
    for route, key, value in cli_route_settings:
        if key in ('tags', '_restricted_tables', '_get_user', '_enable'):
            out[route][key] = ast.literal_eval(value)
        else:
            out[route][key] = value
    return out