{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators      #-}

module UseHaskellAPIClient where

import           Data.Proxy
import           Servant.API
import           Servant.Client
import           UseHaskellAPI

restLoginAPI :: Proxy LoginAPI
restLoginAPI = Proxy

restLockingAPI :: Proxy LockingAPI
restLockingAPI = Proxy

restFileAPI :: Proxy FileAPI
restFileAPI = Proxy

restDirAPI :: Proxy DirAPI
restDirAPI = Proxy

restTAPI :: Proxy TAPI
restTAPI = Proxy

login :: Message -> ClientM [ResponseData]
signup :: Message -> ClientM ResponseData

lock :: Message -> ClientM Bool
unlock :: Message -> ClientM Bool
islocked :: Message -> ClientM Bool

download :: Message -> ClientM [Message]
upload :: StrWrap3 -> ClientM Bool

pushFile :: StrWrap3 -> ClientM [FileMapping]
pullFile :: StrWrap3 -> ClientM [FileMapping]
directories :: StrWrap1 -> ClientM [DirFiles]
dirFiles :: Message -> ClientM [DirFiles]

commitConfirmation :: Message -> ClientM Bool
newTransaction :: StrWrap1 -> ClientM ResponseData
addFile :: Tref -> ClientM Bool
abortTransaction :: Message -> ClientM Bool
commitTransaction :: Message -> ClientM Bool


-- | The following provides the implementations of these types
-- Note that the order of the functions must match the endpoints in the type API from UseHaskell.hs

(login :<|> signup) = client restLoginAPI
(lock :<|> unlock :<|> islocked) = client restLockingAPI
(download :<|> upload) = client restFileAPI
(pushFile :<|> pullFile :<|> directories :<|> dirFiles) = client restDirAPI
(commitConfirmation :<|> newTransaction :<|> addFile :<|> abortTransaction :<|> commitTransaction) = client restTAPI
