# -*- coding: utf-8 -*-
'''
Management of runtest resources
===============================
:depends:   - jsonpath-rw Python module
:configuration: See :py:mod:`salt.modules.runtest` for setup instructions.
'''

import importlib
import logging
import os
from functools import wraps
LOG = logging.getLogger(__name__)

DEPENDENCIES = ['jsonpath_rw']

def __virtual__():
    '''
    Only load if runtest module if dependencies are present
    '''
    failures = []
    for module in DEPENDENCIES:
        try:
            importlib.import_module(module)
        except ImportError:
            failures.append(module)
    if failures:
        log.error("The required modules are not present %s" % ','.join(failures))
        return False
    return 'runtest'

def _test_call(method):
    (resource, functionality) = method.func_name.split('_')
    if functionality == 'present':
        functionality = 'updated'
    else:
        functionality = 'removed'

    @wraps(method)
    def check_for_testing(name, *args, **kwargs):
        if __opts__.get('test', None):
            return _no_change(name, resource, test=functionality)
        return method(name, *args, **kwargs)
    return check_for_testing

@_test_call
def tempestconf_present(name, regenerate=True):
    """ Checks that file with config present."""


    if os.path.isfile(name) and not regenerate:
      	return _no_change(name, 'tempest_config')

    cfg = __salt__['runtest.generate_tempest_config'](name)
    return _created(name, 'tempest_config', cfg)


def _created(name, resource, resource_definition):
    changes_dict = {'name': name,
                    'changes': resource_definition,
                    'result': True,
                    'comment': '{0} {1} created'.format(resource, name)}
    return changes_dict

def _no_change(name, resource, test=False):
    changes_dict = {'name': name,
                    'changes': {},
                    'result': True}
    if test:
        changes_dict['comment'] = \
            '{0} {1} will be {2}'.format(resource, name, test)
    else:
        changes_dict['comment'] = \
            '{0} {1} is in correct state'.format(resource, name)
    return changes_dict
