{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- | This module exports orphan instances to make
-- [@servant-queryparam-core@](https://hackage.haskell.org/package/servant-queryparam-core) work with clients.
module Servant.Client.Record () where

import Data.Kind
import Data.Proxy
import GHC.Generics
import GHC.TypeLits
import Servant.API
import Servant.Client.Core.HasClient
import Servant.Client.Core.Request
import Servant.Client.Core.RunClient
import Servant.Record
import Servant.TypeLevel

instance
  ( RunClient m,
    Generic a,
    GHasClient mod m (Rep a) api
  ) =>
  HasClient m (RecordParam mod a :> api)
  where
  type Client m (RecordParam mod a :> api) = a -> Client m api
  clientWithRoute :: Proxy m
-> Proxy (RecordParam mod a :> api)
-> Request
-> Client m (RecordParam mod a :> api)
clientWithRoute Proxy m
pm Proxy (RecordParam mod a :> api)
Proxy Request
req a
record =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api.
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> a () -> Client m api
gClientWithRoute (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api) Request
req (forall a x. Generic a => a -> Rep a x
from a
record :: Rep a ())
  {-# INLINE clientWithRoute #-}
  hoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
Proxy m
-> Proxy (RecordParam mod a :> api)
-> (forall x. mon x -> mon' x)
-> Client mon (RecordParam mod a :> api)
-> Client mon' (RecordParam mod a :> api)
hoistClientMonad Proxy m
pm Proxy (RecordParam mod a :> api)
Proxy forall x. mon x -> mon' x
f Client mon (RecordParam mod a :> api)
cl a
as =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api (mon :: * -> *) (mon' :: * -> *).
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (a () -> Client mon api)
-> a ()
-> Client mon' api
gHoistClientMonad
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod)
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy api)
      forall x. mon x -> mon' x
f
      (Client mon (RecordParam mod a :> api)
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => Rep a x -> a
to)
      (forall a x. Generic a => a -> Rep a x
from a
as :: Rep a ())
  {-# INLINE hoistClientMonad #-}

data GParam (mod :: Symbol -> Exp Symbol) a

class GHasClient (mod :: Symbol -> Exp Symbol) m (a :: Type -> Type) api where
  gClientWithRoute ::
    RunClient m =>
    Proxy mod ->
    Proxy m ->
    Proxy api ->
    Request ->
    a () ->
    Client m api
  gHoistClientMonad ::
    RunClient m =>
    Proxy mod ->
    Proxy m ->
    Proxy api ->
    (forall x. mon x -> mon' x) ->
    (a () -> Client mon api) ->
    (a () -> Client mon' api)

instance
  ( RunClient m,
    GHasClient mod m a api
  ) =>
  HasClient m (GParam mod (a ()) :> api)
  where
  type Client m (GParam mod (a ()) :> api) = a () -> Client m api
  clientWithRoute :: Proxy m
-> Proxy (GParam mod (a ()) :> api)
-> Request
-> Client m (GParam mod (a ()) :> api)
clientWithRoute Proxy m
pm Proxy (GParam mod (a ()) :> api)
_ = forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api.
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> a () -> Client m api
gClientWithRoute (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api)
  {-# INLINE clientWithRoute #-}
  hoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
Proxy m
-> Proxy (GParam mod (a ()) :> api)
-> (forall x. mon x -> mon' x)
-> Client mon (GParam mod (a ()) :> api)
-> Client mon' (GParam mod (a ()) :> api)
hoistClientMonad Proxy m
pm Proxy (GParam mod (a ()) :> api)
_ = forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api (mon :: * -> *) (mon' :: * -> *).
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (a () -> Client mon api)
-> a ()
-> Client mon' api
gHoistClientMonad (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api)
  {-# INLINE hoistClientMonad #-}

instance
  GHasClient mod m c api =>
  GHasClient mod m (D1 m3 c) api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> D1 m3 c () -> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 c ()
x) =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api.
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> a () -> Client m api
gClientWithRoute (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api) Request
req c ()
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (D1 m3 c () -> Client mon api)
-> D1 m3 c ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
Proxy forall x. mon x -> mon' x
f D1 m3 c () -> Client mon api
cl D1 m3 c ()
x =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api (mon :: * -> *) (mon' :: * -> *).
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (a () -> Client mon api)
-> a ()
-> Client mon' api
gHoistClientMonad (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api) forall x. mon x -> mon' x
f (D1 m3 c () -> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1) (forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1 D1 m3 c ()
x)
  {-# INLINE gHoistClientMonad #-}

instance
  GHasClient mod m a (GParam mod (b ()) :> api) =>
  GHasClient mod m (a :*: b) api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> (:*:) a b () -> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (a ()
x :*: b ()
y) =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api.
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> a () -> Client m api
gClientWithRoute (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy (GParam mod (b ()) :> api)) Request
req a ()
x b ()
y
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> ((:*:) a b () -> Client mon api)
-> (:*:) a b ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
Proxy forall x. mon x -> mon' x
f (:*:) a b () -> Client mon api
cl (a ()
x :*: b ()
y) =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api (mon :: * -> *) (mon' :: * -> *).
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (a () -> Client mon api)
-> a ()
-> Client mon' api
gHoistClientMonad
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod)
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (GParam mod (b ()) :> api))
      forall x. mon x -> mon' x
f
      (\a ()
x' b ()
y' -> (:*:) a b () -> Client mon api
cl (a ()
x' forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: b ()
y'))
      a ()
x
      b ()
y
  {-# INLINE gHoistClientMonad #-}

instance GHasClient mod m a api => GHasClient mod m (C1 mon a) api where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> C1 mon a () -> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 a ()
x) =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api.
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m -> Proxy api -> Request -> a () -> Client m api
gClientWithRoute (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api) Request
req a ()
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (C1 mon a () -> Client mon api)
-> C1 mon a ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
_ forall x. mon x -> mon' x
f C1 mon a () -> Client mon api
cl (M1 a ()
x) =
    forall (mod :: Symbol -> Exp Symbol) (m :: * -> *) (a :: * -> *)
       api (mon :: * -> *) (mon' :: * -> *).
(GHasClient mod m a api, RunClient m) =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (a () -> Client mon api)
-> a ()
-> Client mon' api
gHoistClientMonad (forall {k} (t :: k). Proxy t
Proxy :: Proxy mod) Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy api) forall x. mon x -> mon' x
f (C1 mon a () -> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1) a ()
x
  {-# INLINE gHoistClientMonad #-}

instance
  {-# OVERLAPPING #-}
  ( HasClient m api,
    KnownSymbol sym,
    KnownSymbol (Eval (mod sym))
  ) =>
  GHasClient mod m (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool)) api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> Request
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) ()
-> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 (K1 Bool
x)) =
    forall (m :: * -> *) api.
HasClient m api =>
Proxy m -> Proxy api -> Request -> Client m api
clientWithRoute Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryFlag (Eval (mod sym)) :> api)) Request
req Bool
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) ()
    -> Client mon api)
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
_ forall x. mon x -> mon' x
f S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) () -> Client mon api
cl (M1 (K1 Bool
x)) =
    forall (m :: * -> *) api (mon :: * -> *) (mon' :: * -> *).
HasClient m api =>
Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> Client mon api
-> Client mon' api
hoistClientMonad
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryFlag (Eval (mod sym)) :> api))
      forall x. mon x -> mon' x
f
      (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 Bool) () -> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). c -> K1 i c p
K1)
      Bool
x
  {-# INLINE gHoistClientMonad #-}

instance
  {-# OVERLAPPING #-}
  ( ToHttpApiData a,
    HasClient m api,
    KnownSymbol sym,
    KnownSymbol (Eval (mod sym))
  ) =>
  GHasClient mod m (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a])) api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> Request
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) ()
-> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 (K1 [a]
x)) =
    forall (m :: * -> *) api.
HasClient m api =>
Proxy m -> Proxy api -> Request -> Client m api
clientWithRoute Proxy m
pm (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParams (Eval (mod sym)) a :> api)) Request
req [a]
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) ()
    -> Client mon api)
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
_ forall x. mon x -> mon' x
f S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) () -> Client mon api
cl (M1 (K1 [a]
x)) =
    forall (m :: * -> *) api (mon :: * -> *) (mon' :: * -> *).
HasClient m api =>
Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> Client mon api
-> Client mon' api
hoistClientMonad
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParams (Eval (mod sym)) a :> api))
      forall x. mon x -> mon' x
