Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

64.7 KB
Raw Blame
use error_stack::{report, ResultExt};
use router_env::instrument;
use storage_impl::{utils::pg_connection_read_replica, MockDb};

use super::Store;
use crate::{
    connection,
    core::errors::{self, CustomResult},
    db::kafka_store::KafkaStore,
    types::storage,
};

#[router_derive::track_async_interface]
#[async_trait::async_trait]
pub trait BlocklistInterface {
    async fn insert_blocklist_entry(
        &self,
        pm_blocklist_new: storage::BlocklistNew,
    ) -> CustomResult<storage::Blocklist, errors::StorageError>;

    async fn find_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError>;

    /// Returns matching fingerprint rows for the resolved profile and merchant-wide entries.
    /// An omitted transaction type includes every namespace; legacy NULL rows match payment.
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    async fn find_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError>;

    async fn find_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_ids(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_ids: Vec<String>,
    ) -> CustomResult<Option<storage::Blocklist>, errors::StorageError>;

    /// Batched BIN-only lookup: every BIN-kind blocklist entry for this merchant/profile
    /// whose BIN is in `card_bins`, in a single query. PAN-fingerprint entries are excluded.
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_card_bins(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        card_bins: Vec<String>,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    async fn delete_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError>;

    async fn delete_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError>;

    /// `profile_id` is `None` for any caller that has no resolved profile - publishable-key and
    /// SDK auth, and an API key used without `X-Profile-Id`. Unlike the write paths, listing does
    /// not fall back to the default profile or error; absent means merchant-wide, as before
    /// profile scoping.
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    /// `""` reads from the beginning; `snapshot_at` excludes anything blocked after it.
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    /// The same page over rows written before `processor_merchant_id` existed.
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    /// Same scan as above but with no `transaction_type` filter; used when cloning all types.
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id_all_types(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    /// Same scan as above but with no `transaction_type` filter; used when cloning all types.
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id_all_types(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    async fn get_blocklist_entries_count_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError>;

    /// Counts blocklist entries grouped by fingerprint length, computed via a SQL `GROUP BY`
    /// rather than fetching every row - backs `/blocklist/count`'s `counts_by_length`.
    async fn count_blocklist_entries_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<Vec<(i32, i64)>, errors::StorageError>;

    async fn list_blocklist_entries_by_processor_merchant_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    async fn list_blocklist_entries_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError>;

    async fn get_blocklist_entries_count_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError>;

    /// Bulk insert entries with `ON CONFLICT DO NOTHING`.
    /// Returns the number of rows *newly* inserted.
    /// Rows already present are silently skipped (not an error).
    async fn bulk_insert_blocklist_entries(
        &self,
        entries: Vec<storage::BlocklistNew>,
    ) -> CustomResult<usize, errors::StorageError>;
}

#[async_trait::async_trait]
impl BlocklistInterface for Store {
    #[instrument(skip_all)]
    async fn insert_blocklist_entry(
        &self,
        pm_blocklist: storage::BlocklistNew,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        let conn = connection::pg_connection_write(self).await?;
        pm_blocklist
            .insert(&conn)
            .await
            .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            Some(common_enums::BlocklistTransactionType::Payment) => {
                storage::Blocklist::list_by_processor_merchant_id_profile_id_fingerprint_id_for_payment(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    fingerprint_id,
                )
                .await
            }
            Some(common_enums::BlocklistTransactionType::Payout) => {
                storage::Blocklist::list_by_processor_merchant_id_profile_id_fingerprint_id_for_payout(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    fingerprint_id,
                )
                .await
            }
            None => {
                storage::Blocklist::list_all_by_processor_merchant_id_profile_id_fingerprint_id(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    fingerprint_id,
                )
                .await
            }
        }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        // Stagger release fallback: first try processor_merchant_id, if not found fallback to merchant_id
        // For old records processor_merchant_id is NULL, so we use merchant_id (which has the same value)
        let result = match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::find_by_processor_merchant_id_fingerprint_id_for_payment(
                    &conn,
                    processor_merchant_id,
                    fingerprint_id,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::find_by_processor_merchant_id_fingerprint_id_for_payout(
                    &conn,
                    processor_merchant_id,
                    fingerprint_id,
                )
                .await
            }
        };

        match result {
            Ok(blocklist_entry) => Ok(blocklist_entry),
            Err(error) => {
                if matches!(
                    error.current_context(),
                    diesel_models::errors::DatabaseError::NotFound
                ) {
                    match transaction_type {
                        common_enums::BlocklistTransactionType::Payment => {
                            storage::Blocklist::find_by_merchant_id_fingerprint_id_for_payment(
                                &conn,
                                processor_merchant_id,
                                fingerprint_id,
                            )
                            .await
                        }
                        common_enums::BlocklistTransactionType::Payout => {
                            storage::Blocklist::find_by_merchant_id_fingerprint_id_for_payout(
                                &conn,
                                processor_merchant_id,
                                fingerprint_id,
                            )
                            .await
                        }
                    }
                    .map_err(|error| report!(errors::StorageError::from(error)))
                } else {
                    Err(report!(errors::StorageError::from(error)))
                }
            }
        }
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        let result = match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::find_by_processor_merchant_id_profile_id_fingerprint_id_for_payment(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    fingerprint_id,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::find_by_processor_merchant_id_profile_id_fingerprint_id_for_payout(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    fingerprint_id,
                )
                .await
            }
        };

        match result {
            Ok(blocklist_entry) => Ok(blocklist_entry),
            Err(error) => {
                if matches!(
                    error.current_context(),
                    diesel_models::errors::DatabaseError::NotFound
                ) {
                    match transaction_type {
                                common_enums::BlocklistTransactionType::Payment => {
                                    storage::Blocklist::find_by_merchant_id_profile_id_fingerprint_id_for_payment(
                                        &conn,
                                        processor_merchant_id,
                                        profile_id,
                                        fingerprint_id,
                                    ).await
                                }
                                common_enums::BlocklistTransactionType::Payout => {
                                    storage::Blocklist::find_by_merchant_id_profile_id_fingerprint_id_for_payout(
                                        &conn,
                                        processor_merchant_id,
                                        profile_id,
                                        fingerprint_id,
                                    ).await
                                }
                            }
                    .map_err(|error| report!(errors::StorageError::from(error)))
                } else {
                    Err(report!(errors::StorageError::from(error)))
                }
            }
        }
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_ids(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_ids: Vec<String>,
    ) -> CustomResult<Option<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
                    common_enums::BlocklistTransactionType::Payment => {
                        storage::Blocklist::find_by_processor_merchant_id_profile_id_fingerprint_ids_for_payment(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            fingerprint_ids,
                        ).await
                    }
                    common_enums::BlocklistTransactionType::Payout => {
                        storage::Blocklist::find_by_processor_merchant_id_profile_id_fingerprint_ids_for_payout(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            fingerprint_ids,
                        ).await
                    }
                }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_card_bins(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        card_bins: Vec<String>,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::find_by_processor_merchant_id_profile_id_card_bins_for_payment(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    card_bins,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::find_by_processor_merchant_id_profile_id_card_bins_for_payout(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    card_bins,
                )
                .await
            }
        }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::list_by_processor_merchant_id_for_payment(
                    &conn,
                    processor_merchant_id,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::list_by_processor_merchant_id_for_payout(
                    &conn,
                    processor_merchant_id,
                )
                .await
            }
        }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::list_by_processor_merchant_id_data_kind_for_payment(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                    limit,
                    offset,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::list_by_processor_merchant_id_data_kind_for_payout(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                    limit,
                    offset,
                )
                .await
            }
        }
        .change_context(errors::StorageError::DatabaseError(report!(
            diesel_models::errors::DatabaseError::Others
        )))
    }

    #[instrument(skip_all)]
    async fn get_blocklist_entries_count_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::get_count_by_processor_merchant_id_data_kind_for_payment(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::get_count_by_processor_merchant_id_data_kind_for_payout(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                )
                .await
            }
        }
        .change_context(errors::StorageError::DatabaseError(report!(
            diesel_models::errors::DatabaseError::Others
        )))
    }

    #[instrument(skip_all)]
    async fn delete_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        let conn = connection::pg_connection_write(self).await?;
        // Stagger release fallback: first try processor_merchant_id, if not found fallback to merchant_id
        // For old records processor_merchant_id is NULL, so we delete by merchant_id (which has the same value)
        let result = match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::delete_by_processor_merchant_id_fingerprint_id_for_payment(
                    &conn,
                    processor_merchant_id,
                    fingerprint_id,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::delete_by_processor_merchant_id_fingerprint_id_for_payout(
                    &conn,
                    processor_merchant_id,
                    fingerprint_id,
                )
                .await
            }
        };

        match result {
            Ok(blocklist) => Ok(blocklist),
            Err(error) => {
                if matches!(
                    error.current_context(),
                    diesel_models::errors::DatabaseError::NotFound
                ) {
                    match transaction_type {
                        common_enums::BlocklistTransactionType::Payment => {
                            storage::Blocklist::delete_by_merchant_id_fingerprint_id_for_payment(
                                &conn,
                                processor_merchant_id,
                                fingerprint_id,
                            )
                            .await
                        }
                        common_enums::BlocklistTransactionType::Payout => {
                            storage::Blocklist::delete_by_merchant_id_fingerprint_id_for_payout(
                                &conn,
                                processor_merchant_id,
                                fingerprint_id,
                            )
                            .await
                        }
                    }
                    .map_err(|error| report!(errors::StorageError::from(error)))
                } else {
                    Err(report!(errors::StorageError::from(error)))
                }
            }
        }
    }

    #[instrument(skip_all)]
    async fn delete_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        let conn = connection::pg_connection_write(self).await?;
        let result = match transaction_type {
                    common_enums::BlocklistTransactionType::Payment => {
                        storage::Blocklist::delete_by_processor_merchant_id_profile_id_fingerprint_id_for_payment(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            fingerprint_id,
                        ).await
                    }
                    common_enums::BlocklistTransactionType::Payout => {
                        storage::Blocklist::delete_by_processor_merchant_id_profile_id_fingerprint_id_for_payout(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            fingerprint_id,
                        ).await
                    }
                };

        match result {
            Ok(blocklist) => Ok(blocklist),
            Err(error) => {
                if matches!(
                    error.current_context(),
                    diesel_models::errors::DatabaseError::NotFound
                ) {
                    match transaction_type {
                                common_enums::BlocklistTransactionType::Payment => {
                                    storage::Blocklist::delete_by_merchant_id_profile_id_fingerprint_id_for_payment(
                                        &conn,
                                        processor_merchant_id,
                                        profile_id,
                                        fingerprint_id,
                                    ).await
                                }
                                common_enums::BlocklistTransactionType::Payout => {
                                    storage::Blocklist::delete_by_merchant_id_profile_id_fingerprint_id_for_payout(
                                        &conn,
                                        processor_merchant_id,
                                        profile_id,
                                        fingerprint_id,
                                    ).await
                                }
                            }
                    .map_err(|error| report!(errors::StorageError::from(error)))
                } else {
                    Err(report!(errors::StorageError::from(error)))
                }
            }
        }
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match profile_id {
            Some(profile_id) => match transaction_type {
                common_enums::BlocklistTransactionType::Payment => {
                    storage::Blocklist::list_by_processor_merchant_id_profile_id_data_kind_for_payment(
                        &conn,
                        processor_merchant_id,
                        profile_id,
                        data_kind,
                        limit,
                        offset,
                    )
                    .await
                }
                common_enums::BlocklistTransactionType::Payout => {
                    storage::Blocklist::list_by_processor_merchant_id_profile_id_data_kind_for_payout(
                        &conn,
                        processor_merchant_id,
                        profile_id,
                        data_kind,
                        limit,
                        offset,
                    )
                    .await
                }
            },
            None => match transaction_type {
                common_enums::BlocklistTransactionType::Payment => {
                    storage::Blocklist::list_by_processor_merchant_id_data_kind_for_payment(
                        &conn,
                        processor_merchant_id,
                        data_kind,
                        limit,
                        offset,
                    )
                    .await
                }
                common_enums::BlocklistTransactionType::Payout => {
                    storage::Blocklist::list_by_processor_merchant_id_data_kind_for_payout(
                        &conn,
                        processor_merchant_id,
                        data_kind,
                        limit,
                        offset,
                    )
                    .await
                }
            },
        }
        .change_context(errors::StorageError::DatabaseError(report!(
            diesel_models::errors::DatabaseError::Others
        )))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = pg_connection_read_replica(self).await?;
        match transaction_type {
                    common_enums::BlocklistTransactionType::Payment => {
                        storage::Blocklist::list_after_fingerprint_by_processor_merchant_id_profile_id_for_payment(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            after_fingerprint_id,
                            snapshot_at,
                            limit,
                        ).await
                    }
                    common_enums::BlocklistTransactionType::Payout => {
                        storage::Blocklist::list_after_fingerprint_by_processor_merchant_id_profile_id_for_payout(
                            &conn,
                            processor_merchant_id,
                            profile_id,
                            after_fingerprint_id,
                            snapshot_at,
                            limit,
                        ).await
                    }
                }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = pg_connection_read_replica(self).await?;
        match transaction_type {
            common_enums::BlocklistTransactionType::Payment => {
                storage::Blocklist::list_after_fingerprint_by_legacy_merchant_id_profile_id_for_payment(
                    &conn,
                    merchant_id,
                    profile_id,
                    after_fingerprint_id,
                    snapshot_at,
                    limit,
                )
                .await
            }
            common_enums::BlocklistTransactionType::Payout => {
                storage::Blocklist::list_after_fingerprint_by_legacy_merchant_id_profile_id_for_payout(
                    &conn,
                    merchant_id,
                    profile_id,
                    after_fingerprint_id,
                    snapshot_at,
                    limit,
                )
                .await
            }
        }
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id_all_types(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = pg_connection_read_replica(self).await?;
        storage::Blocklist::list_all_after_fingerprint_by_processor_merchant_id_profile_id(
            &conn,
            processor_merchant_id,
            profile_id,
            after_fingerprint_id,
            snapshot_at,
            limit,
        )
        .await
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id_all_types(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let conn = pg_connection_read_replica(self).await?;
        storage::Blocklist::list_all_after_fingerprint_by_legacy_merchant_id_profile_id(
            &conn,
            merchant_id,
            profile_id,
            after_fingerprint_id,
            snapshot_at,
            limit,
        )
        .await
        .map_err(|error| report!(errors::StorageError::from(error)))
    }

    #[instrument(skip_all)]
    async fn get_blocklist_entries_count_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match (profile_id, transaction_type) {
            (Some(profile_id), Some(common_enums::BlocklistTransactionType::Payment)) => {
                storage::Blocklist::get_count_by_processor_merchant_id_profile_id_data_kind_for_payment(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    data_kind,
                )
                .await
            }
            (Some(profile_id), Some(common_enums::BlocklistTransactionType::Payout)) => {
                storage::Blocklist::get_count_by_processor_merchant_id_profile_id_data_kind_for_payout(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    data_kind,
                )
                .await
            }
            (Some(profile_id), None) => {
                storage::Blocklist::get_all_count_by_processor_merchant_id_profile_id_data_kind(
                    &conn,
                    processor_merchant_id,
                    profile_id,
                    data_kind,
                )
                .await
            }
            (None, Some(common_enums::BlocklistTransactionType::Payment)) => {
                storage::Blocklist::get_count_by_processor_merchant_id_data_kind_for_payment(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                )
                .await
            }
            (None, Some(common_enums::BlocklistTransactionType::Payout)) => {
                storage::Blocklist::get_count_by_processor_merchant_id_data_kind_for_payout(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                )
                .await
            }
            (None, None) => {
                storage::Blocklist::get_all_count_by_processor_merchant_id_data_kind(
                    &conn,
                    processor_merchant_id,
                    data_kind,
                )
                .await
            }
        }
        .change_context(errors::StorageError::DatabaseError(report!(
            diesel_models::errors::DatabaseError::Others
        )))
    }

    #[instrument(skip_all)]
    async fn count_blocklist_entries_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<Vec<(i32, i64)>, errors::StorageError> {
        let conn = connection::pg_connection_read(self).await?;
        match transaction_type {
            Some(common_enums::BlocklistTransactionType::Payment) => {
                storage::Blocklist::count_by_fingerprint_length_processor_merchant_id_profile_id_data_kind_for_payment(
                    &conn, processor_merchant_id, profile_id, data_kind,
                ).await
            }
            Some(common_enums::BlocklistTransactionType::Payout) => {
                storage::Blocklist::count_by_fingerprint_length_processor_merchant_id_profile_id_data_kind_for_payout(
                    &conn, processor_merchant_id, profile_id, data_kind,
                ).await
            }
            None => {
                storage::Blocklist::count_all_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(
                    &conn, processor_merchant_id, profile_id, data_kind,
                ).await
            }
        }
        .change_context(errors::StorageError::DatabaseError(report!(
            diesel_models::errors::DatabaseError::Others
        )))
    }

    #[instrument(skip_all)]
    async fn bulk_insert_blocklist_entries(
        &self,
        entries: Vec<storage::BlocklistNew>,
    ) -> CustomResult<usize, errors::StorageError> {
        let conn = connection::pg_connection_write(self).await?;
        storage::BlocklistNew::bulk_insert_on_conflict_do_nothing(&conn, entries)
            .await
            .map_err(|error| report!(errors::StorageError::from(error)))
    }
}

