module Testlib.Ports where

import Testlib.Types hiding (port)
import Prelude

data PortNamespace
  = NginzSSL
  | NginzHttp2
  | FederatorExternal
  | ServiceInternal Service

port :: (Num a) => PortNamespace -> BackendName -> a
port :: forall a. Num a => PortNamespace -> BackendName -> a
port PortNamespace
NginzSSL BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8443 BackendName
bn
port PortNamespace
NginzHttp2 BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8099 BackendName
bn
port PortNamespace
FederatorExternal BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8098 BackendName
bn
port (ServiceInternal Service
BackgroundWorker) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8089 BackendName
bn
port (ServiceInternal Service
Brig) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8082 BackendName
bn
port (ServiceInternal Service
Cannon) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8083 BackendName
bn
port (ServiceInternal Service
Cargohold) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8084 BackendName
bn
port (ServiceInternal Service
FederatorInternal) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8097 BackendName
bn
port (ServiceInternal Service
Galley) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8085 BackendName
bn
port (ServiceInternal Service
Gundeck) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8086 BackendName
bn
port (ServiceInternal Service
Nginz) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8080 BackendName
bn
port (ServiceInternal Service
Spar) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8088 BackendName
bn
port (ServiceInternal Service
Stern) BackendName
bn = Int -> BackendName -> a
forall a. Num a => Int -> BackendName -> a
mkPort Int
8091 BackendName
bn

portForDyn :: (Num a) => PortNamespace -> Int -> a
portForDyn :: forall a. Num a => PortNamespace -> Int -> a
portForDyn PortNamespace
ns Int
i = PortNamespace -> BackendName -> a
forall a. Num a => PortNamespace -> BackendName -> a
port PortNamespace
ns (Int -> BackendName
DynamicBackend Int
i)

mkPort :: (Num a) => Int -> BackendName -> a
mkPort :: forall a. Num a => Int -> BackendName -> a
mkPort Int
basePort BackendName
bn =
  let i :: Int
i = case BackendName
bn of
        BackendName
BackendA -> Int
0
        BackendName
BackendB -> Int
1
        (DynamicBackend Int
k) -> Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k
   in Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
basePort a -> a -> a
forall a. Num a => a -> a -> a
+ (Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i) a -> a -> a
forall a. Num a => a -> a -> a
* a
1000

internalServicePorts :: (Num a) => BackendName -> Service -> a
internalServicePorts :: forall a. Num a => BackendName -> Service -> a
internalServicePorts BackendName
backend Service
service = PortNamespace -> BackendName -> a
forall a. Num a => PortNamespace -> BackendName -> a
port (Service -> PortNamespace
ServiceInternal Service
service) BackendName
backend