-- | A globally unique identifier
module Asana.Api.Gid
  ( Gid,
    AsanaReference (..),
    gidToText,
    textToGid,
  )
where

import Asana.Api.Prelude
import Data.Aeson
  ( FromJSON (..),
    FromJSONKey,
    ToJSON,
    ToJSONKey,
    genericParseJSON,
  )
import Data.Aeson.Casing (aesonPrefix, snakeCase)
import Data.Hashable (Hashable)

newtype Gid = Gid {Gid -> Text
gidToText :: Text}
  deriving stock (Gid -> Gid -> Bool
(Gid -> Gid -> Bool) -> (Gid -> Gid -> Bool) -> Eq Gid
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Gid -> Gid -> Bool
== :: Gid -> Gid -> Bool
$c/= :: Gid -> Gid -> Bool
/= :: Gid -> Gid -> Bool
Eq, (forall x. Gid -> Rep Gid x)
-> (forall x. Rep Gid x -> Gid) -> Generic Gid
forall x. Rep Gid x -> Gid
forall x. Gid -> Rep Gid x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Gid -> Rep Gid x
from :: forall x. Gid -> Rep Gid x
$cto :: forall x. Rep Gid x -> Gid
to :: forall x. Rep Gid x -> Gid
Generic, Int -> Gid -> ShowS
[Gid] -> ShowS
Gid -> String
(Int -> Gid -> ShowS)
-> (Gid -> String) -> ([Gid] -> ShowS) -> Show Gid
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Gid -> ShowS
showsPrec :: Int -> Gid -> ShowS
$cshow :: Gid -> String
show :: Gid -> String
$cshowList :: [Gid] -> ShowS
showList :: [Gid] -> ShowS
Show)
  deriving newtype (Maybe Gid
Value -> Parser [Gid]
Value -> Parser Gid
(Value -> Parser Gid)
-> (Value -> Parser [Gid]) -> Maybe Gid -> FromJSON Gid
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Gid
parseJSON :: Value -> Parser Gid
$cparseJSONList :: Value -> Parser [Gid]
parseJSONList :: Value -> Parser [Gid]
$comittedField :: Maybe Gid
omittedField :: Maybe Gid
FromJSON, [Gid] -> Value
[Gid] -> Encoding
Gid -> Bool
Gid -> Value
Gid -> Encoding
(Gid -> Value)
-> (Gid -> Encoding)
-> ([Gid] -> Value)
-> ([Gid] -> Encoding)
-> (Gid -> Bool)
-> ToJSON Gid
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Gid -> Value
toJSON :: Gid -> Value
$ctoEncoding :: Gid -> Encoding
toEncoding :: Gid -> Encoding
$ctoJSONList :: [Gid] -> Value
toJSONList :: [Gid] -> Value
$ctoEncodingList :: [Gid] -> Encoding
toEncodingList :: [Gid] -> Encoding
$comitField :: Gid -> Bool
omitField :: Gid -> Bool
ToJSON, ToJSONKeyFunction [Gid]
ToJSONKeyFunction Gid
ToJSONKeyFunction Gid -> ToJSONKeyFunction [Gid] -> ToJSONKey Gid
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
$ctoJSONKey :: ToJSONKeyFunction Gid
toJSONKey :: ToJSONKeyFunction Gid
$ctoJSONKeyList :: ToJSONKeyFunction [Gid]
toJSONKeyList :: ToJSONKeyFunction [Gid]
ToJSONKey, FromJSONKeyFunction [Gid]
FromJSONKeyFunction Gid
FromJSONKeyFunction Gid
-> FromJSONKeyFunction [Gid] -> FromJSONKey Gid
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
$cfromJSONKey :: FromJSONKeyFunction Gid
fromJSONKey :: FromJSONKeyFunction Gid
$cfromJSONKeyList :: FromJSONKeyFunction [Gid]
fromJSONKeyList :: FromJSONKeyFunction [Gid]
FromJSONKey, Eq Gid
Eq Gid => (Int -> Gid -> Int) -> (Gid -> Int) -> Hashable Gid
Int -> Gid -> Int
Gid -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> Gid -> Int
hashWithSalt :: Int -> Gid -> Int
$chash :: Gid -> Int
hash :: Gid -> Int
Hashable)

-- | An object @{ gid: <Gid> }@
newtype AsanaReference = AsanaReference {AsanaReference -> Gid
arGid :: Gid}
  deriving stock (AsanaReference -> AsanaReference -> Bool
(AsanaReference -> AsanaReference -> Bool)
-> (AsanaReference -> AsanaReference -> Bool) -> Eq AsanaReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AsanaReference -> AsanaReference -> Bool
== :: AsanaReference -> AsanaReference -> Bool
$c/= :: AsanaReference -> AsanaReference -> Bool
/= :: AsanaReference -> AsanaReference -> Bool
Eq, (forall x. AsanaReference -> Rep AsanaReference x)
-> (forall x. Rep AsanaReference x -> AsanaReference)
-> Generic AsanaReference
forall x. Rep AsanaReference x -> AsanaReference
forall x. AsanaReference -> Rep AsanaReference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AsanaReference -> Rep AsanaReference x
from :: forall x. AsanaReference -> Rep AsanaReference x
$cto :: forall x. Rep AsanaReference x -> AsanaReference
to :: forall x. Rep AsanaReference x -> AsanaReference
Generic, Int -> AsanaReference -> ShowS
[AsanaReference] -> ShowS
AsanaReference -> String
(Int -> AsanaReference -> ShowS)
-> (AsanaReference -> String)
-> ([AsanaReference] -> ShowS)
-> Show AsanaReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AsanaReference -> ShowS
showsPrec :: Int -> AsanaReference -> ShowS
$cshow :: AsanaReference -> String
show :: AsanaReference -> String
$cshowList :: [AsanaReference] -> ShowS
showList :: [AsanaReference] -> ShowS
Show)

instance FromJSON AsanaReference where
  parseJSON :: Value -> Parser AsanaReference
parseJSON = Options -> Value -> Parser AsanaReference
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser AsanaReference)
-> Options -> Value -> Parser AsanaReference
forall a b. (a -> b) -> a -> b
$ ShowS -> Options
aesonPrefix ShowS
snakeCase

textToGid :: Text -> Gid
textToGid :: Text -> Gid
textToGid = Text -> Gid
Gid