#[async_trait::async_trait]
impl BlocklistInterface for MockDb {
    #[instrument(skip_all)]
    async fn insert_blocklist_entry(
        &self,
        _pm_blocklist: storage::BlocklistNew,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        Ok(self
            .blocklists
            .lock()
            .await
            .iter()
            .filter(|entry| {
                (entry.processor_merchant_id.as_ref() == Some(processor_merchant_id)
                    || (entry.processor_merchant_id.is_none()
                        && &entry.merchant_id == processor_merchant_id))
                    && entry.fingerprint_id == fingerprint_id
                    && (entry.profile_id.as_ref() == Some(profile_id) || entry.profile_id.is_none())
                    && transaction_type
                        .map(|transaction_type| {
                            entry.transaction_type.unwrap_or_default() == transaction_type
                        })
                        .unwrap_or(true)
            })
            .cloned()
            .collect())
    }

    async fn find_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn find_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _profile_id: &common_utils::id_type::ProfileId,
        _fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn find_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_ids(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _profile_id: &common_utils::id_type::ProfileId,
        _fingerprint_ids: Vec<String>,
    ) -> CustomResult<Option<storage::Blocklist>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_card_bins(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _profile_id: &common_utils::id_type::ProfileId,
        _card_bins: Vec<String>,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_by_processor_merchant_id(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_by_processor_merchant_id_data_kind(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _data_kind: common_enums::BlocklistDataKind,
        _limit: i64,
        _offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn get_blocklist_entries_count_by_processor_merchant_id_data_kind(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn delete_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn delete_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _profile_id: &common_utils::id_type::ProfileId,
        _fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_data_kind(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: common_enums::BlocklistTransactionType,
        _profile_id: Option<&common_utils::id_type::ProfileId>,
        _data_kind: common_enums::BlocklistDataKind,
        _limit: i64,
        _offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let mut entries = self
            .blocklists
            .lock()
            .await
            .iter()
            .filter(|entry| {
                entry.processor_merchant_id.as_ref() == Some(processor_merchant_id)
                    && entry.transaction_type.unwrap_or_default() == transaction_type
                    && entry.fingerprint_id > after_fingerprint_id
                    && entry.created_at <= snapshot_at
                    && (entry.profile_id.as_ref() == Some(profile_id) || entry.profile_id.is_none())
            })
            .cloned()
            .collect::<Vec<_>>();
        entries.sort_by(|left, right| left.fingerprint_id.cmp(&right.fingerprint_id));
        entries.truncate(usize::try_from(limit).unwrap_or(usize::MAX));
        Ok(entries)
    }

    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let mut entries = self
            .blocklists
            .lock()
            .await
            .iter()
            .filter(|entry| {
                entry.merchant_id == *merchant_id
                    && entry.processor_merchant_id.is_none()
                    && entry.transaction_type.unwrap_or_default() == transaction_type
                    && entry.fingerprint_id > after_fingerprint_id
                    && entry.created_at <= snapshot_at
                    && (entry.profile_id.as_ref() == Some(profile_id) || entry.profile_id.is_none())
            })
            .cloned()
            .collect::<Vec<_>>();
        entries.sort_by(|left, right| left.fingerprint_id.cmp(&right.fingerprint_id));
        entries.truncate(usize::try_from(limit).unwrap_or(usize::MAX));
        Ok(entries)
    }

    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id_all_types(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let mut entries = self
            .blocklists
            .lock()
            .await
            .iter()
            .filter(|entry| {
                entry.processor_merchant_id.as_ref() == Some(processor_merchant_id)
                    && entry.fingerprint_id > after_fingerprint_id
                    && entry.created_at <= snapshot_at
                    && (entry.profile_id.as_ref() == Some(profile_id) || entry.profile_id.is_none())
            })
            .cloned()
            .collect::<Vec<_>>();
        entries.sort_by(|left, right| left.fingerprint_id.cmp(&right.fingerprint_id));
        entries.truncate(usize::try_from(limit).unwrap_or(usize::MAX));
        Ok(entries)
    }

    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id_all_types(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        let mut entries = self
            .blocklists
            .lock()
            .await
            .iter()
            .filter(|entry| {
                entry.merchant_id == *merchant_id
                    && entry.processor_merchant_id.is_none()
                    && entry.fingerprint_id > after_fingerprint_id
                    && entry.created_at <= snapshot_at
                    && (entry.profile_id.as_ref() == Some(profile_id) || entry.profile_id.is_none())
            })
            .cloned()
            .collect::<Vec<_>>();
        entries.sort_by(|left, right| left.fingerprint_id.cmp(&right.fingerprint_id));
        entries.truncate(usize::try_from(limit).unwrap_or(usize::MAX));
        Ok(entries)
    }

    async fn get_blocklist_entries_count_by_processor_merchant_id_profile_id_data_kind(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: Option<common_enums::BlocklistTransactionType>,
        _profile_id: Option<&common_utils::id_type::ProfileId>,
        _data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn count_blocklist_entries_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(
        &self,
        _processor_merchant_id: &common_utils::id_type::MerchantId,
        _transaction_type: Option<common_enums::BlocklistTransactionType>,
        _profile_id: &common_utils::id_type::ProfileId,
        _data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<Vec<(i32, i64)>, errors::StorageError> {
        Err(errors::StorageError::MockDbError)?
    }

    async fn bulk_insert_blocklist_entries(
        &self,
        entries: Vec<storage::BlocklistNew>,
    ) -> CustomResult<usize, errors::StorageError> {
        let mut blocklists = self.blocklists.lock().await;
        let mut inserted = 0usize;
        for entry in entries {
            let already_exists = blocklists.iter().any(|b| {
                ((b.merchant_id == entry.merchant_id && entry.profile_id.is_some())
                    || (entry.processor_merchant_id.is_some()
                        && b.processor_merchant_id == entry.processor_merchant_id))
                    && b.profile_id == entry.profile_id
                    && b.fingerprint_id == entry.fingerprint_id
                    && b.transaction_type == Some(entry.transaction_type)
            });
            if !already_exists {
                blocklists.push(storage::Blocklist {
                    merchant_id: entry.merchant_id,
                    fingerprint_id: entry.fingerprint_id,
                    data_kind: entry.data_kind,
                    metadata: entry.metadata,
                    created_at: entry.created_at,
                    processor_merchant_id: entry.processor_merchant_id,
                    created_by: entry.created_by,
                    profile_id: entry.profile_id,
                    transaction_type: Some(entry.transaction_type),
                });
                inserted += 1;
            }
        }
        Ok(inserted)
    }
}

#[async_trait::async_trait]
impl BlocklistInterface for KafkaStore {
    #[instrument(skip_all)]
    async fn insert_blocklist_entry(
        &self,
        pm_blocklist: storage::BlocklistNew,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        BlocklistInterface::insert_blocklist_entry(&self.diesel_store, pm_blocklist).await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_id(&self.diesel_store,
                processor_merchant_id,
                transaction_type,
                profile_id,
                fingerprint_id,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        BlocklistInterface::find_blocklist_entry_by_processor_merchant_id_fingerprint_id(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            fingerprint_id,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        BlocklistInterface::find_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            profile_id,
            fingerprint_id,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn find_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_ids(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_ids: Vec<String>,
    ) -> CustomResult<Option<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::find_blocklist_entries_by_processor_merchant_id_profile_id_fingerprint_ids(&self.diesel_store,
                processor_merchant_id,
                transaction_type,
                profile_id,
                fingerprint_ids,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_card_bins(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        card_bins: Vec<String>,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_by_processor_merchant_id_profile_id_card_bins(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            profile_id,
            card_bins,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn delete_blocklist_entry_by_processor_merchant_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        BlocklistInterface::delete_blocklist_entry_by_processor_merchant_id_fingerprint_id(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            fingerprint_id,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_by_processor_merchant_id_data_kind(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            data_kind,
            limit,
            offset,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn delete_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        fingerprint_id: &str,
    ) -> CustomResult<storage::Blocklist, errors::StorageError> {
        BlocklistInterface::delete_blocklist_entry_by_processor_merchant_id_profile_id_fingerprint_id(&self.diesel_store,
                processor_merchant_id,
                transaction_type,
                profile_id,
                fingerprint_id,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
        limit: i64,
        offset: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_by_processor_merchant_id_profile_id_data_kind(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            profile_id,
            data_kind,
            limit,
            offset,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id(&self.diesel_store,
                processor_merchant_id,
                transaction_type,
                profile_id,
                after_fingerprint_id,
                snapshot_at,
                limit,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id(&self.diesel_store,
                merchant_id,
                transaction_type,
                profile_id,
                after_fingerprint_id,
                snapshot_at,
                limit,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id_all_types(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_after_fingerprint_by_processor_merchant_id_profile_id_all_types(&self.diesel_store,
                processor_merchant_id,
                profile_id,
                after_fingerprint_id,
                snapshot_at,
                limit,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id_all_types(
        &self,
        merchant_id: &common_utils::id_type::MerchantId,
        profile_id: &common_utils::id_type::ProfileId,
        after_fingerprint_id: String,
        snapshot_at: time::PrimitiveDateTime,
        limit: i64,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_after_fingerprint_by_legacy_merchant_id_profile_id_all_types(&self.diesel_store,
                merchant_id,
                profile_id,
                after_fingerprint_id,
                snapshot_at,
                limit,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn get_blocklist_entries_count_by_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: Option<&common_utils::id_type::ProfileId>,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        BlocklistInterface::get_blocklist_entries_count_by_processor_merchant_id_profile_id_data_kind(&self.diesel_store,
                processor_merchant_id,
                transaction_type,
                profile_id,
                data_kind,
            )
            .await
    }

    #[instrument(skip_all)]
    async fn get_blocklist_entries_count_by_processor_merchant_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<usize, errors::StorageError> {
        BlocklistInterface::get_blocklist_entries_count_by_processor_merchant_id_data_kind(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
            data_kind,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn count_blocklist_entries_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: Option<common_enums::BlocklistTransactionType>,
        profile_id: &common_utils::id_type::ProfileId,
        data_kind: common_enums::BlocklistDataKind,
    ) -> CustomResult<Vec<(i32, i64)>, errors::StorageError> {
        BlocklistInterface::count_blocklist_entries_by_fingerprint_length_processor_merchant_id_profile_id_data_kind(&self.diesel_store,
                        processor_merchant_id,
                        transaction_type,
                        profile_id,
                        data_kind,
                    )
            .await
    }

    #[instrument(skip_all)]
    async fn list_blocklist_entries_by_processor_merchant_id(
        &self,
        processor_merchant_id: &common_utils::id_type::MerchantId,
        transaction_type: common_enums::BlocklistTransactionType,
    ) -> CustomResult<Vec<storage::Blocklist>, errors::StorageError> {
        BlocklistInterface::list_blocklist_entries_by_processor_merchant_id(
            &self.diesel_store,
            processor_merchant_id,
            transaction_type,
        )
        .await
    }

    #[instrument(skip_all)]
    async fn bulk_insert_blocklist_entries(
        &self,
        entries: Vec<storage::BlocklistNew>,
    ) -> CustomResult<usize, errors::StorageError> {
        BlocklistInterface::bulk_insert_blocklist_entries(&self.diesel_store, entries).await
    }
}