-- | Common services

{-# OPTIONS_HADDOCK hide #-}

module Blockfrost.API.Common
  where

import Blockfrost.Types
import Blockfrost.Util.Tag (Tag)
import Data.Text (Text)
import Servant.API
import Servant.API.Generic

data CommonAPI route =
  CommonAPI
    {
      forall route.
CommonAPI route
-> route
   :- (Summary "Root endpoint"
       :> (Description
             "Root endpoint has no other function than to point end users to documentation."
           :> (Tag "Health" :> Get '[JSON] URLVersion)))
_getRoot
        :: route
        :- Summary "Root endpoint"
        :> Description "Root endpoint has no other function than to point end users to documentation."
        :> Tag "Health"
        :> Get '[JSON] URLVersion
    , forall route.
CommonAPI route
-> route
   :- (Summary "Backend health status"
       :> (Description
             "Return backend status as a boolean. Your application should handle situations when backend for the given chain is unavailable."
           :> (Tag "Health" :> ("health" :> Get '[JSON] Healthy))))
_getHealth
        :: route
        :- Summary "Backend health status"
        :> Description "Return backend status as a boolean. \
                        \Your application should handle situations when backend for the given chain is unavailable."
        :> Tag "Health"
        :> "health"
        :> Get '[JSON] Healthy
    , forall route.
CommonAPI route
-> route
   :- (Summary "Current backend time"
       :> (Description
             "This endpoint provides the current UNIX time. Your application might use this to verify if the client clock is not out of sync."
           :> (Tag "Health"
               :> ("health" :> ("clock" :> Get '[JSON] ServerTime)))))
_getClock
        :: route
        :- Summary "Current backend time"
        :> Description "This endpoint provides the current UNIX time. \
                         \Your application might use this to verify if \
                         \the client clock is not out of sync."
        :> Tag "Health"
        :> "health"
        :> "clock"
        :> Get '[JSON] ServerTime
    , forall route.
CommonAPI route
-> route
   :- (Summary "Blockfrost usage metrics"
       :> (Description
             "History of your Blockfrost usage metrics in the past 30 days."
           :> (Tag "Metrics" :> ("metrics" :> Get '[JSON] [Metric]))))
_metrics
        :: route
        :- Summary "Blockfrost usage metrics"
        :> Description "History of your Blockfrost usage metrics in the past 30 days."
        :> Tag "Metrics"
        :> "metrics"
        :> Get '[JSON] [Metric]
    , forall route.
CommonAPI route
-> route
   :- (Summary "Blockfrost endpoint usage metrics"
       :> (Description
             "History of your Blockfrost usage metrics per endpoint in the past 30 days."
           :> (Tag "Metrics"
               :> ("metrics" :> ("endpoints" :> Get '[JSON] [(Text, Metric)])))))
_metricsEndpoints
        :: route
        :- Summary "Blockfrost endpoint usage metrics"
        :> Description "History of your Blockfrost usage metrics per endpoint in the past 30 days."
        :> Tag "Metrics"
        :> "metrics"
        :> "endpoints"
        :> Get '[JSON] [(Text, Metric)]
    } deriving ((forall x. CommonAPI route -> Rep (CommonAPI route) x)
-> (forall x. Rep (CommonAPI route) x -> CommonAPI route)
-> Generic (CommonAPI route)
forall x. Rep (CommonAPI route) x -> CommonAPI route
forall x. CommonAPI route -> Rep (CommonAPI route) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall route x. Rep (CommonAPI route) x -> CommonAPI route
forall route x. CommonAPI route -> Rep (CommonAPI route) x
$cfrom :: forall route x. CommonAPI route -> Rep (CommonAPI route) x
from :: forall x. CommonAPI route -> Rep (CommonAPI route) x
$cto :: forall route x. Rep (CommonAPI route) x -> CommonAPI route
to :: forall x. Rep (CommonAPI route) x -> CommonAPI route
Generic)