f
      (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 [a]) () -> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). c -> K1 i c p
K1)
      [a]
x
  {-# INLINE gHoistClientMonad #-}

instance
  {-# OVERLAPPING #-}
  ( ToHttpApiData a,
    HasClient m api,
    KnownSymbol sym,
    KnownSymbol (Eval (mod sym))
  ) =>
  GHasClient
    mod
    m
    (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)))
    api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> Request
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()
-> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 (K1 Maybe a
x)) =
    forall (m :: * -> *) api.
HasClient m api =>
Proxy m -> Proxy api -> Request -> Client m api
clientWithRoute
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParam' '[Optional, Strict] (Eval (mod sym)) a :> api))
      Request
req
      Maybe a
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()
    -> Client mon api)
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
_ forall x. mon x -> mon' x
f S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()
-> Client mon api
cl (M1 (K1 Maybe a
x)) =
    forall (m :: * -> *) api (mon :: * -> *) (mon' :: * -> *).
HasClient m api =>
Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> Client mon api
-> Client mon' api
hoistClientMonad
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParam' '[Optional, Strict] (Eval (mod sym)) a :> api))
      forall x. mon x -> mon' x
f
      (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 (Maybe a)) ()
-> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). c -> K1 i c p
K1)
      Maybe a
x
  {-# INLINE gHoistClientMonad #-}

instance
  {-# OVERLAPPABLE #-}
  ( ToHttpApiData a,
    HasClient m api,
    KnownSymbol sym,
    KnownSymbol (Eval (mod sym))
  ) =>
  GHasClient
    mod
    m
    (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a))
    api
  where
  gClientWithRoute :: RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> Request
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) ()
-> Client m api
gClientWithRoute Proxy mod
_ Proxy m
pm Proxy api
_ Request
req (M1 (K1 a
x)) =
    forall (m :: * -> *) api.
