-- |Interpreters for 'ProcessOutput' and 'ProcessInput', Internal
module Polysemy.Process.Interpreter.ProcessIO where

import Polysemy.Process.Effect.ProcessInput (ProcessInput)
import Polysemy.Process.Effect.ProcessOutput (OutputPipe (Stderr, Stdout), ProcessOutput)
import Polysemy.Process.Interpreter.ProcessInput (interpretProcessInputId, interpretProcessInputText)
import Polysemy.Process.Interpreter.ProcessOutput (
  interpretProcessOutputId,
  interpretProcessOutputIgnore,
  interpretProcessOutputLines,
  interpretProcessOutputText,
  interpretProcessOutputTextLines,
  )

-- |The effects used by 'Polysemy.Process.Process' to send and receive chunks of bytes to and from a process.
type ProcessIO i o =
  [
    ProcessInput i,
    ProcessOutput 'Stdout o,
    ProcessOutput 'Stderr o
  ]

-- |Interpret 'ProcessIO' with plain 'ByteString's without chunking.
-- Silently discards stderr.
interpretProcessByteString ::
  InterpretersFor (ProcessIO ByteString ByteString) r
interpretProcessByteString :: forall (r :: [Effect]).
InterpretersFor (ProcessIO ByteString ByteString) r
interpretProcessByteString =
  forall (p :: OutputPipe) a (r :: [Effect]).
