{-# LANGUAGE OverloadedStrings, ConstraintKinds, FlexibleContexts, TemplateHaskell #-}

module TelemetryTypes where

import Data.Time.Clock
import Data.Time.LocalTime
import Data.Time.Calendar
import Data.Text
import Data.Map
import Data.Functor.Identity
import Control.Monad.Reader
import Control.Lens

-- General Types

type TelemetryMonad m = (MonadReader TelemetryConfig m)

data Notifier = Notifier
    {
        _notifierName :: Text,
        _notifierCommands :: (Text, Text)
    } deriving (Eq, Show)


newtype TelemetryConfig = TelemetryConfig {
        _tcNotifiers :: [Notifier]
    } deriving (Eq, Show)

makeLenses ''Notifier
makeLenses ''TelemetryConfig

-- Parser Types

data TelemetryCommand = TelemetryStart | TelemetryStop
    deriving (Eq, Show)

newtype TelemetryColumn = TelemetryColumn Int
    deriving (Eq, Show)

data TelemetryRecord = TelemetryRecord Notifier TelemetryCommand TimeOfDay
    deriving (Eq, Show)

data TelemetryBlock = TelemetryBlock Day [(Maybe TelemetryRecord, Maybe TelemetryRecord)]
    deriving (Eq, Show)

newtype TelemetryLog = TelemetryLog [TelemetryBlock]
    deriving (Eq, Show)

type TelemetrySource = Text
type TelemetryState = TelemetryParserState

data TelemetryParserState = TelemetryParserState{
        _tpsNotifiers :: (Maybe Notifier, Maybe Notifier),
        _tpsCurrentColumn :: Int
    } deriving (Eq, Show)

makeLenses ''TelemetryParserState

emptyTPS :: TelemetryParserState
emptyTPS = TelemetryParserState (Nothing, Nothing) 1

--Analyzer Types
instance Ord Notifier where
    compare l r = compare (l^.notifierName) (r^.notifierName)

newtype AlarmInterval = AlarmInterval (UTCTime, UTCTime)
    deriving (Eq, Show)

type TelemetryReport = Map Notifier [AlarmInterval]