import at.clockwork.system.domain.*

import at.clockwork.transfer.gwtTransfer.client.enumeration.DatafoxOutputEnum
import at.clockwork.terminal.datafox.domain.*

import grails.util.Holders

class UpdateScriptService {

//	def terminalDatafox2ActionWriteService = Holders.grailsApplication.mainContext.getBean 'terminalDatafox2ActionWriteService'

	def run(def connection, def dataSourceFields) {

/*
        TerminalDatafox2Action.findAllWhere(deleted:false).each { TerminalDatafox2Action terminalDatafox2Action ->

            switch(terminalDatafox2Action.portOut) {
                case 1:
                    terminalDatafox2Action.outputEnum = DatafoxOutputEnum.BASE_RELAIS_1
                    break

                case 3:
                    terminalDatafox2Action.outputEnum = DatafoxOutputEnum.BASE_RELAIS_2
                    break

                case -101:
                    terminalDatafox2Action.outputEnum = DatafoxOutputEnum.UuZ
                    break

                default:
                    terminalDatafox2Action.outputEnum = DatafoxOutputEnum.BASE_RELAIS_4
                    break

            }

            terminalDatafox2ActionWriteService.save(terminalDatafox2Action)

        }
*/

        at.clockwork.system.service.DataSourceService.execute(
            connection,
            dataSourceFields,
            [
                mySQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'BASE_RELAIS_1' where port_out = 1",
                msSQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'BASE_RELAIS_1' where port_out = 1"
            ]
        )

        at.clockwork.system.service.DataSourceService.execute(
            connection,
            dataSourceFields,
            [
                mySQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'BASE_RELAIS_2' where port_out = 3",
                msSQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'BASE_RELAIS_2' where port_out = 3"
            ]
        )

        at.clockwork.system.service.DataSourceService.execute(
            connection,
            dataSourceFields,
            [
                mySQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'UuZ' where port_out = -101",
                msSQLStatement:"update cw_terminal_datafox_2_action set output_enum = 'UuZ' where port_out = -101"
            ]
        )

		true

	}
}