{-# LANGUAGE TemplateHaskell #-}

module Network.Courriel.Types where

import           Data.ByteString (ByteString)
import           Data.Sequence (Seq)
import           Data.Time.Clock (UTCTime)
import           Lens.Micro.Platform (makeLenses)

data Address = Address
  { _addrLocalPart :: ByteString
  , _addrDomain    :: ByteString
  } deriving (Eq, Show, Read)

data Mailbox = Mailbox
  { _mbName :: Maybe ByteString
  , _mbAddr :: Address
  } deriving (Eq, Show, Read)

data MBGroup
  = MBSingle Mailbox
  | MBGroup ByteString (Seq Mailbox)
    deriving (Eq, Show, Read)

data Header
  = HeaderOrigDate UTCTime
  | HeaderFrom (Seq Mailbox)
  | HeaderSender Mailbox
  | HeaderReplyTo (Seq MBGroup)
  | HeaderTo (Seq MBGroup)
  | HeaderCc (Seq MBGroup)
  | HeaderBcc (Seq MBGroup)
  | HeaderMessageId MessageId
  | HeaderInReplyTo (Seq MessageId)
  | HeaderReferences (Seq MessageId)
  | HeaderSubject ByteString
  | HeaderComments ByteString
  | HeaderKeywords ByteString
  | HeaderOther ByteString ByteString
    deriving (Eq, Show, Read)

newtype MessageId = MessageId { _fromMessageId :: ByteString }
  deriving (Eq, Show, Read)

data Body = Body { _fromBody :: ByteString }
  deriving (Eq, Show, Read)

data RawEmail = RawEmail
  { _rawEmailHeaders :: Seq Header
  , _rawEmailBodies  :: Seq Body
  } deriving (Eq, Show, Read)

data Email = Email
  { _emailFilename :: FilePath
  , _emailFrom     :: Address
  , _emailTo       :: Seq Address
  , _emailCc       :: Seq Address
  , _emailBcc      :: Seq Address
  , _emailHeaders  :: Seq Header
  , _emailBodies   :: Seq Body
  } deriving (Eq, Show, Read)

makeLenses ''Address
makeLenses ''Mailbox
makeLenses ''MessageId
makeLenses ''Body
makeLenses ''Email
