content: {-# OPTIONS_GHC -Wno-dodgy-exports #-}
  {-# OPTIONS_GHC -Wno-orphans #-}
  {-# OPTIONS_GHC -Wno-unused-imports #-}
  
  module Storage.Queries.CallStatus (module Storage.Queries.CallStatus, module ReExport) where
  
  import qualified Domain.Types.CallStatus
  import Kernel.Beam.Functions
  import qualified Kernel.External.Call.Interface.Types
  import qualified Kernel.External.Call.Types
  import Kernel.External.Encryption
  import Kernel.Prelude
  import qualified Kernel.Prelude
  import Kernel.Types.Error
  import qualified Kernel.Types.Id
  import Kernel.Utils.Common (CacheFlow, EsqDBFlow, MonadFlow, fromMaybeM, getCurrentTime)
  import qualified Sequelize as Se
  import qualified Storage.Beam.CallStatus as Beam
  import Storage.Queries.CallStatusExtra as ReExport
  
  createMany :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => ([Domain.Types.CallStatus.CallStatus] -> m ())
  createMany = traverse_ create
  
  findByCallId :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Kernel.Prelude.Text -> m (Maybe Domain.Types.CallStatus.CallStatus))
  findByCallId callId = do findOneWithKV [Se.Is Beam.callId $ Se.Eq callId]
  
  findById :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m (Maybe Domain.Types.CallStatus.CallStatus))
  findById id = do findOneWithKV [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]
  
  updateAiCallAnalyzed :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Kernel.Prelude.Maybe Kernel.Prelude.Bool -> Kernel.Prelude.Text -> m ())
  updateAiCallAnalyzed aiCallAnalyzed callId = do updateWithKV [Se.Set Beam.aiCallAnalyzed aiCallAnalyzed] [Se.Is Beam.callId $ Se.Eq callId]
  
  updateCallError ::
    (EsqDBFlow m r, MonadFlow m, CacheFlow m r) =>
    (Kernel.Prelude.Maybe Kernel.Prelude.Text -> Kernel.Prelude.Maybe Kernel.External.Call.Types.CallService -> Kernel.Prelude.Maybe Kernel.Prelude.Text -> Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m ())
  updateCallError callError callService merchantId id = do
    updateWithKV
      [ Se.Set Beam.callError callError,
        Se.Set Beam.callService callService,
        Se.Set Beam.merchantId merchantId
      ]
      [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]
  
  updateCallStatus ::
    (EsqDBFlow m r, MonadFlow m, CacheFlow m r) =>
    (Kernel.Prelude.Int -> Kernel.Prelude.Maybe Kernel.Prelude.Text -> Kernel.External.Call.Interface.Types.CallStatus -> Kernel.Prelude.Maybe Domain.Types.CallStatus.CallAttemptStatus -> Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m ())
  updateCallStatus conversationDuration recordingUrl status callAttempt id = do
    updateWithKV
      [ Se.Set Beam.conversationDuration conversationDuration,
        Se.Set Beam.recordingUrl recordingUrl,
        Se.Set Beam.status status,
        Se.Set Beam.callAttempt callAttempt
      ]
      [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]
  
  updateCallStatusCallId :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Kernel.Prelude.Text -> Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m ())
  updateCallStatusCallId callId id = do updateWithKV [Se.Set Beam.callId callId] [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]
  
  updateCallStatusInformation ::
    (EsqDBFlow m r, MonadFlow m, CacheFlow m r) =>
    (Kernel.Prelude.Maybe Kernel.Prelude.Text -> Kernel.Prelude.Maybe Kernel.Prelude.Text -> Kernel.Prelude.Maybe Kernel.External.Call.Types.CallService -> Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m ())
  updateCallStatusInformation dtmfNumberUsed merchantId callService id = do
    updateWithKV
      [ Se.Set Beam.dtmfNumberUsed dtmfNumberUsed,
        Se.Set Beam.merchantId merchantId,
        Se.Set Beam.callService callService
      ]
      [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]
  
  findByPrimaryKey :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Kernel.Types.Id.Id Domain.Types.CallStatus.CallStatus -> m (Maybe Domain.Types.CallStatus.CallStatus))
  findByPrimaryKey id = do findOneWithKV [Se.And [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]]
  
  updateByPrimaryKey :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Domain.Types.CallStatus.CallStatus -> m ())
  updateByPrimaryKey (Domain.Types.CallStatus.CallStatus {..}) = do
    updateWithKV
      [ Se.Set Beam.aiCallAnalyzed aiCallAnalyzed,
        Se.Set Beam.callAttempt callAttempt,
        Se.Set Beam.callError callError,
        Se.Set Beam.callId callId,
        Se.Set Beam.callService callService,
        Se.Set Beam.conversationDuration conversationDuration,
        Se.Set Beam.createdAt createdAt,
        Se.Set Beam.dtmfNumberUsed dtmfNumberUsed,
        Se.Set Beam.entityId entityId,
        Se.Set Beam.merchantId merchantId,
        Se.Set Beam.merchantOperatingCityId (Kernel.Types.Id.getId <$> merchantOperatingCityId),
        Se.Set Beam.recordingUrl recordingUrl,
        Se.Set Beam.status status
      ]
      [Se.And [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]]
  