module Web.Minion.Media (ContentType (..), AllContentTypes (..)) where

import Data.List.NonEmpty qualified as Nel
import Network.HTTP.Media qualified as Http

class ContentType a where
  media :: Nel.NonEmpty Http.MediaType

class AllContentTypes cts where
  allContentTypes :: [Http.MediaType]

instance (ContentType ct, AllContentTypes cts) => AllContentTypes (ct ': cts) where
  allContentTypes :: [MediaType]
allContentTypes = NonEmpty MediaType -> [MediaType]
forall a. NonEmpty a -> [a]
Nel.toList (forall (a :: a). ContentType a => NonEmpty MediaType
forall {k} (a :: k). ContentType a => NonEmpty MediaType
media @ct) [MediaType] -> [MediaType] -> [MediaType]
forall a. Semigroup a => a -> a -> a
<> forall (cts :: [a]). AllContentTypes cts => [MediaType]
forall {k} (cts :: k). AllContentTypes cts => [MediaType]
allContentTypes @cts

instance AllContentTypes '[] where
  allContentTypes :: [MediaType]
allContentTypes = [MediaType]
forall a. Monoid a => a
mempty