-- SPDX-FileCopyrightText: 2026 Alexandra de Wit
--
-- SPDX-License-Identifier: MIT

-- | Closed metadata responses shared by native registry routes.
module Ecluse.Core.Server.Pipeline.Packument.Response (
    MetadataResponse,
    metadataReplies,
    keepPrivateUnauthorised,
) where

import Network.HTTP.Types (ResponseHeaders)

import Ecluse.Core.Server.Contract (
    ResponseChoice (FirstResponse, SecondResponse),
    ResponseValue,
    responseValue,
 )
import Ecluse.Core.Server.Pipeline.Packument (PackumentReplies (..))
import Ecluse.Core.Server.Response (Refusal, ServeDecision)

-- | Metadata replies ordered as 200, 304, 401, 403, 404, 406, 500, 502 and 503.
type MetadataResponse refusal =
    ResponseChoice
        (ResponseValue LByteString)
        ( ResponseChoice
            (ResponseValue ())
            ( ResponseChoice
                (ResponseValue refusal)
                ( ResponseChoice
                    (ResponseValue refusal)
                    ( ResponseChoice
                        (ResponseValue refusal)
                        ( ResponseChoice
                            (ResponseValue refusal)
                            ( ResponseChoice
                                (ResponseValue refusal)
                                (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
                            )
                        )
                    )
                )
            )
        )

-- | Keep native denial wording and refusal bodies within the shared response order. A listing that admitted nothing answers 404.
metadataReplies ::
    ([ServeDecision] -> Text) ->
    (Refusal -> refusal) ->
    PackumentReplies (MetadataResponse refusal)
metadataReplies :: forall refusal.
([ServeDecision] -> Text)
-> (Refusal -> refusal)
-> PackumentReplies (MetadataResponse refusal)
metadataReplies [ServeDecision] -> Text
deniedText Refusal -> refusal
refusalBody =
    PackumentReplies
        { packumentDeniedText :: [ServeDecision] -> Text
packumentDeniedText = [ServeDecision] -> Text
deniedText
        , packumentOk :: ResponseHeaders
-> LByteString
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentOk = \ResponseHeaders
headers LByteString
body -> ResponseValue LByteString
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> LByteString -> ResponseValue LByteString
forall a. ResponseHeaders -> a -> ResponseValue a
responseValue ResponseHeaders
headers LByteString
body)
        , packumentNotModified :: ResponseHeaders
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentNotModified = \ResponseHeaders
headers -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue ()
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> () -> ResponseValue ()
forall a. ResponseHeaders -> a -> ResponseValue a
responseValue ResponseHeaders
headers ()))
        , packumentUnauthorised :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentUnauthorised = \ResponseHeaders
headers Refusal
message -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal) (ResponseValue refusal))))))
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal))))))
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message)))
        , packumentPrivateRefused :: Int
-> ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentPrivateRefused = (ResponseHeaders
 -> Refusal
 -> ResponseChoice
      (ResponseValue LByteString)
      (ResponseChoice
         (ResponseValue ())
         (ResponseChoice
            (ResponseValue refusal)
            (ResponseChoice
               (ResponseValue refusal)
               (ResponseChoice
                  (ResponseValue refusal)
                  (ResponseChoice
                     (ResponseValue refusal)
                     (ResponseChoice
                        (ResponseValue refusal)
                        (ResponseChoice
                           (ResponseValue refusal) (ResponseValue refusal)))))))))
-> Int
-> ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. a -> b -> a
const ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall {a} {a} {a} {b}.
ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
forbiddenReply
        , packumentForbidden :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentForbidden = ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall {a} {a} {a} {b}.
ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
forbiddenReply
        , packumentDenied :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentDenied = ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall {a} {a} {a} {a} {b}.
ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a
        (ResponseChoice
           a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))))
notFoundReply
        , packumentNotFound :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentNotFound = ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall {a} {a} {a} {a} {b}.
ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a
        (ResponseChoice
           a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))))
notFoundReply
        , packumentNotAcceptable :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentNotAcceptable = \ResponseHeaders
headers Refusal
message -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal) (ResponseValue refusal))))))
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message))))))
        , packumentInternal :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentInternal = \ResponseHeaders
