{-# LANGUAGE LambdaCase #-}

module WykopProfile (
      indexProfile
    , addedProfile
    , publishedProfile
    , commentedProfile
    , diggedProfile
    , buriedProfile
    , observeProfile
    , unobserveProfile
    , blockProfile
    , unblockProfile
    , followersProfile
    , followedProfile
    , favoritesProfile
    , module WykopTypes
    ) where

import WykopTypes
import WykopUtils

indexProfile :: Keys -> String -> IO (Maybe Profile)
indexProfile k login = get k [] [] res
    where
        res = "profile/index/" ++ login

addedProfile :: Keys -> String -> Maybe Int -> IO (Maybe [Link])
addedProfile k login page = get k [] (mPageToGet page) res
    where
        res = "profile/added/" ++ login

publishedProfile :: Keys -> String -> Maybe Int -> IO (Maybe [Link])
publishedProfile k login page = get k [] (mPageToGet page) res
    where
        res = "profile/published/" ++ login

commentedProfile :: Keys -> String -> Maybe Int -> IO (Maybe [Link])
commentedProfile k login page = get k [] (mPageToGet page) res
    where
        res = "profile/commented/" ++ login

diggedProfile :: Keys -> String -> Maybe Int -> IO (Maybe [Link])
diggedProfile k login page = get k [] (mPageToGet page) res
    where
        res = "profile/digged/" ++ login

buriedProfile :: Keys -> String -> Userkey -> Maybe Int -> IO (Maybe [Link])
buriedProfile k login userKey page = get k [] getData res
    where
        getData = (mPageToGet page) ++ (toGet userKey)
        res = "profile/buried/" ++ login

observeProfile :: Keys -> String -> Userkey -> IO (Maybe [Bool])
observeProfile k login userKey = get k [] (toGet userKey) res
    where
        res = "profile/observe/" ++ login

unobserveProfile :: Keys -> String -> Userkey -> IO (Maybe [Bool])
unobserveProfile k login userKey = get k [] (toGet userKey) res
    where
        res = "profile/unobserve/" ++ login

blockProfile :: Keys -> String -> Userkey -> IO (Maybe [Bool])
blockProfile k login userKey = get k [] (toGet userKey) res
    where
        res = "profile/block/" ++ login

unblockProfile :: Keys -> String -> Userkey -> IO (Maybe [Bool])
unblockProfile k login userKey = get k [] (toGet userKey) res
    where
        res = "profile/unblock/" ++ login

followersProfile :: Keys -> String -> Maybe Userkey -> Maybe Int -> IO (Maybe [Profile])
followersProfile k login userKey page = get k [] getData res
    where
        getData = (mPageToGet page) ++ (mToGet userKey)
        res = "profile/followers/" ++ login

followedProfile :: Keys -> String -> Maybe Userkey -> Maybe Int -> IO (Maybe [Profile])
followedProfile k login userKey page = get k [] getData res
    where
        getData = (mPageToGet page) ++ (mToGet userKey)
        res = "profile/followed/" ++ login

favoritesProfile :: Keys -> String -> Maybe Int -> Maybe Int -> IO (Maybe [Link])
favoritesProfile k login id page = get k [] (mPageToGet page) res
    where
        res = "profile/favorites/" ++ login ++ idToURL
        idToURL = case id of
            Just x -> "/" ++ show x
            _      -> ""
