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
