    {-# LANGUAGE DeriveGeneric #-}
    {-# LANGUAGE OverloadedStrings #-}
    module Codec.Xlsx.Types.Internal where

    import Control.Arrow
    import Data.Monoid ((<>))
    import Data.Text (Text)
    import GHC.Generics (Generic)

    import Codec.Xlsx.Parser.Internal
    import Codec.Xlsx.Writer.Internal

    newtype RefId = RefId { RefId -> Text
    unRefId :: Text } deriving (RefId -> RefId -> Bool
    (RefId -> RefId -> Bool) -> (RefId -> RefId -> Bool) -> Eq RefId
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: RefId -> RefId -> Bool
    == :: RefId -> RefId -> Bool
    $c/= :: RefId -> RefId -> Bool
    /= :: RefId -> RefId -> Bool
    Eq, Eq RefId
    Eq RefId =>
    (RefId -> RefId -> Ordering)
    -> (RefId -> RefId -> Bool)
    -> (RefId -> RefId -> Bool)
    -> (RefId -> RefId -> Bool)
    -> (RefId -> RefId -> Bool)
    -> (RefId -> RefId -> RefId)
    -> (RefId -> RefId -> RefId)
    -> Ord RefId
    RefId -> RefId -> Bool
    RefId -> RefId -> Ordering
    RefId -> RefId -> RefId
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: RefId -> RefId -> Ordering
    compare :: RefId -> RefId -> Ordering
    $c< :: RefId -> RefId -> Bool
    < :: RefId -> RefId -> Bool
    $c<= :: RefId -> RefId -> Bool
    <= :: RefId -> RefId -> Bool
    $c> :: RefId -> RefId -> Bool
    > :: RefId -> RefId -> Bool
    $c>= :: RefId -> RefId -> Bool
    >= :: RefId -> RefId -> Bool
    $cmax :: RefId -> RefId -> RefId
    max :: RefId -> RefId -> RefId
    $cmin :: RefId -> RefId -> RefId
    min :: RefId -> RefId -> RefId
    Ord, Int -> RefId -> ShowS
    [RefId] -> ShowS
    RefId -> String
    (Int -> RefId -> ShowS)
    -> (RefId -> String) -> ([RefId] -> ShowS) -> Show RefId
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> RefId -> ShowS
    showsPrec :: Int -> RefId -> ShowS
    $cshow :: RefId -> String
    show :: RefId -> String
    $cshowList :: [RefId] -> ShowS
    showList :: [RefId] -> ShowS
    Show, (forall x. RefId -> Rep RefId x)
    -> (forall x. Rep RefId x -> RefId) -> Generic RefId
    forall x. Rep RefId x -> RefId
    forall x. RefId -> Rep RefId x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. RefId -> Rep RefId x
    from :: forall x. RefId -> Rep RefId x
    $cto :: forall x. Rep RefId x -> RefId
    to :: forall x. Rep RefId x -> RefId
    Generic)

    instance ToAttrVal RefId where
        toAttrVal :: RefId -> Text
    toAttrVal = Text -> Text
    forall a. ToAttrVal a => a -> Text
    toAttrVal (Text -> Text) -> (RefId -> Text) -> RefId -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RefId -> Text
    unRefId

    instance FromAttrVal RefId where
        fromAttrVal :: Reader RefId
    fromAttrVal Text
    t = (Text -> RefId) -> (Text, Text) -> (RefId, Text)
    forall b c d. (b -> c) -> (b, d) -> (c, d)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (b, d) (c, d)
    first Text -> RefId
    RefId ((Text, Text) -> (RefId, Text))
    -> Either String (Text, Text) -> Either String (RefId, Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Reader Text
    forall a. FromAttrVal a => Reader a
    fromAttrVal Text
    t

    instance FromAttrBs RefId where
      fromAttrBs :: ByteString -> Either Text RefId
    fromAttrBs = (Text -> RefId) -> Either Text Text -> Either Text RefId
    forall a b. (a -> b) -> Either Text a -> Either Text b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Text -> RefId
    RefId (Either Text Text -> Either Text RefId)
    -> (ByteString -> Either Text Text)
    -> ByteString
    -> Either Text RefId
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> Either Text Text
    forall a. FromAttrBs a => ByteString -> Either Text a
    fromAttrBs

    unsafeRefId :: Int -> RefId
    unsafeRefId :: Int -> RefId
    unsafeRefId Int
    num = Text -> RefId
    RefId (Text -> RefId) -> Text -> RefId
    forall a b. (a -> b) -> a -> b
    $ Text
    "rId" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Int -> Text
    forall a. Integral a => a -> Text
    txti Int
    num