# Path: scar/utils.py
# class DataTypesUtils:
# 
#     """Common methods for data types management."""
# 
#     @staticmethod
#     def merge_dicts(dict1: Dict, dict2: Dict) -> Dict:
#         """Merge 'dict1' and 'dict2' dicts into 'dict1'.
#         'dict2' has precedence over 'dict1'.
#         """
#         for key, val in dict2.items():
#             if val is not None:
#                 if isinstance(val, dict) and key in dict1:
#                     dict1[key] = DataTypesUtils.merge_dicts(dict1[key], val)
#                 elif isinstance(val, list) and key in dict1:
#                     dict1[key] += val
#                 else:
#                     dict1[key] = val
#         return dict1
# 
#     @staticmethod
#     def merge_dicts_with_copy(dict1: Dict, dict2: Dict) -> Dict:
#         """Merge 'dict1' and 'dict2' dicts into a new Dict.
#         'dict2' has precedence over 'dict1'."""
#         result = deepcopy(dict1)
#         for key, val in dict2.items():
#             if val is not None:
#                 if isinstance(val, dict) and key in result:
#                     result[key] = DataTypesUtils.merge_dicts_with_copy(result[key], val)
#                 elif isinstance(val, list) and key in result:
#                     result[key] += val
#                 else:
#                     result[key] = val
#         return result
# 
#     @staticmethod
#     def divide_list_in_chunks(elements: List, chunk_size: int) -> Generator[List, None, None]:
#         """Yield successive n-sized chunks from th elements list."""
#         if not elements:
#             yield []
#         for i in range(0, len(elements), chunk_size):
#             yield elements[i:i + chunk_size]
# 
#     @staticmethod
#     def parse_arg_list(arg_keys: List, cmd_args: Dict) -> Dict:
#         """Parse an argument dictionary filtering by the names specified in a list."""
#         result = {}
#         for key in arg_keys:
#             if isinstance(key, tuple):
#                 if key[0] in cmd_args and cmd_args[key[0]]:
#                     result[key[1]] = cmd_args[key[0]]
#             else:
#                 if key in cmd_args and cmd_args[key]:
#                     result[key] = cmd_args[key]
#         return result


from typing import Dict
from scar.utils import DataTypesUtils
# 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.

FAAS_PROVIDERS = ["aws", "oscar"]

def merge_conf(conf: Dict, yaml: Dict) -> Dict:
    result = yaml.copy()
    # We have to merge the default config with all the defined functions
    for provider in FAAS_PROVIDERS:
        for index, function in enumerate(result.get('functions', {}).get(provider, {})):
            result['functions'][provider][index] = \
                DataTypesUtils.merge_dicts_with_copy(conf.get(provider,{}), function)
    result['scar'] = DataTypesUtils.merge_dicts_with_copy(result.get('scar', {}),
                                                          conf.get('scar', {}))
    return result

def merge_cmd_yaml(cmd: Dict, yaml: Dict) -> Dict:
    result = yaml.copy()
    # We merge the cli commands with all the defined functions
    # CLI only allows define AWS parameters
    for cli_cmd in cmd.get('functions', {}).get("aws", {}):
        for index, function in enumerate(result.get('functions', {}).get("aws", {})):
            result['functions']['aws'][index] = \

# Path: scar/utils.py
# class DataTypesUtils:
# 
#     """Common methods for data types management."""
# 
#     @staticmethod
#     def merge_dicts(dict1: Dict, dict2: Dict) -> Dict:
#         """Merge 'dict1' and 'dict2' dicts into 'dict1'.
#         'dict2' has precedence over 'dict1'.
#         """
#         for key, val in dict2.items():
#             if val is not None:
#                 if isinstance(val, dict) and key in dict1:
#                     dict1[key] = DataTypesUtils.merge_dicts(dict1[key], val)
#                 elif isinstance(val, list) and key in dict1:
#                     dict1[key] += val
#                 else:
#                     dict1[key] = val
#         return dict1
# 
#     @staticmethod
#     def merge_dicts_with_copy(dict1: Dict, dict2: Dict) -> Dict:
#         """Merge 'dict1' and 'dict2' dicts into a new Dict.
#         'dict2' has precedence over 'dict1'."""
#         result = deepcopy(dict1)
#         for key, val in dict2.items():
#             if val is not None:
#                 if isinstance(val, dict) and key in result:
#                     result[key] = DataTypesUtils.merge_dicts_with_copy(result[key], val)
#                 elif isinstance(val, list) and key in result:
#                     result[key] += val
#                 else:
#                     result[key] = val
#         return result
# 
#     @staticmethod
#     def divide_list_in_chunks(elements: List, chunk_size: int) -> Generator[List, None, None]:
#         """Yield successive n-sized chunks from th elements list."""
#         if not elements:
#             yield []
#         for i in range(0, len(elements), chunk_size):
#             yield elements[i:i + chunk_size]
# 
#     @staticmethod
#     def parse_arg_list(arg_keys: List, cmd_args: Dict) -> Dict:
#         """Parse an argument dictionary filtering by the names specified in a list."""
#         result = {}
#         for key in arg_keys:
#             if isinstance(key, tuple):
#                 if key[0] in cmd_args and cmd_args[key[0]]:
#                     result[key[1]] = cmd_args[key[0]]
#             else:
#                 if key in cmd_args and cmd_args[key]:
#                     result[key] = cmd_args[key]
#         return result


# Path: scar/parser/fdl.py
from typing import Dict
from scar.utils import DataTypesUtils

# 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.

FAAS_PROVIDERS = ["aws", "oscar"]

def merge_conf(conf: Dict, yaml: Dict) -> Dict:
    result = yaml.copy()
    # We have to merge the default config with all the defined functions
    for provider in FAAS_PROVIDERS:
        for index, function in enumerate(result.get('functions', {}).get(provider, {})):
            result['functions'][provider][index] = \
                DataTypesUtils.merge_dicts_with_copy(conf.get(provider,{}), function)
    result['scar'] = DataTypesUtils.merge_dicts_with_copy(result.get('scar', {}),
                                                          conf.get('scar', {}))
    return result

def merge_cmd_yaml(cmd: Dict, yaml: Dict) -> Dict:
    result = yaml.copy()
    # We merge the cli commands with all the defined functions
    # CLI only allows define AWS parameters
    for cli_cmd in cmd.get('functions', {}).get("aws", {}):
        for index, function in enumerate(result.get('functions', {}).get("aws", {})):
            result['functions']['aws'][index] = \

                DataTypesUtils.merge_dicts_with_copy(function, cli_cmd)