{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies      #-}

module PlutusCore.Pretty.ConfigName
  ( PrettyConfigName (..)
  , HasPrettyConfigName (..)
  , prettyConfigName
  , prettyConfigNameSimple
  ) where

import Data.Coerce (coerce)
import Text.PrettyBy (HasPrettyDefaults)
import Text.PrettyBy.Fixity (Sole (Sole))

-- | A config that determines how to pretty-print a PLC name.
newtype PrettyConfigName = PrettyConfigName
  { PrettyConfigName -> Bool
_pcnShowsUnique :: Bool
  -- ^ Whether to show the 'Unique' of a name or not.
  }
  deriving stock (PrettyConfigName -> PrettyConfigName -> Bool
(PrettyConfigName -> PrettyConfigName -> Bool)
-> (PrettyConfigName -> PrettyConfigName -> Bool)
-> Eq PrettyConfigName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrettyConfigName -> PrettyConfigName -> Bool
== :: PrettyConfigName -> PrettyConfigName -> Bool
$c/= :: PrettyConfigName -> PrettyConfigName -> Bool
/= :: PrettyConfigName -> PrettyConfigName -> Bool
Eq, Int -> PrettyConfigName -> ShowS
[PrettyConfigName] -> ShowS
PrettyConfigName -> String
(Int -> PrettyConfigName -> ShowS)
-> (PrettyConfigName -> String)
-> ([PrettyConfigName] -> ShowS)
-> Show PrettyConfigName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrettyConfigName -> ShowS
showsPrec :: Int -> PrettyConfigName -> ShowS
$cshow :: PrettyConfigName -> String
show :: PrettyConfigName -> String
$cshowList :: [PrettyConfigName] -> ShowS
showList :: [PrettyConfigName] -> ShowS
Show)

type instance HasPrettyDefaults PrettyConfigName = 'True

-- | A class of configs from which a 'PrettyConfigName' can be extracted.
class HasPrettyConfigName config where
  toPrettyConfigName :: config -> PrettyConfigName

instance HasPrettyConfigName (Sole PrettyConfigName) where
  toPrettyConfigName :: Sole PrettyConfigName -> PrettyConfigName
toPrettyConfigName = Sole PrettyConfigName -> PrettyConfigName
forall a b. Coercible a b => a -> b
coerce

-- | The 'PrettyConfigName' used by default: print 'Unique' indexes after nams.
prettyConfigName :: PrettyConfigName
prettyConfigName :: PrettyConfigName
prettyConfigName = PrettyConfigName{_pcnShowsUnique :: Bool
_pcnShowsUnique = Bool
True}

-- | The 'PrettyConfigName' to be used when 'Unique' indices don't matter. Easier to read.
prettyConfigNameSimple :: PrettyConfigName
prettyConfigNameSimple :: PrettyConfigName
prettyConfigNameSimple = PrettyConfigName{_pcnShowsUnique :: Bool
_pcnShowsUnique = Bool
False}