{-# LANGUAGE DataKinds #-}

module Unison.SyncV2.API
  ( API,
    api,
    Routes (..),
  )
where

import Data.Proxy
import GHC.Generics (Generic)
import Servant.API
import Unison.SyncV2.Types
import Unison.Util.Servant.CBOR (CBOR)

api :: Proxy API
api :: Proxy API
api = Proxy API
forall {k} (t :: k). Proxy t
Proxy

type API = NamedRoutes Routes

type DownloadEntitiesStream =
  -- | The causal hash the client needs. The server should provide it and all of its dependencies
  ReqBody '[CBOR, JSON] DownloadEntitiesRequest
    :> StreamPost NoFraming OctetStream (SourceIO (CBORStream DownloadEntitiesChunk))

-- | Get the relevant dependencies of a causal, including the causal spine and the causal hashes of any library roots.
type CausalDependenciesStream =
  ReqBody '[CBOR, JSON] CausalDependenciesRequest
    :> StreamPost NoFraming OctetStream (SourceIO (CBORStream CausalDependenciesChunk))

data Routes mode = Routes
  { forall mode.
Routes mode
-> mode :- ("entities" :> ("download" :> DownloadEntitiesStream))
downloadEntitiesStream :: mode :- "entities" :> "download" :> DownloadEntitiesStream,
    forall mode.
Routes mode
-> mode
   :- ("entities" :> ("dependencies" :> CausalDependenciesStream))
causalDependenciesStream :: mode :- "entities" :> "dependencies" :> CausalDependenciesStream
  }
  deriving stock ((forall x. Routes mode -> Rep (Routes mode) x)
-> (forall x. Rep (Routes mode) x -> Routes mode)
-> Generic (Routes mode)
forall x. Rep (Routes mode) x -> Routes mode
forall x. Routes mode -> Rep (Routes mode) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall mode x. Rep (Routes mode) x -> Routes mode
forall mode x. Routes mode -> Rep (Routes mode) x
$cfrom :: forall mode x. Routes mode -> Rep (Routes mode) x
from :: forall x. Routes mode -> Rep (Routes mode) x
$cto :: forall mode x. Rep (Routes mode) x -> Routes mode
to :: forall x. Rep (Routes mode) x -> Routes mode
Generic)