module Web.Eved.UrlElement
    where

import           Data.Text       (Text)
import qualified Web.HttpApiData as HttpApiData

data UrlElement a = UrlElement
    { UrlElement a -> Text -> Either Text a
fromUrlPiece :: Text -> Either Text a
    , UrlElement a -> a -> Text
toUrlPiece   :: a -> Text
    }

auto :: (HttpApiData.FromHttpApiData a, HttpApiData.ToHttpApiData a, Applicative f) => f (UrlElement a)
auto :: f (UrlElement a)
auto = UrlElement a -> f (UrlElement a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UrlElement a -> f (UrlElement a))
-> UrlElement a -> f (UrlElement a)
forall a b. (a -> b) -> a -> b
$ UrlElement :: forall a. (Text -> Either Text a) -> (a -> Text) -> UrlElement a
UrlElement
    { fromUrlPiece :: Text -> Either Text a
fromUrlPiece = Text -> Either Text a
forall a. FromHttpApiData a => Text -> Either Text a
HttpApiData.parseUrlPiece
    , toUrlPiece :: a -> Text
toUrlPiece = a -> Text
forall a. ToHttpApiData a => a -> Text
HttpApiData.toUrlPiece
    }

integer :: Applicative f => f (UrlElement Integer)
integer :: f (UrlElement Integer)
integer = f (UrlElement Integer)
forall a (f :: * -> *).
(FromHttpApiData a, ToHttpApiData a, Applicative f) =>
f (UrlElement a)
auto

text :: Applicative f => f (UrlElement Text)
text :: f (UrlElement Text)
text = f (UrlElement Text)
forall a (f :: * -> *).
(FromHttpApiData a, ToHttpApiData a, Applicative f) =>
f (UrlElement a)
auto