-- |Combinators for 'PluginName'.
module Ribosome.PluginName where

import Exon (exon)

import Ribosome.Data.PluginName (PluginName (PluginName))
import Ribosome.Host.Text (pascalCase)

-- |Get the 'PluginName' from a 'Reader'.
pluginName ::
  Member (Reader PluginName) r =>
  Sem r PluginName
pluginName :: forall (r :: EffectRow).
Member (Reader PluginName) r =>
Sem r PluginName
pluginName =
  Sem r PluginName
forall i (r :: EffectRow). Member (Reader i) r => Sem r i
ask

-- |Get the 'PluginName' from a 'Reader' and prefix the given string with it, followed by a colon..
pluginNamePrefixed ::
  Member (Reader PluginName) r =>
  Text ->
  Sem r Text
pluginNamePrefixed :: forall (r :: EffectRow).
Member (Reader PluginName) r =>
Text -> Sem r Text
pluginNamePrefixed Text
msg = do
  PluginName Text
name <- Sem r PluginName
forall (r :: EffectRow).
Member (Reader PluginName) r =>
Sem r PluginName
pluginName
  Text -> Sem r Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure [exon|#{name}: #{msg}|]

-- |Get the 'PluginName' from a 'Reader' and convert it to PascalCase.
pluginNamePascalCase ::
  Member (Reader PluginName) r =>
  Sem r PluginName
pluginNamePascalCase :: forall (r :: EffectRow).
Member (Reader PluginName) r =>
Sem r PluginName
pluginNamePascalCase = do
  PluginName Text
n <- Sem r PluginName
forall (r :: EffectRow).
Member (Reader PluginName) r =>
Sem r PluginName
pluginName
  PluginName -> Sem r PluginName
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> PluginName
PluginName (Text -> Text
forall a b. (ToString a, IsString b) => a -> b
pascalCase Text
n))