content: {-
   Copyright 2022-23, Juspay India Pvt Ltd
  
   This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License
  
   as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program
  
   is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  
   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of
  
   the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
  -}
  
  module ExternalAPI where
  
  import "public-transport-rider-platform" Beckn.Spec.OnCancel
  import "public-transport-rider-platform" Beckn.Spec.OnConfirm
  import "public-transport-rider-platform" Beckn.Spec.OnSearch
  import "public-transport-rider-platform" Beckn.Spec.OnStatus
  import Environment
  import Kernel.Mock.App
  import Kernel.Mock.ExternalAPI
  import Kernel.Types.Beckn.Ack (AckResponse)
  import Kernel.Types.Beckn.ReqTypes
  import Servant
  import Servant.Client
  
  type GatewayOnSearchAPI =
    "on_search"
      :> ReqBody '[JSON] (BecknCallbackReq OnSearchCatalog)
      :> Post '[JSON] AckResponse
  
  callGatewayOnSearch :: BecknCallbackReq OnSearchCatalog -> MockM AppEnv ()
  callGatewayOnSearch = callAPI @GatewayOnSearchAPI gatewayUrl
    where
      gatewayUrl = BaseUrl Http "localhost" 8015 "v1"
  
  ----------------------------
  type OnConfirmAPI =
    "on_confirm"
      :> ReqBody '[JSON] (BecknCallbackReq OnConfirmMessage)
      :> Post '[JSON] AckResponse
  
  callBapOnConfirm :: BecknCallbackReq OnConfirmMessage -> MockM AppEnv ()
  callBapOnConfirm = callBapAPI @OnConfirmAPI
  
  ----------------------------
  type OnStatusAPI =
    "on_status"
      :> ReqBody '[JSON] (BecknCallbackReq OnStatusMessage)
      :> Post '[JSON] AckResponse
  
  callBapOnStatus :: BecknCallbackReq OnStatusMessage -> MockM AppEnv ()
  callBapOnStatus = callBapAPI @OnStatusAPI
  
  ----------------------------
  type OnCancelAPI =
    "on_cancel"
      :> ReqBody '[JSON] (BecknCallbackReq OnCancelMessage)
      :> Post '[JSON] AckResponse
  
  callBapOnCancel :: BecknCallbackReq OnCancelMessage -> MockM AppEnv ()
  callBapOnCancel = callBapAPI @OnCancelAPI
  