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 API.Search where
  
  import API.Utils (buildOnActionContext)
  import "public-transport-rider-platform" Beckn.Spec.Search
  import Environment
  import ExternalAPI
  import Kernel.Mock.App
  import Kernel.Types.Beckn.Ack (AckResponse (..))
  import Kernel.Types.Beckn.Context
  import Kernel.Types.Beckn.ReqTypes
  import Kernel.Types.Common
  import Kernel.Utils.Common (logPretty)
  import Kernel.Utils.Time
  import MockData.OnSearch
  import Relude
  
  searchServer :: BecknReq SearchMessage -> MockM AppEnv AckResponse
  searchServer becknReq@(BecknReq ctx req) = do
    logPretty DEBUG "request body" becknReq
    _ <- fork "call on_search" $ do
      waitMilliSec <- asks (.callbackWaitTimeMilliSec)
      threadDelayMilliSec waitMilliSec
      context' <- buildOnActionContext ON_SEARCH ctx
      let callbackData = onSearchCatalog req.intent.fulfillment.start.time.range.start
      _ <- callGatewayOnSearch $ BecknCallbackReq context' $ Right callbackData
      pure ()
    pure Ack
  