"""Builds Swagger data model definitions using PAPI source docs."""
from __future__ import print_function

import argparse
import json
import modulefinder
import os
import re
import sys


def find_matching_obj_def(obj_defs, new_obj_def):
    """Find matching object definition."""
    for obj_name in obj_defs:
        existing_obj_def = obj_defs[obj_name]
        if 'properties' in new_obj_def and 'properties' in existing_obj_def:
            if new_obj_def['properties'] == existing_obj_def['properties']:
                return obj_name
        elif 'properties' not in existing_obj_def:
            print('**** No properties: {}'.format(existing_obj_def))
    return None


def find_or_add_obj_def(obj_defs, new_obj_def, new_obj_name):
    """Reuse existing object definition if exists or add new one."""
    matching_obj = find_matching_obj_def(obj_defs, new_obj_def)
    if matching_obj is not None:
        return matching_obj

    obj_defs[new_obj_name] = new_obj_def
    return new_obj_name


def add_dependencies(module_dir, filename, modules):
    finder = modulefinder.ModuleFinder()