import at.clockwork.system.domain.Smtp

import at.clockwork.singleton.SystemConfigurations
import at.clockwork.transfer.gwtTransfer.client.enumeration.SmtpDomainEnum
import at.clockwork.generated.service.*

import grails.util.Holders

class UpdateScriptService {

	def smtpWriteService = Holders.grailsApplication.mainContext.getBean 'smtpWriteService'

    SystemConfigurations systemConfigurations = SystemConfigurations.getInstance()

	def run(def connection, def dataSourceFields) {

        Smtp smtp = new Smtp()

        smtp.name = "all"
        smtp.description = "all Domains"

        smtp.priority = 0
        smtp.smtpDomainEnum = SmtpDomainEnum.ALL_DOMAINS
        smtp.smtpDomain = ""

        smtp.host = systemConfigurations.getItem(3001, "strValue") ?: ""
        smtp.port = systemConfigurations.getItem(3002, "intValue") ?: 0
        smtp.auth = systemConfigurations.getItem(3003, "booleanValue") ?: false
        smtp.user = systemConfigurations.getItem(3004, "strValue") ?: ""
        smtp.password = systemConfigurations.getItem(3005, "pwValue") ?: ""
        smtp.startTlsEnable = systemConfigurations.getItem(3006, "booleanValue") ?: false
        smtp.fromEmailAddress = systemConfigurations.getItem(3007, "strValue") ?: ""

        smtp.deleted = false

        smtpWriteService.save(smtp)

		true

	}
}