import logging

logger = logging.getLogger(__name__)

test_timestamper_groovy = """\
import hudson.plugins.timestamper.TimestamperConfig

def timestamper = TimestamperConfig.get()
if (timestamper.isAllPipelines()) {
  print("ENABLED")
} else {
  print("DISABLED")
}
"""

enable_timestamper_groovy = """\
import hudson.plugins.timestamper.TimestamperConfig

def timestamper = TimestamperConfig.get()
if (!timestamper.isAllPipelines()) {
  timestamper.setAllPipelines(true)
  print("ENABLED")
} else {
  print("ALREADY ENABLED")
}
"""

disable_timestamper_groovy = """\
import hudson.plugins.timestamper.TimestamperConfig

def timestamper = TimestamperConfig.get()
if (timestamper.isAllPipelines()) {
  timestamper.setAllPipelines(false)
  print("DISABLED")
} else {
  print("ALREADY DISABLED")
}
"""

def __virtual__():
    '''
    Only load if jenkins_common module exist.
    '''
    if 'jenkins_common.call_groovy_script' not in __salt__:
        return (
            False,
            'The jenkins_timestamper state module cannot be loaded: '
            'jenkins_common not found')
    return True


def present(name='timestamper'):
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            test_timestamper_groovy, {})
        if call_result["code"] == 200 and call_result["msg"] in [
                "DISABLED"]:
            ret['comment'] = 'Jenkins timestamper will be enabled'
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            enable_timestamper_groovy, {})
        if call_result["code"] == 200 and call_result["msg"] in [
                "ENABLED", "ALREADY ENABLED"]:
            status = call_result["msg"]
            if status == "ENABLED":
                ret['changes'][name] = status
            ret['comment'] = 'Jenkins timestamper config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins timestamper config API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins timestamper config API call failure: %s' % (call_result[
                "msg"])
    ret['result'] = None if test else result
    return ret


def absent(name='timestamper'):
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            test_timestamper_groovy, {})
        if call_result["code"] == 200 and call_result["msg"] in [
                "ENABLED"]:
            ret['comment'] = 'Jenkins timestamper will be disabled'
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            disable_timestamper_groovy, {})
        if call_result["code"] == 200 and call_result["msg"] in [
                "DISABLED", "ALREADY DISABLED"]:
            status = call_result["msg"]
            if status == "DISABLED":
                ret['changes'][name] = status
            ret['comment'] = 'Jenkins timestamper config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins timestamper config API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins timestamper config API call failure: %s' % (call_result[
                "msg"])
    ret['result'] = None if test else result
    return ret