headers Refusal
message -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal) (ResponseValue refusal))))))
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message)))))))
        , packumentBadGateway :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentBadGateway = \ResponseHeaders
headers Refusal
message -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal) (ResponseValue refusal))))))
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal
-> ResponseChoice (ResponseValue refusal) (ResponseValue refusal)
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message))))))))
        , packumentUnavailable :: ResponseHeaders
-> Refusal
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
packumentUnavailable = \ResponseHeaders
headers Refusal
message -> ResponseChoice
  (ResponseValue ())
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal)))))))
-> ResponseChoice
     (ResponseValue LByteString)
     (ResponseChoice
        (ResponseValue ())
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal)
                       (ResponseChoice
                          (ResponseValue refusal) (ResponseValue refusal))))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal) (ResponseValue refusal))))))
-> ResponseChoice
     (ResponseValue ())
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal)
                    (ResponseChoice
                       (ResponseValue refusal) (ResponseValue refusal)))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice
                 (ResponseValue refusal)
                 (ResponseChoice
                    (ResponseValue refusal) (ResponseValue refusal))))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice
              (ResponseValue refusal)
              (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice
           (ResponseValue refusal)
           (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  (ResponseValue refusal)
  (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice
        (ResponseValue refusal)
        (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice (ResponseValue refusal) (ResponseValue refusal)
-> ResponseChoice
     (ResponseValue refusal)
     (ResponseChoice (ResponseValue refusal) (ResponseValue refusal))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal
-> ResponseChoice (ResponseValue refusal) (ResponseValue refusal)
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message))))))))
        }
  where
    forbiddenReply :: ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
forbiddenReply ResponseHeaders
headers Refusal
message = ResponseChoice
  a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))
-> ResponseChoice
     a
     (ResponseChoice
        a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)
-> ResponseChoice
     a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice (ResponseValue refusal) b
-> ResponseChoice a (ResponseChoice (ResponseValue refusal) b)
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal -> ResponseChoice (ResponseValue refusal) b
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message))))
    notFoundReply :: ResponseHeaders
-> Refusal
-> ResponseChoice
     a
     (ResponseChoice
        a
        (ResponseChoice
           a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))))
notFoundReply ResponseHeaders
headers Refusal
message = ResponseChoice
  a
  (ResponseChoice
     a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
-> ResponseChoice
     a
     (ResponseChoice
        a
        (ResponseChoice
           a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice
  a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))
-> ResponseChoice
     a
     (ResponseChoice
        a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice a (ResponseChoice (ResponseValue refusal) b)
-> ResponseChoice
     a (ResponseChoice a (ResponseChoice (ResponseValue refusal) b))
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseChoice (ResponseValue refusal) b
-> ResponseChoice a (ResponseChoice (ResponseValue refusal) b)
forall a b. b -> ResponseChoice a b
SecondResponse (ResponseValue refusal -> ResponseChoice (ResponseValue refusal) b
forall a b. a -> ResponseChoice a b
FirstResponse (ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message)))))
    refusalValue :: ResponseHeaders -> Refusal -> ResponseValue refusal
refusalValue ResponseHeaders
headers Refusal
message = ResponseHeaders -> refusal -> ResponseValue refusal
forall a. ResponseHeaders -> a -> ResponseValue a
responseValue ResponseHeaders
headers (Refusal -> refusal
refusalBody Refusal
message)

-- | Answer a private origin's 401 with @replies@' 401 and every other private refusal with its 403.
keepPrivateUnauthorised :: PackumentReplies response -> Int -> ResponseHeaders -> Refusal -> response
keepPrivateUnauthorised :: forall response.
PackumentReplies response
-> Int -> ResponseHeaders -> Refusal -> response
keepPrivateUnauthorised PackumentReplies response
replies Int
code
    | Int
code Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
401 = PackumentReplies response -> ResponseHeaders -> Refusal -> response
forall response.
PackumentReplies response -> ResponseHeaders -> Refusal -> response
packumentUnauthorised PackumentReplies response
replies
    | Bool
otherwise = PackumentReplies response -> ResponseHeaders -> Refusal -> response
forall response.
PackumentReplies response -> ResponseHeaders -> Refusal -> response
packumentForbidden PackumentReplies response
replies