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

import grails.util.Holders

class UpdateScriptService {

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

	def run(def connection, def dataSourceFields) {

        GantnerPersonDayAccessSchedule2Detail.findAll().each { gantnerPersonDayAccessSchedule2Detail ->

            gantnerPersonDayAccessSchedule2Detail.identificationEnum = GantnerTimeSpanIdentificationEnum.CARD

            if (gantnerPersonDayAccessSchedule2Detail.usePinCode)
                gantnerPersonDayAccessSchedule2Detail.verificationEnum = GantnerTimeSpanVerificationEnum.PIN_CODE
            else
                gantnerPersonDayAccessSchedule2Detail.verificationEnum = GantnerTimeSpanVerificationEnum.NO

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

            gantnerPersonDayAccessSchedule2DetailWriteService.save(gantnerPersonDayAccessSchedule2Detail)

        }

		true
	}
}