import at.clockwork.system.domain.*
import at.clockwork.transfer.gwtTransfer.client.enumeration.*

import grails.util.Holders

class UpdateScriptService {

    /*
        HookScript VALIDATE_TIME_ATTENDANCE_* wurde geaendert
        -----------------------------------------------------

        VALIDATE_TIME_ATTENDANCE_1
        Aufruf vom HookScript:
        persons = scriptService.executeScript( hookScript, persons, startDate, endDate )

        VALIDATE_TIME_ATTENDANCE_99
        Aufruf vom HookScript:
        errors = scriptService.executeScript( hookScript, errors, persons, startDate, endDate )

    */

	def scriptNotTransactionalService = Holders.grailsApplication.mainContext.getBean 'scriptNotTransactionalService'
	def informationTransactionalService = Holders.grailsApplication.mainContext.getBean 'informationTransactionalService'

	def run(def connection, def dataSourceFields) {

        List hookTypeEnums = [
            HookTypeEnum.VALIDATE_TIME_ATTENDANCE_1,
            HookTypeEnum.VALIDATE_TIME_ATTENDANCE_99
        ]

        HookScript.findAllWhere(deleted:false).each { HookScript itHookScript ->

            if ( hookTypeEnums.any{ it == itHookScript.hookTypeEnum } ) {
                informationTransactionalService.add( "name=${itHookScript.name}, desc=${itHookScript.description}, enum=${itHookScript.hookTypeEnum}", new Date(), "VALIDATE_TIME_ATTENDANCE: startTimeStamp / endTimeStamp" )
            }

		}

		true

	}

}