{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Duckling.Url.Types where
import Control.DeepSeq
import Data.Aeson
import Data.Hashable
import Data.Maybe
import Data.Text (Text)
import GHC.Generics
import Prelude
import Duckling.Resolve (Resolve(..))
data UrlData = UrlData
{ UrlData -> Text
value :: Text
, UrlData -> Text
domain :: Text
}
deriving (UrlData -> UrlData -> Bool
(UrlData -> UrlData -> Bool)
-> (UrlData -> UrlData -> Bool) -> Eq UrlData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UrlData -> UrlData -> Bool
$c/= :: UrlData -> UrlData -> Bool
== :: UrlData -> UrlData -> Bool
$c== :: UrlData -> UrlData -> Bool
Eq, (forall x. UrlData -> Rep UrlData x)
-> (forall x. Rep UrlData x -> UrlData) -> Generic UrlData
forall x. Rep UrlData x -> UrlData
forall x. UrlData -> Rep UrlData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UrlData x -> UrlData
$cfrom :: forall x. UrlData -> Rep UrlData x
Generic, Int -> UrlData -> Int
UrlData -> Int
(Int -> UrlData -> Int) -> (UrlData -> Int) -> Hashable UrlData
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: UrlData -> Int
$chash :: UrlData -> Int
hashWithSalt :: Int -> UrlData -> Int
$chashWithSalt :: Int -> UrlData -> Int
Hashable, Eq UrlData
Eq UrlData
-> (UrlData -> UrlData -> Ordering)
-> (UrlData -> UrlData -> Bool)
-> (UrlData -> UrlData -> Bool)
-> (UrlData -> UrlData -> Bool)
-> (UrlData -> UrlData -> Bool)
-> (UrlData -> UrlData -> UrlData)
-> (UrlData -> UrlData -> UrlData)
-> Ord UrlData
UrlData -> UrlData -> Bool
UrlData -> UrlData -> Ordering
UrlData -> UrlData -> UrlData
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UrlData -> UrlData -> UrlData
$cmin :: UrlData -> UrlData -> UrlData
max :: UrlData -> UrlData -> UrlData
$cmax :: UrlData -> UrlData -> UrlData
>= :: UrlData -> UrlData -> Bool
$c>= :: UrlData -> UrlData -> Bool
> :: UrlData -> UrlData -> Bool
$c> :: UrlData -> UrlData -> Bool
<= :: UrlData -> UrlData -> Bool
$c<= :: UrlData -> UrlData -> Bool
< :: UrlData -> UrlData -> Bool
$c< :: UrlData -> UrlData -> Bool
compare :: UrlData -> UrlData -> Ordering
$ccompare :: UrlData -> UrlData -> Ordering
$cp1Ord :: Eq UrlData
Ord, Int -> UrlData -> ShowS
[UrlData] -> ShowS
UrlData -> String
(Int -> UrlData -> ShowS)
-> (UrlData -> String) -> ([UrlData] -> ShowS) -> Show UrlData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UrlData] -> ShowS
$cshowList :: [UrlData] -> ShowS
show :: UrlData -> String
$cshow :: UrlData -> String
showsPrec :: Int -> UrlData -> ShowS
$cshowsPrec :: Int -> UrlData -> ShowS
Show, UrlData -> ()
(UrlData -> ()) -> NFData UrlData
forall a. (a -> ()) -> NFData a
rnf :: UrlData -> ()
$crnf :: UrlData -> ()
NFData)
instance Resolve UrlData where
type ResolvedValue UrlData = UrlData
resolve :: Context
-> Options -> UrlData -> Maybe (ResolvedValue UrlData, Bool)
resolve Context
_ Options
_ UrlData
x = (UrlData, Bool) -> Maybe (UrlData, Bool)
forall a. a -> Maybe a
Just (UrlData
x, Bool
False)
instance ToJSON UrlData where
toJSON :: UrlData -> Value
toJSON (UrlData Text
value Text
domain) = [Pair] -> Value
object
[ Text
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
value
, Text
"domain" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
domain
, Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (Text
"value" :: Text)
]