-- |
-- Module      : Data.KindID.V1.Unsafe
-- License     : MIT
-- Maintainer  : mmzk1526@outlook.com
-- Portability : GHC
--
-- Unsafe 'KindIDV1' functions.
--
module Data.KindID.V1.Unsafe
  (
  -- * Unsafe 'KindIDV1' decoding ('KindIDV1'-specific)
    unsafeParseString
  , unsafeParseText
  , unsafeParseByteString
  -- * Unsafe 'KindIDV1' decoding (class methods)
  , unsafeString2ID
  , unsafeText2ID
  , unsafeByteString2ID
  -- * Unsafe conversion
  , unsafeFromTypeID
  ) where

import           Data.ByteString.Lazy (ByteString)
import           Data.KindID.Class
import qualified Data.KindID.Internal as KID
import           Data.KindID.V1 (KindIDV1)
import           Data.TypeID.V1 (TypeIDV1)
import           Data.Text (Text)
import           Data.TypeID.Class

-- | Parse a 'KindIDV1' from its 'String' representation, but does not behave
-- correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindIDV1'. If there are other parse errors, it will crash.
unsafeParseString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                  => String -> KindIDV1 prefix
unsafeParseString :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> KindIDV1 prefix
unsafeParseString = String -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> KindID' version prefix
KID.unsafeParseString
{-# INLINE unsafeParseString #-}

-- | Parse a 'KindIDV1' from its string representation as a strict 'Text', but
-- does not behave correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindIDV1'. If there are other parse errors, it will crash.
unsafeParseText :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                => Text -> KindIDV1 prefix
unsafeParseText :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> KindIDV1 prefix
unsafeParseText = Text -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> KindID' version prefix
KID.unsafeParseText
{-# INLINE unsafeParseText #-}

-- | Parse a 'KindIDV1' from its string representation as a lazy 'ByteString',
-- but does not behave correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindIDV1'. If there are other parse errors, it will crash.
unsafeParseByteString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                      => ByteString -> KindIDV1 prefix
unsafeParseByteString :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> KindIDV1 prefix
unsafeParseByteString = ByteString -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> KindID' version prefix
KID.unsafeParseByteString
{-# INLINE unsafeParseByteString #-}

-- | Convert a 'TypeIDV1' to a 'KindIDV1'. If the actual prefix does not match
-- with the expected one as defined by the type, it does not complain and
-- produces a wrong 'KindIDV1'.
unsafeFromTypeID :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                 => TypeIDV1 -> KindIDV1 prefix
unsafeFromTypeID :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeIDV1 -> KindIDV1 prefix
unsafeFromTypeID = TypeIDV1 -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
KID.unsafeFromTypeID
{-# INLINE unsafeFromTypeID #-}