-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | This is a library for handling calendars and resource availability
--   based on the "top-nodes algorithm" and set operations.
--   
--   This is a library for handling calendars and resource availability
--   based on the "top-nodes algorithm" and set operations.
@package SCalendar
@version 1.1.0

module Time.SCalendar.Types

-- | This data type is either a TimeInterval of the form (start-date,
--   end-date) or a TimeUnit which, in this case, is a nominal day. The
--   time unit of this calendar library is a nominal day, that is, 86400
--   seconds. TimeIntervals as well as TimeUnits are stored as UTCTime so
--   that it is easy to transform results to local time or store results in
--   databases as timestamps.
data TimePeriod

-- | TimeIntervals represent the number of days that a node in a calendar
--   covers from a start-date up to an end-date.
TimeInterval :: UTCTime -> UTCTime -> TimePeriod

-- | TimeUnits are only encountered in the leaves of a calendar and
--   represent a specific day of the calendar.
TimeUnit :: UTCTime -> TimePeriod

-- | A Reservation is the product of a set of identifiers and a TimePeriod
--   over which the resources identified by the set will be reserved.
data Reservation
Reservation :: Set Text -> TimePeriod -> Reservation

-- | Set of identifiers which point to reservable resources.
[reservUnits] :: Reservation -> Set Text

-- | TimePeriod over which the resources will be reserved.
[reservPeriod] :: Reservation -> TimePeriod

-- | A Cancellation is the product of a set of identifiers which point to
--   resources previously reserved in a Calendar and a TimePeriod over
--   which those resources were reserved.
data Cancellation
Cancellation :: Set Text -> TimePeriod -> Cancellation

-- | Set of identifiers which point to resources to be cancelled.
[cancUnits] :: Cancellation -> Set Text

-- | TimePeriod over which the resources will be cancelled.
[cancPeriod] :: Cancellation -> TimePeriod

-- | An SCalendar is the product of a set of identifiers, which point to a
--   set of available resources, and a Calendar.
data SCalendar
SCalendar :: Set Text -> Calendar -> SCalendar

-- | Set of resources which can be reserved for the TimePeriod covered by
--   the root node of the Calendar.
[calUnits] :: SCalendar -> Set Text

-- | Calendar which covers the complete period of time over which a set of
--   resources can be reserved.
[calendar] :: SCalendar -> Calendar

-- | A Calendar is a recursive tree-structure whose nodes are TimePeriods
--   representing the interval of time covered by them. TimeUnits are only
--   encountered in the leaves since they represent specific days, or time
--   units, of the Calendar. The unit of time of this Calendar library is a
--   nominal day (or 86400 seconds). Each node of a Calendar also carries
--   additional data according to the "top-nodes" algorithm: a <tt>Q</tt>
--   set and a <tt>QN</tt> set. For more information about the meaning of
--   these sets visit:
--   <a>https://en.wikipedia.org/wiki/Top-nodes_algorithm</a>
data Calendar
Unit :: TimePeriod -> (Set Text) -> (Set Text) -> Calendar
Node :: TimePeriod -> (Set Text) -> (Set Text) -> Calendar -> Calendar -> Calendar

-- | A Report represents a summary of important facts related to an
--   SCalendar.
data Report
Report :: TimePeriod -> Set Text -> Set Text -> Set Text -> Report

-- | The TimePeriod which the report covers.
[reportPeriod] :: Report -> TimePeriod

-- | The set of total identifiers reservable in the SCalendar this Report
--   belongs to.
[totalUnits] :: Report -> Set Text

-- | The set of total identifiers which have been reserved in a TimePeriod
--   in the SCalendar related to this Report.
[reservedUnits] :: Report -> Set Text

-- | The set of total identifiers which are still available in a
--   Time&lt;Period in the SCalendar related to this Report.
[remainingUnits] :: Report -> Set Text

