import logging

logger = logging.getLogger(__name__)

create_node_groovy = u"""\
import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
import hudson.plugins.sshslaves.*

def result=Jenkins.instance.slaves.find{
 it.name == '{name}' &&
 it.numExecutors == {num_executors} &&
 it.nodeDescription == "${desc}" &&
 it.remoteFS == "${remote_home}" &&
 it.labelString == "${label}" &&
 it.mode == Node.Mode.{node_mode} &&
 it.launcher.getClass().getName().equals({launcher}.getClass().getName()) &&
 it.retentionStrategy.getClass().getName().equals(new hudson.slaves.RetentionStrategy.${ret_strategy}().getClass().getName())}
if(result){
    print("EXISTS")
}else{
  Slave slave = new DumbSlave(
                    "${name}",
                    "${desc}",
                    "${remote_home}",
                    "${num_executors}",
                    Node.Mode.${node_mode},
                    "${label}",
                    ${launcher},
                    new RetentionStrategy.${ret_strategy}(),
                    new LinkedList())
  Jenkins.instance.addNode(slave)
  print("CREATED")
}
"""  # noqa

create_lbl_groovy = u"""\
hudson = hudson.model.Hudson.instance
updated = false
hudson.slaves.find { slave -> slave.nodeName.equals("${name}")
  if({append}){
    slave.labelString = slave.labelString + " " + "${lbl_text}"
  }else{
    slave.labelString = "${lbl_text}"
  }
  updated = true
  print "${lbl_text}"
}
if(!updated){
    print "FAILED"
}
hudson.save()
"""  # noqa

configure_master_groovy = u"""\
def instance = Jenkins.instance
def changed = false

if(Jenkins.instance.numExecutors != ${num_executors}){
    Jenkins.instance.setNumExecutors(${num_executors})
    changed = true
}

if(!Jenkins.instance.mode.name.equals(new String("${node_mode}").toUpperCase())){
    Jenkins.instance.setMode(Node.Mode.${node_mode})
    changed = true
}

if(!Jenkins.instance.labelString.equals("${labels}")){
    Jenkins.instance.setLabelString("${labels}")
    changed = true
}
if(changed){
    Jenkins.instance.save()
    print("CREATED")
}else{
    print("EXISTS")
}
"""


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


def label(name, lbl_text, append=False):
    """
    Jenkins node label state method

    :param name: node name
    :param lbl_text: label text
    :returns: salt-specified state dict
    """
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        status = 'CREATED'
        ret['changes'][name] = status
        ret['comment'] = 'Label %s %s' % (name, status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            create_lbl_groovy, {'name': name, 'lbl_text': lbl_text, 'append': "true" if append else "false"})
        if call_result["code"] == 200 and call_result["msg"].strip(
        ) == lbl_text:
            status = "CREATED"
            ret['changes'][name] = status
            ret['comment'] = 'Label %s %s ' % (name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins label API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins label API call failure: %s' % (
                call_result["msg"])
    ret['result'] = None if test else result
    return ret


def present(name, remote_home, launcher, num_executors="1",
            node_mode="Normal", desc="", labels=[], ret_strategy="Always"):
    """
    Jenkins node state method

    :param name: node name
    :param remote_home: node remote home path
    :param launcher: launcher dict with type, name, port, username, password
    :param num_executors: number of node executurs (optional, default 1)
    :param node_mode: node mode (optional, default Normal)
    :param desc: node description (optional)
    :param labels: node labels list (optional)
    :param ret_strategy: node retention strategy from RetentionStrategy class
    :returns: salt-specified state dict
    """
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        status = 'CREATED'
        ret['changes'][name] = status
        ret['comment'] = 'Node %s %s' % (name, status.lower())
    else:
        label_string = " ".join(labels)
        launcher_string = "new hudson.slaves.JNLPLauncher()"
        if launcher:
            if launcher["type"] == "ssh":
                launcher_string = 'new hudson.plugins.sshslaves.SSHLauncher("{}",{},"{}","{}","","","","","")'.format(
                    launcher["host"], launcher["port"], launcher["username"], launcher["password"])
            elif launcher["type"] == "jnlp":
                launcher_string = "new hudson.slaves.JNLPLauncher()"

        call_result = __salt__['jenkins_common.call_groovy_script'](
            create_node_groovy,
            {"name": name,
                "desc": desc if desc else "",
                "label": label_string if label_string else "",
                "remote_home": remote_home if remote_home else "",
                "num_executors": num_executors if num_executors else "1",
                "launcher": launcher_string,
                "node_mode": node_mode.upper(),
                "ret_strategy": ret_strategy if ret_strategy else "Always"})
        if call_result["code"] == 200 and call_result["msg"] in [
                "CREATED", "EXISTS"]:
            status = call_result["msg"]
            if call_result["msg"] == "CREATED":
                ret['changes'][name] = status
            ret['comment'] = 'Node %s %s' % (name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins node API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins node API call failure: %s' % (
                call_result["msg"])
    ret['result'] = None if test else result
    return ret


def setup_master(name, num_executors="1", node_mode="Normal", labels=[]):
    """
    Jenkins setup master state method

    :param name: node name (master)
    :param num_executors: number of executors (optional, default 1)
    :param node_mode: Node mode (Normal or Exclusive)
    :param labels: array of labels
    :returns: salt-specified state dict
    """
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        status = 'CREATED'
        ret['changes'][name] = status
        ret['comment'] = 'Master node %s' % (status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            configure_master_groovy, {'num_executors': num_executors, 'labels': " ".join(labels), 'node_mode': node_mode.upper()})
        if call_result["code"] == 200 and call_result["msg"] in [
                "CREATED", "EXISTS"]:
            status = call_result["msg"]
            if status == "CREATED":
                ret['changes'][name] = status
            ret['comment'] = 'Master node configuration %s ' % (status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins master configure API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins master configure API call failure: %s' % (
                call_result["msg"])
    ret['result'] = None if test else result
    return ret