HasClient m api =>
Proxy m -> Proxy api -> Request -> Client m api
clientWithRoute
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParam' '[Required, Strict] (Eval (mod sym)) a :> api))
      Request
req
      a
x
  {-# INLINE gClientWithRoute #-}
  gHoistClientMonad :: forall (mon :: * -> *) (mon' :: * -> *).
RunClient m =>
Proxy mod
-> Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) ()
    -> Client mon api)
-> S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) ()
-> Client mon' api
gHoistClientMonad Proxy mod
_ Proxy m
pm Proxy api
_ forall x. mon x -> mon' x
f S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) () -> Client mon api
cl (M1 (K1 a
x)) =
    forall (m :: * -> *) api (mon :: * -> *) (mon' :: * -> *).
HasClient m api =>
Proxy m
-> Proxy api
-> (forall x. mon x -> mon' x)
-> Client mon api
-> Client mon' api
hoistClientMonad
      Proxy m
pm
      (forall {k} (t :: k). Proxy t
Proxy :: Proxy (QueryParam' '[Required, Strict] (Eval (mod sym)) a :> api))
      forall x. mon x -> mon' x
f
      (S1 ('MetaSel ('Just sym) d1 d2 d3) (Rec0 a) () -> Client mon api
cl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). c -> K1 i c p
K1)
      a
x
  {-# INLINE gHoistClientMonad #-}