module Utils.Schedule.Types.ScheduleOffset
  ( ScheduleOffset(..)
  , addOffset, offsetInDays
  ) where

import Import.NoModel


data ScheduleOffset = ScheduleOffsetNone
                    | ScheduleOffsetDays Int
  deriving (Eq, Ord, Show, Read, Generic, Typeable)

derivePathPiece ''ScheduleOffset (camelToPathPiece' 1) "_"


-- | Join two ScheduleOffsets by addition
addOffset :: ScheduleOffset -> ScheduleOffset -> ScheduleOffset
addOffset ScheduleOffsetNone offset = offset
addOffset offset ScheduleOffsetNone = offset
addOffset (ScheduleOffsetDays d) (ScheduleOffsetDays d') = ScheduleOffsetDays $ d + d'

-- | Calculate number of offset days from ScheduleOffset
offsetInDays :: ScheduleOffset -> Int
offsetInDays  ScheduleOffsetNone    = 0
offsetInDays (ScheduleOffsetDays d) = d
