module TD.Query.GetCountry
  (GetCountry(..)
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T

-- | Returns information about an existing country. Can be called before authorization. Returns 'TD.Data.CountryInfo.CountryInfo'
data GetCountry
  = GetCountry
    { GetCountry -> Maybe Text
country_code :: Maybe T.Text -- ^ A two-letter ISO 3166-1 alpha-2 country code
    }
  deriving (GetCountry -> GetCountry -> Bool
(GetCountry -> GetCountry -> Bool)
-> (GetCountry -> GetCountry -> Bool) -> Eq GetCountry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCountry -> GetCountry -> Bool
== :: GetCountry -> GetCountry -> Bool
$c/= :: GetCountry -> GetCountry -> Bool
/= :: GetCountry -> GetCountry -> Bool
Eq, Int -> GetCountry -> ShowS
[GetCountry] -> ShowS
GetCountry -> String
(Int -> GetCountry -> ShowS)
-> (GetCountry -> String)
-> ([GetCountry] -> ShowS)
-> Show GetCountry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCountry -> ShowS
showsPrec :: Int -> GetCountry -> ShowS
$cshow :: GetCountry -> String
show :: GetCountry -> String
$cshowList :: [GetCountry] -> ShowS
showList :: [GetCountry] -> ShowS
Show)

instance I.ShortShow GetCountry where
  shortShow :: GetCountry -> String
shortShow
    GetCountry
      { country_code :: GetCountry -> Maybe Text
country_code = Maybe Text
country_code_
      }
        = String
"GetCountry"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"country_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
country_code_
          ]

instance AT.ToJSON GetCountry where
  toJSON :: GetCountry -> Value
toJSON
    GetCountry
      { country_code :: GetCountry -> Maybe Text
country_code = Maybe Text
country_code_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type"        Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"getCountry"
          , Key
"country_code" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
country_code_
          ]