# -*- 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=False):
    """ 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
