module Charon.Backend.Fdo.Utils
  ( percentEncodeFileName,
  )
where

import Charon.Data.Paths (PathI (MkPathI), PathIndex (TrashEntryFileName))
import Charon.Prelude
import Charon.Utils qualified as Utils
import Data.Text qualified as T

percentEncodeFileName ::
  forall m pd k.
  ( HasCallStack,
    Is k A_Getter,
    LabelOptic' "fileName" k pd (PathI TrashEntryFileName),
    MonadThrow m
  ) =>
  pd ->
  m ByteString
percentEncodeFileName :: forall (m :: * -> *) pd k.
(HasCallStack, Is k A_Getter,
 LabelOptic' "fileName" k pd (PathI 'TrashEntryFileName),
 MonadThrow m) =>
pd -> m ByteString
percentEncodeFileName pd
pd =
  String -> ByteString
percentEncode (String -> ByteString) -> m String -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OsPath -> m String
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
OsPath -> m String
decodeOsToFpThrowM OsPath
fileName
  where
    percentEncode :: String -> ByteString
percentEncode = ByteString -> ByteString
Utils.percentEncode (ByteString -> ByteString)
-> (String -> ByteString) -> String -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
encodeUtf8 (Text -> ByteString) -> (String -> Text) -> String -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
    MkPathI OsPath
fileName = Optic' k NoIx pd (PathI 'TrashEntryFileName)
-> pd -> PathI 'TrashEntryFileName
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Optic' k NoIx pd (PathI 'TrashEntryFileName)
#fileName pd
pd