{-# LANGUAGE KindSignatures #-}

module Scrappy.Types where

-- may change Types + Links -> Navigation + Something else 



-- import Network.HTTP.Client (CookieJar, requestBody, method, destroyCookieJar, responseCookieJar, httpLbs, RequestBody (RequestBodyBS, RequestBodyLBS), parseRequest, newManager, responseBody, Manager)
import Control.Concurrent (ThreadId)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.State.Lazy (StateT)
--import Data.Time.Clock.System
import Data.Text (Text)

import Text.Parsec (ParsecT, parserZero)
--import Witherable


-- -- | Upgrade an error to discard parser 
-- instance Filterable (ParsecT s u f) where
--   mapMaybe f ma = do
--     x <- ma
--     case f x of
--       Just a -> return a 
--       Nothing -> parserZero



mapMaybe :: (a -> Maybe b) -> ParsecT s u m a -> ParsecT s u m b
mapMaybe :: forall a b s u (m :: * -> *).
(a -> Maybe b) -> ParsecT s u m a -> ParsecT s u m b
mapMaybe a -> Maybe b
f ParsecT s u m a
ma = do
  a
x <- ParsecT s u m a
ma
  case a -> Maybe b
f a
x of
    Just b
a -> b -> ParsecT s u m b
forall a. a -> ParsecT s u m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
a
    Maybe b
Nothing -> ParsecT s u m b
forall s u (m :: * -> *) a. ParsecT s u m a
parserZero



data ScrapeFail = Eof | NonMatch deriving Int -> ScrapeFail -> ShowS
[ScrapeFail] -> ShowS
ScrapeFail -> String
(Int -> ScrapeFail -> ShowS)
-> (ScrapeFail -> String)
-> ([ScrapeFail] -> ShowS)
-> Show ScrapeFail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScrapeFail -> ShowS
showsPrec :: Int -> ScrapeFail -> ShowS
$cshow :: ScrapeFail -> String
show :: ScrapeFail -> String
$cshowList :: [ScrapeFail] -> ShowS
showList :: [ScrapeFail] -> ShowS
Show

-- | Note: both elemParser and treeElemParser are capable of doing greedy or non-greedy matching
  --treeElemParser (unless its really slow) should be better for non-greedy/focused
  --elemParser should be better for greedy



-- eitherP :: Alternative m => m a -> m b -> m (Either a b)
-- eitherP a b = (Left <$> a) <|> (Right <$> b)



  

-- IO for requests
-- Either for high level important errors
-- Maybe for Naive scraping logic 


-- State looking important for managing status of each site as well
-- as scrape coin 

-- |  data Processor a b = Processor ThreadId { runFunc :: (a -> b) }
type Html = String -- or could be just the pdf, but maybe even URL for storage sake --> could become research graph
                   -- but in a sense, would be a forest of uncited (yet) publicationsop