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/>.
  -}
  {-# OPTIONS_GHC -Wno-dodgy-exports #-}
  {-# OPTIONS_GHC -Wno-orphans #-}
  {-# OPTIONS_GHC -Wno-unused-imports #-}
  
  module Storage.Queries.SubscriptionTransaction (module Storage.Queries.SubscriptionTransaction, module ReExport) where
  
  import qualified Domain.Types.SubscriptionTransaction
  import Kernel.Beam.Functions
  import Kernel.External.Encryption
  import 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.SubscriptionTransaction as Beam
  import Storage.Queries.SubscriptionTransactionExtra as ReExport
  
  create :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => (Domain.Types.SubscriptionTransaction.SubscriptionTransaction -> m ())
  create = createWithKV
  
  createMany :: (EsqDBFlow m r, MonadFlow m, CacheFlow m r) => ([Domain.Types.SubscriptionTransaction.SubscriptionTransaction] -> m ())
  createMany = traverse_ create
  
  findByPrimaryKey ::
    (EsqDBFlow m r, MonadFlow m, CacheFlow m r) =>
    (Kernel.Types.Id.Id Domain.Types.SubscriptionTransaction.SubscriptionTransaction -> m (Maybe Domain.Types.SubscriptionTransaction.SubscriptionTransaction))
  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.SubscriptionTransaction.SubscriptionTransaction -> m ())
  updateByPrimaryKey (Domain.Types.SubscriptionTransaction.SubscriptionTransaction {..}) = do
    _now <- getCurrentTime
    updateWithKV
      [ Se.Set Beam.amount amount,
        Se.Set Beam.createdAt createdAt,
        Se.Set Beam.driverId (Kernel.Types.Id.getId driverId),
        Se.Set Beam.entityId entityId,
        Se.Set Beam.fromLocationId (Kernel.Types.Id.getId <$> fromLocationId),
        Se.Set Beam.merchantId (Kernel.Types.Id.getId <$> merchantId),
        Se.Set Beam.merchantOperatingCityId (Kernel.Types.Id.getId merchantOperatingCityId),
        Se.Set Beam.runningBalance runningBalance,
        Se.Set Beam.status status,
        Se.Set Beam.toLocationId (Kernel.Types.Id.getId <$> toLocationId),
        Se.Set Beam.transactionType transactionType,
        Se.Set Beam.updatedAt _now
      ]
      [Se.And [Se.Is Beam.id $ Se.Eq (Kernel.Types.Id.getId id)]]
  