import logging

logger = logging.getLogger(__name__)

set_smtp_groovy = """\
def result = ""
for(desc in [Jenkins.getInstance().getDescriptor("hudson.plugins.emailext.ExtendedEmailPublisher"),Jenkins.getInstance().getDescriptor("hudson.tasks.Mailer")]){
    if(desc.getSmtpServer().equals("${host}") &&
       ((desc instanceof hudson.plugins.emailext.ExtendedEmailPublisherDescriptor && desc.getSmtpAuthUsername().equals("${username}")) ||
        (desc instanceof hudson.tasks.Mailer$DescriptorImpl && desc.getSmtpAuthUserName().equals("${username}"))) &&
       desc.getSmtpAuthPassword().toString().equals("${password}") &&
       desc.getSmtpPort().equals("${port}") &&
       desc.getUseSsl() == ${ssl} &&
       desc.getCharset().equals("${charset}") &&
       (!${reply_to_exists} || desc.getReplyAddress().equals("${reply_to}"))){
            result = "EXISTS"
    }else{
        desc.setSmtpAuth("${username}", "${password}")
        desc.setUseSsl(${ssl})
        if(desc instanceof hudson.plugins.emailext.ExtendedEmailPublisherDescriptor){
            desc.setSmtpServer("${host}")
        }else{
            desc.setSmtpHost("${host}")
        }
        desc.setSmtpPort("${port}")
        desc.setCharset("${charset}")
        if(${reply_to_exists}){
            desc.setReplyToAddress("${reply_to}")
        }
        desc.save()
        result = "SUCCESS"
    }
}
print(result)
"""  # noqa

set_admin_email_groovy = """
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
if(jenkinsLocationConfiguration.getAdminAddress().equals("${email}")){
    print("EXISTS")
}else{
    jenkinsLocationConfiguration.setAdminAddress("${email}")
    jenkinsLocationConfiguration.save()
    print("SUCCESS")
}
"""  # noqa


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


def config(name, host, username, password, reply_to=None,
           port=25, ssl=False, charset="UTF-8"):
    """
    Jenkins SMTP server config state method

    :param name: configuration name
    :param host: SMTP host
    :param username: SMTP username
    :param password: SMTP password
    :param reply_to: sent emails ReplyTo header (optional)
    :param port: SMTP port (optional, default 25)
    :param ssl: use SSL for SMTP (optional, default False)
    :param charset: SMTP charset (optional, default UTF-8)
    :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 SMTP config %s %s' % (name, status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            set_smtp_groovy, {"username": username, "password": password, "host": host,
                              "reply_to_exists": "true" if reply_to else "false",
                              "reply_to": reply_to,
                              "port": port if port else 25,
                              "ssl": "true" if ssl else "false",
                              "charset": charset if charset else "UTF-8"})
        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 smtp config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins smtp API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins smtp API call failure: %s' % (call_result[
                "msg"])
    ret['result'] = None if test else result
    return ret


def admin_email(name, email):
    """
    Jenkins Admin user email config state method

    :param name: jenkins admin email
    :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 admin email config %s %s' % (
            name, status.lower())
    else:
        call_result = __salt__['jenkins_common.call_groovy_script'](
            set_admin_email_groovy, {"email": email})
        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 admin email config %s %s' % (
                name, status.lower())
            result = True
        else:
            status = 'FAILED'
            logger.error(
                "Jenkins admin email API call failure: %s", call_result["msg"])
            ret['comment'] = 'Jenkins admin email API call failure: %s' % (call_result[
                                                                           "msg"])
    ret['result'] = None if test else result
    return ret
