module WykopLinks (
      promotedLinks
    , promotedLinks'
    , upcomingLinks
    , upcomingLinks'
    , PSort(..)
    , USort(..)
    , module WykopTypes
) where

import WykopTypes
import WykopUtils hiding (toGet)

data PSort = Day | Week | Month

instance Show PSort where
    show Day = "day"
    show Week = "week"
    show Month = "month"

promotedLinks :: Keys -> Int -> PSort -> IO (Maybe [Link])
promotedLinks k p s = get k [] (toGet p s) "links/promoted"

promotedLinks' :: Keys -> IO (Maybe [Link])
promotedLinks' k = promotedLinks k 1 Day

data USort = UDate | UVotes | UComments

instance Show USort where
    show UDate = "date"
    show UVotes = "votes"
    show UComments = "comments"

upcomingLinks :: Keys -> Int -> USort -> IO (Maybe [Link])
upcomingLinks k p s = get k [] (toGet p s) "links/upcoming"

upcomingLinks' :: Keys -> IO (Maybe [Link])
upcomingLinks' k = upcomingLinks k 1 UVotes

toGet :: (Show a) => Int -> a -> GetData
toGet p s = [("page", show p), ("sort", show s)]
