import at.clockwork.access.gantner.domain.*
import at.clockwork.transfer.gwtTransfer.client.enumeration.*

import grails.util.Holders

class UpdateScriptService {

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

	def run(def connection, def dataSourceFields) {

        GantnerDoorDayAccessSchedule2Detail.findAll().each { gantnerDoorDayAccessSchedule2Detail ->

            if (gantnerDoorDayAccessSchedule2Detail.checkOnlyCompanyIdentification)
                gantnerDoorDayAccessSchedule2Detail.generalOpenModeEnum = GantnerTimeSpanGeneralOpenModeEnum.ACCESS_WITH_VALID_FID
            else if (gantnerDoorDayAccessSchedule2Detail.activeFromFirstAccess)
                gantnerDoorDayAccessSchedule2Detail.generalOpenModeEnum = GantnerTimeSpanGeneralOpenModeEnum.GENERAL_OPEN_AFTER_VALID_ACCESS
            else if (gantnerDoorDayAccessSchedule2Detail.office)
                gantnerDoorDayAccessSchedule2Detail.generalOpenModeEnum = GantnerTimeSpanGeneralOpenModeEnum.OFFICE_FUNCTION
            else if (gantnerDoorDayAccessSchedule2Detail.unlock)
                gantnerDoorDayAccessSchedule2Detail.generalOpenModeEnum = GantnerTimeSpanGeneralOpenModeEnum.GENERAL_OPEN
            else
                gantnerDoorDayAccessSchedule2Detail.generalOpenModeEnum = GantnerTimeSpanGeneralOpenModeEnum.NO

            if (gantnerDoorDayAccessSchedule2Detail.specialRelayPlan)
                gantnerDoorDayAccessSchedule2Detail.relayPlanEnum = GantnerTimeSpanRelayPlanEnum.SPECIAL_RELAY_PLAN
            else
                gantnerDoorDayAccessSchedule2Detail.relayPlanEnum = GantnerTimeSpanRelayPlanEnum.NORMAL_RELAY_PLAN

            if (gantnerDoorDayAccessSchedule2Detail.suppressTooLongOpenAlarm)
                gantnerDoorDayAccessSchedule2Detail.suppressAlarmModeEnum = GantnerTimeSpanSuppressAlarmModeEnum.BREAK_IN_ALARM
            else if (gantnerDoorDayAccessSchedule2Detail.suppressTooLongOpenAlarm)
                gantnerDoorDayAccessSchedule2Detail.suppressAlarmModeEnum = GantnerTimeSpanSuppressAlarmModeEnum.DOOR_TOO_LONG_OPEN
            else
                gantnerDoorDayAccessSchedule2Detail.suppressAlarmModeEnum = GantnerTimeSpanSuppressAlarmModeEnum.NO

            gantnerDoorDayAccessSchedule2DetailWriteService.save(gantnerDoorDayAccessSchedule2Detail)

        }

		true
	}
}