-- | Check if a time-period <tt>t1</tt> is included in a time-period
--   <tt>t2</tt>. Note that neither a TimeUnit can be included in another
--   TimeUnit nor a TimeInterval can be included in a TimeUnit. If two
--   TimeIntervals are equal they are said to be included in one another.
isIncluded :: TimePeriod -> TimePeriod -> Bool

-- | Getter function to get the UTCTime start-date from a TimePeriod. For a
--   TimeUnit the start-sate and the end-date are equal.
getFrom :: TimePeriod -> UTCTime

-- | Getter function to fet the UTCTime end-date from a TimePeriod. Again,
--   for a TimeUnit the start-sate and the end-date are equal.
getTo :: TimePeriod -> UTCTime

-- | This function transforms a TimeInterval into a TimeUnit in case that
--   the start-date and end-date of that TimeInterval are equal.
toTimeUnit :: TimePeriod -> TimePeriod

-- | Given a year, a month and a day this function creates a time period
--   which covers the specified number of days.
makeTimePeriod :: Integer -> Int -> Int -> Int -> Maybe TimePeriod

-- | Given a TimePeriod and a set of identifiers this function creates a
--   reservation.
makeReservation :: TimePeriod -> Set Text -> Maybe Reservation

-- | Given a TimePeriod and a set of identifiers this function creates a
--   cancellation.
makeCancellation :: TimePeriod -> Set Text -> Maybe Cancellation

-- | Given a year, a month, and a day this function creates a Calendar
--   which covers the specified number of days. The TimePeriod in the root
--   node of a Calendar does not exactly span the number of days specified
--   in the function, but a number of days which is a power of 2 and which
--   is greater than or equal to the number of days specified.
createCalendar :: Integer -> Int -> Int -> Int -> Maybe Calendar

-- | This constructor additionally attaches a set of identifiers, which
--   point to the available resources of the calendar. Thus, this function
--   creates an SCalendar which is basically a Calendar with a set of
--   resources which can be reserved over the period of time determined by
--   the root node of the Calendar.
createSCalendar :: Integer -> Int -> Int -> Int -> Set Text -> Maybe SCalendar
oneDay :: NominalDiffTime
powerOfTwo :: Int -> Int
instance GHC.Show.Show Time.SCalendar.Types.SCalendar
instance GHC.Classes.Eq Time.SCalendar.Types.SCalendar
instance GHC.Show.Show Time.SCalendar.Types.Calendar
instance GHC.Classes.Eq Time.SCalendar.Types.Calendar
instance GHC.Show.Show Time.SCalendar.Types.Report
instance GHC.Classes.Eq Time.SCalendar.Types.Report
instance GHC.Show.Show Time.SCalendar.Types.Cancellation
instance GHC.Classes.Eq Time.SCalendar.Types.Cancellation
instance GHC.Show.Show Time.SCalendar.Types.Reservation
instance GHC.Classes.Eq Time.SCalendar.Types.Reservation
instance GHC.Show.Show Time.SCalendar.Types.TimePeriod
instance GHC.Classes.Eq Time.SCalendar.Types.TimePeriod

module Time.SCalendar.Zippers
type CalendarZipper = (Calendar, Breadcrumbs)
goUp :: CalendarZipper -> Maybe CalendarZipper
goLeft :: CalendarZipper -> Maybe CalendarZipper
goRight :: CalendarZipper -> Maybe CalendarZipper
upToRoot :: CalendarZipper -> Maybe CalendarZipper
toZipper :: Calendar -> CalendarZipper
instance GHC.Classes.Eq Time.SCalendar.Zippers.Crumb
instance GHC.Show.Show Time.SCalendar.Zippers.Crumb

