import logging

logger = logging.getLogger(__name__)

set_smtp_groovy = """\
def result = "FAILED"
for(desc in [Jenkins.getInstance().getDescriptor("hudson.plugins.emailext.ExtendedEmailPublisher"),Jenkins.getInstance().getDescriptor("hudson.tasks.Mailer")]){
    if(desc.getSmtpServer().equals("${host}") &&
       (desc instanceof hudson.tasks.Mailer$DescriptorImpl ? desc.getSmtpAuthUserName() : desc.getSmtpUsername()) == "${username}" &&
       (desc instanceof hudson.tasks.Mailer$DescriptorImpl ? desc.getSmtpAuthPassword() : desc.getSmtpPassword().toString()) == "${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
