{-# LANGUAGE DataKinds #-}

module Hercules.API.Build where

import Hercules.API.Accounts.Account (Account)
import Hercules.API.Build.DerivationInfo (DerivationInfo)
import Hercules.API.Build.Log (Log)
import Hercules.API.Prelude
import Hercules.API.Projects.Job (Job)
import Servant.API
import Servant.API.Generic

data BuildAPI auth f = BuildAPI
  { forall auth f.
BuildAPI auth f
-> f
   :- (Summary "Restart a derivation"
       :> ("accounts"
           :> (Capture "accountId" (Id Account)
               :> ("derivations"
                   :> (Capture "derivationPath" Text
                       :> ("retry" :> (auth :> Post '[PlainText, JSON] NoContent)))))))
restartDerivation ::
      f :- Summary "Restart a derivation"
        :> "accounts"
        :> Capture "accountId" (Id Account)
        :> "derivations"
        :> Capture "derivationPath" Text
        :> "retry"
        :> auth
        :> Post '[PlainText, JSON] NoContent,
    forall auth f.
BuildAPI auth f
-> f
   :- (Summary "Read a derivation build log"
       :> (Description "This interface may change."
           :> ("accounts"
               :> (Capture "accountId" (Id Account)
                   :> ("derivations"
                       :> (Capture "derivationPath" Text
                           :> ("log"
                               :> (QueryParam "logId" (Id "log")
                                   :> (auth :> Get '[PlainText, JSON] Text)))))))))
readDerivationLogText ::
      f :- Summary "Read a derivation build log"
        :> Description "This interface may change."
        :> "accounts"
        :> Capture "accountId" (Id Account)
        :> "derivations"
        :> Capture "derivationPath" Text
        :> "log"
        :> QueryParam "logId" (Id "log")
        :> auth
        :> Get '[PlainText, JSON] Text, -- NB: We use JSON only to be able to generate elm api
        -- FIXME: bytes?
    forall auth f.
BuildAPI auth f
-> f
   :- (Summary "Read all recorded log entries"
       :> ("accounts"
           :> (Capture "accountId" (Id Account)
               :> ("derivations"
                   :> (Capture "derivationPath" Text
                       :> ("log"
                           :> ("lines"
                               :> (QueryParam' '[Required] "logId" (Id "log")
                                   :> (QueryParam' '[Optional] "iMin" Int
                                       :> (auth :> Get '[JSON] Log))))))))))
getLog ::
      f :- Summary "Read all recorded log entries"
        :> "accounts"
        :> Capture "accountId" (Id Account)
        :> "derivations"
        :> Capture "derivationPath" Text
        :> "log"
        :> "lines"
        :> QueryParam' '[Required] "logId" (Id "log")
        :> QueryParam' '[Optional] "iMin" Int
        :> auth
        :> Get '[JSON] Log,
    forall auth f.
BuildAPI auth f
-> f
   :- (Summary "Get information about a derivation."
       :> (Description
             "Optionally, a job id can be specified to provide context."
           :> ("accounts"
               :> (Capture "accountId" (Id Account)
                   :> ("derivations"
                       :> (Capture "derivationPath" Text
                           :> (QueryParam' '[Optional, Strict] "via-job" (Id Job)
                               :> (auth :> Get '[JSON] DerivationInfo))))))))
getDerivationInfo ::
      f :- Summary "Get information about a derivation."
        :> Description "Optionally, a job id can be specified to provide context."
        :> "accounts"
        :> Capture "accountId" (Id Account)
        :> "derivations"
        :> Capture "derivationPath" Text
        :> QueryParam' '[Optional, Strict] "via-job" (Id Job)
        :> auth
        :> Get '[JSON] DerivationInfo
  }
  deriving ((forall x. BuildAPI auth f -> Rep (BuildAPI auth f) x)
-> (forall x. Rep (BuildAPI auth f) x -> BuildAPI auth f)
-> Generic (BuildAPI auth f)
forall x. Rep (BuildAPI auth f) x -> BuildAPI auth f
forall x. BuildAPI auth f -> Rep (BuildAPI auth f) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall auth f x. Rep (BuildAPI auth f) x -> BuildAPI auth f
forall auth f x. BuildAPI auth f -> Rep (BuildAPI auth f) x
$cto :: forall auth f x. Rep (BuildAPI auth f) x -> BuildAPI auth f
$cfrom :: forall auth f x. BuildAPI auth f -> Rep (BuildAPI auth f) x
Generic)