-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

module Lorentz.UStore.Common
  ( fieldNameToMText
  ) where

import GHC.TypeLits (KnownSymbol, symbolVal)

import Michelson.Text

fieldNameToMText :: forall field. KnownSymbol field => MText
fieldNameToMText :: MText
fieldNameToMText =
  -- Using 'mkMTextUnsafe' because our coding practices does not allow
  -- weird characters (like unicode) in field names
  HasCallStack => Text -> MText
Text -> MText
mkMTextUnsafe (Text -> MText) -> (Proxy field -> Text) -> Proxy field -> MText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. ToText a => a -> Text
toText (String -> Text) -> (Proxy field -> String) -> Proxy field -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy field -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy field -> MText) -> Proxy field -> MText
forall a b. (a -> b) -> a -> b
$ Proxy field
forall k (t :: k). Proxy t
Proxy @field