module Time.SCalendar.Internal
getInterval :: Calendar -> TimePeriod
daysBetween :: UTCTime -> UTCTime -> Int
goToNode :: TimePeriod -> Calendar -> Maybe CalendarZipper
updateQ :: CalendarZipper -> Maybe CalendarZipper
intervalFitsCalendar :: TimePeriod -> Calendar -> Bool
checkQuantAvailability :: TimePeriod -> Int -> Set Text -> CalendarZipper -> Bool
checkReservAvailability :: Reservation -> Set Text -> CalendarZipper -> Bool
updateCalendar :: [TimePeriod] -> Set Text -> Calendar -> (Set Text -> Set Text -> Maybe (Set Text)) -> Maybe Calendar
topMostNodes :: TimePeriod -> Calendar -> Maybe [CalendarZipper]
leftMostTopNode :: TimePeriod -> Calendar -> Maybe CalendarZipper
rightMostTopNode :: TimePeriod -> Calendar -> Maybe CalendarZipper
commonParent :: CalendarZipper -> CalendarZipper -> Maybe CalendarZipper
getZipInterval :: CalendarZipper -> TimePeriod
getQMax :: CalendarZipper -> Maybe (Set Text)

module Time.SCalendar.Operations

-- | Given an SCalendar of size 2^n, this function increases its size k
--   times, that is, 2^(n+k). The new SCalendar is properly updated up to
--   its root so that it will render the same results as the previous one.
--   For example, given an SCalendar <tt>c</tt> of size 2^5=32,
--   'augmentCalendar c 3' would produce a new SCalendar of size
--   2^(5+3)=256.
augmentCalendar :: SCalendar -> Int -> Maybe SCalendar

-- | Given a quantity, this function determines if it is available in a
--   TimePeriod for a specific SCalendar. Thus, it does not take into
--   account the particular resources whose availability wants to be
--   determined: it is only concerned with the availabilty of a quantity in
--   a specific SCalendar.
isQuantityAvailable :: Int -> TimePeriod -> SCalendar -> Bool

-- | Given a Reservation, this function determines if it is available in a
--   SCalendar. A Reservation is the product of a set of identifiers which
--   point to reservable resources and a TimePeriod over which those
--   resources are to be reserved. Thus, this function checks if that
--   particular set of resources is available for a TimePeriod in the given
--   SCalendar.
isReservAvailable :: Reservation -> SCalendar -> Bool

-- | This function introduces a new Reservation in a Calendar. Note that
--   since no availability check is performed before introducing the
--   Reservation, here we use a plain Calendar. Thus this function is
--   useful to introduce Reservations without any constraint, but that's
--   why it must be used carefully since information can be lost due to the
--   usage of the union set-operation to update the Q and QN sets in the
--   Calendar.
reservePeriod' :: Reservation -> Calendar -> Maybe Calendar

-- | This function introduces a new Reservation in a SCalendar applying an
--   availability check. This means that if the reservation conflicts with
--   others already made in the SCalendar, it will no be introduced. Thus
--   this function takes into account the set of reservable identifiers for
--   the SCalendar to calculate the subset of available ones and introduce
--   the Reservation if possible.
reservePeriod :: Reservation -> SCalendar -> Maybe SCalendar

-- | This function is like reservePeriod but introduces several
--   Reservations at once. It is important to note that if a Reservation in
--   the list conflicts with others already made in the SCalendar, it will
--   be excluded. Thus the order of the Reservations in the list matters,
--   since if one Reservation passes the availability check but the next
--   one does not, then latter will be excluded.
reserveManyPeriods :: [Reservation] -> SCalendar -> Maybe SCalendar

-- | This function is like reservePeriod' but adds a list of Reservations
--   without any availabilty check.
reserveManyPeriods' :: [Reservation] -> Calendar -> Maybe Calendar

-- | This function removes reserved identifiers in a Calendar according to
--   the Set of identifiers and TimePeriod specified in the Cancellation.
--   Thus a Cancellation only affects the nodes whose upper or lower bounds
--   are included in the TimePeriod of the Cancellation.
cancelPeriod :: Cancellation -> Calendar -> Maybe Calendar

-- | This is like cancelPeriod but performs several Cancellations at once.
cancelManyPeriods :: [Cancellation] -> Calendar -> Maybe Calendar

-- | Given a TimePeriod and a SCalendar, this function returns a Report
--   which summarizes important data about the reserved and available
--   identifiers in that SCalendar.
periodReport :: TimePeriod -> SCalendar -> Maybe Report