InterpreterFor (ProcessOutput p a) r
interpretProcessOutputIgnore @'Stderr (Sem (ProcessOutput 'Stderr ByteString : r) a -> Sem r a)
-> (Sem
      (ProcessInput ByteString
         : ProcessOutput 'Stdout ByteString
         : ProcessOutput 'Stderr ByteString : r)
      a
    -> Sem (ProcessOutput 'Stderr ByteString : r) a)
-> Sem
     (ProcessInput ByteString
        : ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall (p :: OutputPipe) (r :: [Effect]).
InterpreterFor (ProcessOutput p ByteString) r
interpretProcessOutputId @'Stdout (Sem
   (ProcessOutput 'Stdout ByteString
      : ProcessOutput 'Stderr ByteString : r)
   a
 -> Sem (ProcessOutput 'Stderr ByteString : r) a)
-> (Sem
      (ProcessInput ByteString
         : ProcessOutput 'Stdout ByteString
         : ProcessOutput 'Stderr ByteString : r)
      a
    -> Sem
         (ProcessOutput 'Stdout ByteString
            : ProcessOutput 'Stderr ByteString : r)
         a)
-> Sem
     (ProcessInput ByteString
        : ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
-> Sem (ProcessOutput 'Stderr ByteString : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  (ProcessInput ByteString
     : ProcessOutput 'Stdout ByteString
     : ProcessOutput 'Stderr ByteString : r)
  a
-> Sem
     (ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
forall (r :: [Effect]). InterpreterFor (ProcessInput ByteString) r
interpretProcessInputId

-- |Interpret 'ProcessIO' with 'ByteString's chunked as lines.
-- Silently discards stderr.
interpretProcessByteStringLines ::
  InterpretersFor (ProcessIO ByteString ByteString) r
interpretProcessByteStringLines :: forall (r :: [Effect]).
InterpretersFor (ProcessIO ByteString ByteString) r
interpretProcessByteStringLines =
  forall (p :: OutputPipe) a (r :: [Effect]).
InterpreterFor (ProcessOutput p a) r
interpretProcessOutputIgnore @'Stderr (Sem (ProcessOutput 'Stderr ByteString : r) a -> Sem r a)
-> (Sem
      (ProcessInput ByteString
         : ProcessOutput 'Stdout ByteString
         : ProcessOutput 'Stderr ByteString : r)
      a
    -> Sem (ProcessOutput 'Stderr ByteString : r) a)
-> Sem
     (ProcessInput ByteString
        : ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall (p :: OutputPipe) (r :: [Effect]).
InterpreterFor (ProcessOutput p ByteString) r
interpretProcessOutputLines @'Stdout (Sem
   (ProcessOutput 'Stdout ByteString
      : ProcessOutput 'Stderr ByteString : r)
   a
 -> Sem (ProcessOutput 'Stderr ByteString : r) a)
-> (Sem
      (ProcessInput ByteString
         : ProcessOutput 'Stdout ByteString
         : ProcessOutput 'Stderr ByteString : r)
      a
    -> Sem
         (ProcessOutput 'Stdout ByteString
            : ProcessOutput 'Stderr ByteString : r)
         a)
-> Sem
     (ProcessInput ByteString
        : ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
-> Sem (ProcessOutput 'Stderr ByteString : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  (ProcessInput ByteString
     : ProcessOutput 'Stdout ByteString
     : ProcessOutput 'Stderr ByteString : r)
  a
-> Sem
     (ProcessOutput 'Stdout ByteString
        : ProcessOutput 'Stderr ByteString : r)
     a
forall (r :: [Effect]). InterpreterFor (ProcessInput ByteString) r
interpretProcessInputId

-- |Interpret 'ProcessIO' with plain 'Text's without chunking.
-- Silently discards stderr.
interpretProcessText ::
  InterpretersFor (ProcessIO Text Text) r
interpretProcessText :: forall (r :: [Effect]). InterpretersFor (ProcessIO Text Text) r
interpretProcessText =
  forall (p :: OutputPipe) a (r :: [Effect]).
InterpreterFor (ProcessOutput p a) r
interpretProcessOutputIgnore @'Stderr (Sem (ProcessOutput 'Stderr Text : r) a -> Sem r a)
-> (Sem
      (ProcessInput Text
         : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
      a
    -> Sem (ProcessOutput 'Stderr Text : r) a)
-> Sem
     (ProcessInput Text
        : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
     a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall (p :: OutputPipe) (r :: [Effect]).
InterpreterFor (ProcessOutput p Text) r
interpretProcessOutputText @'Stdout (Sem
   (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a
 -> Sem (ProcessOutput 'Stderr Text : r) a)
-> (Sem
      (ProcessInput Text
         : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
      a
    -> Sem
         (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a)
-> Sem
     (ProcessInput Text
        : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
     a
-> Sem (ProcessOutput 'Stderr Text : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  (ProcessInput Text
     : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
  a
-> Sem
     (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a
forall (r :: [Effect]). InterpreterFor (ProcessInput Text) r
interpretProcessInputText

-- |Interpret 'ProcessIO' with 'Text's chunked as lines.
-- Silently discards stderr.
interpretProcessTextLines ::
  InterpretersFor (ProcessIO Text Text) r
interpretProcessTextLines :: forall (r :: [Effect]). InterpretersFor (ProcessIO Text Text) r
interpretProcessTextLines =
  forall (p :: OutputPipe) a (r :: [Effect]).
InterpreterFor (ProcessOutput p a) r
interpretProcessOutputIgnore @'Stderr (Sem (ProcessOutput 'Stderr Text : r) a -> Sem r a)
-> (Sem
      (ProcessInput Text
         : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
      a
    -> Sem (ProcessOutput 'Stderr Text : r) a)
-> Sem
     (ProcessInput Text
        : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
     a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall (p :: OutputPipe) (r :: [Effect]).
InterpreterFor (ProcessOutput p Text) r
interpretProcessOutputTextLines @'Stdout (Sem
   (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a
 -> Sem (ProcessOutput 'Stderr Text : r) a)
-> (Sem
      (ProcessInput Text
         : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
      a
    -> Sem
         (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a)
-> Sem
     (ProcessInput Text
        : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
     a
-> Sem (ProcessOutput 'Stderr Text : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  (ProcessInput Text
     : ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r)
  a
-> Sem
     (ProcessOutput 'Stdout Text : ProcessOutput 'Stderr Text : r) a
forall (r :: [Effect]). InterpreterFor (ProcessInput Text) r
interpretProcessInputText