module Aws.Pa.ServiceConfiguration (
  ServiceConfiguration (..),
  defaultServiceConfiguration
) where

import           Aws.Core.Endpoint        (AwsEndpoint (..), AwsHost (..),
                                           AwsService (..))
import qualified Aws.Core.Protocol        as P
import           Aws.Pa.Commands.MsgTypes (AssociateId)
import           Aws.Pa.Config            (Service, Version, associateId,
                                           baseDomain, serviceDomain,
                                           serviceName, servicePath,
                                           serviceVersion)

import qualified Data.ByteString.Char8    as BS

data ServiceConfiguration qt = ServiceConfiguration {
     srvService     :: Service,
     srvVersion     :: Version,
     srvEndpoint    :: AwsEndpoint,
     srvAssociateId :: AssociateId
}

defaultServiceConfiguration :: ServiceConfiguration qt
defaultServiceConfiguration =
  serviceConfiguration associateId serviceVersion

serviceConfiguration :: AssociateId -> Version -> ServiceConfiguration qt
serviceConfiguration aid ver =
  ServiceConfiguration serviceName ver serviceEndpoint aid

serviceEndpoint :: AwsEndpoint
serviceEndpoint = AwsEndpoint {epProtocol = P.HTTP,
                               epHost = host,
                               epPort = 80,
                               epPath = servicePath}
                  where
                    AwsService srvc = serviceDomain
                    host = AwsHost $ BS.concat [srvc, ".", baseDomain]
