{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Admin.Components.ComponentList
  ( ComponentList(..)
  , namesOf
  , descriptionsOf
  , empty
  ) where

import Admin.Components.ComponentDescription
import Admin.Components.Internal.TypeLevel (ManySymbolVal, manySymbolVal)
import Data.Version
import GHC.TypeLits (Symbol)
import Servant

data ComponentList (names :: [Symbol]) apis =
  ComponentList
    { ComponentList names apis -> Server apis
serveAll :: Server apis
    , ComponentList names apis -> [Version]
versions :: [Version]
    }

namesOf ::
     forall names apis. (ManySymbolVal names)
  => ComponentList names apis
  -> [String]
namesOf :: ComponentList names apis -> [String]
namesOf ComponentList names apis
_ = Proxy names -> [String]
forall (xs :: [Symbol]) (proxy :: [Symbol] -> *).
ManySymbolVal xs =>
proxy xs -> [String]
manySymbolVal (Proxy names
forall k (t :: k). Proxy t
Proxy :: Proxy names)

descriptionsOf ::
     forall names apis. (ManySymbolVal names)
  => ComponentList names apis
  -> [ComponentDescription]
descriptionsOf :: ComponentList names apis -> [ComponentDescription]
descriptionsOf ComponentList names apis
cs = (String -> Version -> ComponentDescription)
-> [String] -> [Version] -> [ComponentDescription]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith String -> Version -> ComponentDescription
ComponentDescription (ComponentList names apis -> [String]
forall (names :: [Symbol]) apis.
ManySymbolVal names =>
ComponentList names apis -> [String]
namesOf ComponentList names apis
cs) (ComponentList names apis -> [Version]
forall (names :: [Symbol]) apis.
ComponentList names apis -> [Version]
versions ComponentList names apis
cs)

empty :: ComponentList '[] EmptyAPI
empty :: ComponentList '[] EmptyAPI
empty = Server EmptyAPI -> [Version] -> ComponentList '[] EmptyAPI
forall (names :: [Symbol]) apis.
Server apis -> [Version] -> ComponentList names apis
ComponentList Server EmptyAPI
forall (m :: * -> *). ServerT EmptyAPI m
emptyServer [[Int] -> Version
makeVersion [Int
1]]