import logging

logger = logging.getLogger(__name__)

config_global_libs_groovy = """\
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import jenkins.plugins.git.GitSCMSource;

def globalLibsDesc = Jenkins.getInstance().getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
def existingLib = globalLibsDesc.get().getLibraries().find{
  (!it.retriever.class.name.equals("org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever") ||
   it.retriever.scm.remote.equals("${url}") &&
   it.retriever.scm.credentialsId.equals("${credential_id}")) &&
   it.name.equals("${lib_name}") &&
   it.defaultVersion.equals("${branch}") &&
   it.implicit == true
}
if(existingLib){
    print("EXISTS")
}else{
    SCMSourceRetriever retriever = new SCMSourceRetriever(new GitSCMSource(
        "${lib_name}",
        "${url}",
        "${credential_id}",
        "*",
        "",
        false))
    LibraryConfiguration library = new LibraryConfiguration("${lib_name}", retriever)
    library.setDefaultVersion("${branch}")
    library.setImplicit(${implicit})
    if(globalLibsDesc.get().getLibraries().isEmpty()){
      globalLibsDesc.get().setLibraries([library])
    }else{
      globalLibsDesc.get().getLibraries().removeIf{ it.name.equals("${lib_name}")}
      globalLibsDesc.get().getLibraries().add(library)
    }
    globalLibsDesc.save()
    print("SUCCESS")
}
"""  # noqa

remove_global_libs_groovy = """\
def globalLibsDesc = Jenkins.getInstance().getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
def existingLib = globalLibsDesc.get().getLibraries().removeIf{it.name.equals("${lib_name}")}
if(existingLib){
    globalLibsDesc.save()
    print("DELETED")
}else{
    print("NOT PRESENT")
}
"""


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


def present(name, url, branch="master",
            credential_id="", implicit=True, **kwargs):
    """
    Jenkins Global pipeline library present state method

    :param name: pipeline library name
    :param url: url to remote repo
    :param branch: remote branch
    :param credential_id: credential id for repo
    :param implicit: implicit load boolean switch
    :returns: salt-specified state dict
    """
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        status = "SUCCESS"
        ret['changes'][name] = status
        ret['comment'] = 'Jenkins pipeline lib config %s %s' % (
            name, status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            config_global_libs_groovy, {"lib_name": name,
                                        "url": url,
                                        "branch": branch,
                                        "credential_id": credential_id if credential_id else "",
                                        "implicit": "true" if implicit else "false"
                                        })
        if call_result["code"] == 200 and call_result["msg"] in [
                "SUCCESS", "EXISTS"]:
            status = call_result["msg"]
            if status == "SUCCESS":
                ret['changes'][name] = status
            ret['comment'] = 'Jenkins pipeline lib config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins pipeline lib API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins pipeline lib API call failure: %s' % (call_result[
                "msg"])
    ret['result'] = None if test else result
    return ret


def absent(name, **kwargs):
    """
    Jenkins Global pipeline library absent state method

    :param name: pipeline library name
    :returns: salt-specified state dict
    """
    test = __opts__['test']  # noqa
    ret = {
        'name': name,
        'changes': {},
        'result': False,
        'comment': '',
    }
    result = False
    if test:
        status = "SUCCESS"
        ret['changes'][name] = status
        ret['comment'] = 'Jenkins pipeline lib config %s %s' % (
            name, status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            remove_global_libs_groovy, {"lib_name": name})
        if call_result["code"] == 200 and call_result["msg"] in [
                "DELETED", "NOT PRESENT"]:
            status = call_result["msg"]
            if status == "DELETED":
                ret['changes'][name] = status
            ret['comment'] = 'Jenkins pipeline lib config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins pipeline lib API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins pipeline lib API call failure: %s' % (call_result[
                "msg"])
    ret['result'] = None if test else result
    return ret
