{-# LANGUAGE FlexibleContexts #-}

module Saturn.Unstable.Type.Schedule where

import qualified Data.Text.Lazy.Builder as Builder
import qualified Saturn.Unstable.Type.Day as Day
import qualified Saturn.Unstable.Type.Hour as Hour
import qualified Saturn.Unstable.Type.Minute as Minute
import qualified Saturn.Unstable.Type.Month as Month
import qualified Saturn.Unstable.Type.Weekday as Weekday
import qualified Text.Parsec as Parsec

data Schedule = Schedule
  { Schedule -> Minute
minute :: Minute.Minute,
    Schedule -> Hour
hour :: Hour.Hour,
    Schedule -> Day
day :: Day.Day,
    Schedule -> Month
month :: Month.Month,
    Schedule -> Weekday
weekday :: Weekday.Weekday
  }
  deriving (Schedule -> Schedule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Schedule -> Schedule -> Bool
$c/= :: Schedule -> Schedule -> Bool
== :: Schedule -> Schedule -> Bool
$c== :: Schedule -> Schedule -> Bool
Eq, Int -> Schedule -> ShowS
[Schedule] -> ShowS
Schedule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Schedule] -> ShowS
$cshowList :: [Schedule] -> ShowS
show :: Schedule -> String
$cshow :: Schedule -> String
showsPrec :: Int -> Schedule -> ShowS
$cshowsPrec :: Int -> Schedule -> ShowS
Show)

parsec :: (Parsec.Stream s m Char) => Parsec.ParsecT s u m Schedule
parsec :: forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Schedule
parsec =
  Minute -> Hour -> Day -> Month -> Weekday -> Schedule
Schedule
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Minute
Minute.parsec
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
Parsec.skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
Parsec.char Char
' ')
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Hour
Hour.parsec
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
Parsec.skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
Parsec.char Char
' ')
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Day
Day.parsec
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
Parsec.skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
Parsec.char Char
' ')
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Month
Month.parsec
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
Parsec.skipMany1 (forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
Parsec.char Char
' ')
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Weekday
Weekday.parsec

toBuilder :: Schedule -> Builder.Builder
toBuilder :: Schedule -> Builder
toBuilder Schedule
schedule =
  Minute -> Builder
Minute.toBuilder (Schedule -> Minute
minute Schedule
schedule)
    forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.singleton Char
' '
    forall a. Semigroup a => a -> a -> a
<> Hour -> Builder
Hour.toBuilder (Schedule -> Hour
hour Schedule
schedule)
    forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.singleton Char
' '
    forall a. Semigroup a => a -> a -> a
<> Day -> Builder
Day.toBuilder (Schedule -> Day
day Schedule
schedule)
    forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.singleton Char
' '
    forall a. Semigroup a => a -> a -> a
<> Month -> Builder
Month.toBuilder (Schedule -> Month
month Schedule
schedule)
    forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.singleton Char
' '
    forall a. Semigroup a => a -> a -> a
<> Weekday -> Builder
Weekday.toBuilder (Schedule -> Weekday
weekday Schedule
schedule)