// File: crates/diesel_models/src/schema.rs

// @generated automatically by Diesel CLI.

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    address (address_id) {
        #[max_length = 64]
        address_id -> Varchar,
        #[max_length = 128]
        city -> Nullable<Varchar>,
        country -> Nullable<CountryAlpha2>,
        line1 -> Nullable<Bytea>,
        line2 -> Nullable<Bytea>,
        line3 -> Nullable<Bytea>,
        state -> Nullable<Bytea>,
        zip -> Nullable<Bytea>,
        first_name -> Nullable<Bytea>,
        last_name -> Nullable<Bytea>,
        phone_number -> Nullable<Bytea>,
        #[max_length = 8]
        country_code -> Nullable<Varchar>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 64]
        customer_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        payment_id -> Nullable<Varchar>,
        #[max_length = 32]
        updated_by -> Varchar,
        email -> Nullable<Bytea>,
        origin_zip -> Nullable<Bytea>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    api_keys (key_id) {
        #[max_length = 64]
        key_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        name -> Varchar,
        #[max_length = 256]
        description -> Nullable<Varchar>,
        #[max_length = 128]
        hashed_api_key -> Varchar,
        #[max_length = 16]
        prefix -> Varchar,
        created_at -> Timestamp,
        expires_at -> Nullable<Timestamp>,
        last_used -> Nullable<Timestamp>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    authentication (authentication_id) {
        #[max_length = 64]
        authentication_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        authentication_connector -> Nullable<Varchar>,
        #[max_length = 64]
        connector_authentication_id -> Nullable<Varchar>,
        authentication_data -> Nullable<Jsonb>,
        #[max_length = 64]
        payment_method_id -> Varchar,
        #[max_length = 64]
        authentication_type -> Nullable<Varchar>,
        #[max_length = 64]
        authentication_status -> Varchar,
        #[max_length = 64]
        authentication_lifecycle_status -> Varchar,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        error_message -> Nullable<Text>,
        #[max_length = 64]
        error_code -> Nullable<Varchar>,
        connector_metadata -> Nullable<Jsonb>,
        maximum_supported_version -> Nullable<Jsonb>,
        #[max_length = 64]
        threeds_server_transaction_id -> Nullable<Varchar>,
        #[max_length = 64]
        cavv -> Nullable<Varchar>,
        #[max_length = 64]
        authentication_flow_type -> Nullable<Varchar>,
        message_version -> Nullable<Jsonb>,
        #[max_length = 64]
        eci -> Nullable<Varchar>,
        #[max_length = 64]
        trans_status -> Nullable<Varchar>,
        #[max_length = 64]
        acquirer_bin -> Nullable<Varchar>,
        #[max_length = 64]
        acquirer_merchant_id -> Nullable<Varchar>,
        three_ds_method_data -> Nullable<Varchar>,
        three_ds_method_url -> Nullable<Varchar>,
        acs_url -> Nullable<Varchar>,
        challenge_request -> Nullable<Varchar>,
        acs_reference_number -> Nullable<Varchar>,
        acs_trans_id -> Nullable<Varchar>,
        acs_signed_content -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 255]
        payment_id -> Nullable<Varchar>,
        #[max_length = 128]
        merchant_connector_id -> Nullable<Varchar>,
        #[max_length = 64]
        ds_trans_id -> Nullable<Varchar>,
        #[max_length = 128]
        directory_server_id -> Nullable<Varchar>,
        #[max_length = 64]
        acquirer_country_code -> Nullable<Varchar>,
        service_details -> Nullable<Jsonb>,
        #[max_length = 32]
        organization_id -> Varchar,
        #[max_length = 128]
        authentication_client_secret -> Nullable<Varchar>,
        force_3ds_challenge -> Nullable<Bool>,
        psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
        #[max_length = 2048]
        return_url -> Nullable<Varchar>,
        amount -> Nullable<Int8>,
        currency -> Nullable<Currency>,
        billing_address -> Nullable<Bytea>,
        shipping_address -> Nullable<Bytea>,
        browser_info -> Nullable<Jsonb>,
        email -> Nullable<Bytea>,
        #[max_length = 128]
        profile_acquirer_id -> Nullable<Varchar>,
        challenge_code -> Nullable<Varchar>,
        challenge_cancel -> Nullable<Varchar>,
        challenge_code_reason -> Nullable<Varchar>,
        message_extension -> Nullable<Jsonb>,
        #[max_length = 255]
        challenge_request_key -> Nullable<Varchar>,
        customer_details -> Nullable<Bytea>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    blocklist (merchant_id, fingerprint_id) {
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        fingerprint_id -> Varchar,
        data_kind -> BlocklistDataKind,
        metadata -> Nullable<Jsonb>,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    blocklist_fingerprint (merchant_id, fingerprint_id) {
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        fingerprint_id -> Varchar,
        data_kind -> BlocklistDataKind,
        encrypted_fingerprint -> Text,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    blocklist_lookup (merchant_id, fingerprint) {
        #[max_length = 64]
        merchant_id -> Varchar,
        fingerprint -> Text,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    business_profile (profile_id) {
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        profile_name -> Varchar,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        return_url -> Nullable<Text>,
        enable_payment_response_hash -> Bool,
        #[max_length = 255]
        payment_response_hash_key -> Nullable<Varchar>,
        redirect_to_merchant_with_http_post -> Bool,
        webhook_details -> Nullable<Json>,
        metadata -> Nullable<Json>,
        routing_algorithm -> Nullable<Json>,
        intent_fulfillment_time -> Nullable<Int8>,
        frm_routing_algorithm -> Nullable<Jsonb>,
        payout_routing_algorithm -> Nullable<Jsonb>,
        is_recon_enabled -> Bool,
        applepay_verified_domains -> Nullable<Array<Nullable<Text>>>,
        payment_link_config -> Nullable<Jsonb>,
        session_expiry -> Nullable<Int8>,
        authentication_connector_details -> Nullable<Jsonb>,
        payout_link_config -> Nullable<Jsonb>,
        is_extended_card_info_enabled -> Nullable<Bool>,
        extended_card_info_config -> Nullable<Jsonb>,
        is_connector_agnostic_mit_enabled -> Nullable<Bool>,
        use_billing_as_payment_method_billing -> Nullable<Bool>,
        collect_shipping_details_from_wallet_connector -> Nullable<Bool>,
        collect_billing_details_from_wallet_connector -> Nullable<Bool>,
        outgoing_webhook_custom_http_headers -> Nullable<Bytea>,
        always_collect_billing_details_from_wallet_connector -> Nullable<Bool>,
        always_collect_shipping_details_from_wallet_connector -> Nullable<Bool>,
        #[max_length = 64]
        tax_connector_id -> Nullable<Varchar>,
        is_tax_connector_enabled -> Nullable<Bool>,
        version -> ApiVersion,
        dynamic_routing_algorithm -> Nullable<Json>,
        is_network_tokenization_enabled -> Bool,
        is_auto_retries_enabled -> Nullable<Bool>,
        max_auto_retries_enabled -> Nullable<Int2>,
        always_request_extended_authorization -> Nullable<Bool>,
        is_click_to_pay_enabled -> Bool,
        authentication_product_ids -> Nullable<Jsonb>,
        card_testing_guard_config -> Nullable<Jsonb>,
        card_testing_secret_key -> Nullable<Bytea>,
        is_clear_pan_retries_enabled -> Bool,
        force_3ds_challenge -> Nullable<Bool>,
        is_debit_routing_enabled -> Bool,
        merchant_business_country -> Nullable<CountryAlpha2>,
        #[max_length = 64]
        id -> Nullable<Varchar>,
        is_iframe_redirection_enabled -> Nullable<Bool>,
        is_pre_network_tokenization_enabled -> Nullable<Bool>,
        three_ds_decision_rule_algorithm -> Nullable<Jsonb>,
        acquirer_config_map -> Nullable<Jsonb>,
        #[max_length = 16]
        merchant_category_code -> Nullable<Varchar>,
        #[max_length = 32]
        merchant_country_code -> Nullable<Varchar>,
        dispute_polling_interval -> Nullable<Int4>,
        is_manual_retry_enabled -> Nullable<Bool>,
        always_enable_overcapture -> Nullable<Bool>,
        #[max_length = 64]
        billing_processor_id -> Nullable<Varchar>,
        is_external_vault_enabled -> Nullable<Bool>,
        external_vault_connector_details -> Nullable<Jsonb>,
        is_l2_l3_enabled -> Nullable<Bool>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    callback_mapper (id, type_) {
        #[max_length = 128]
        id -> Varchar,
        #[sql_name = "type"]
        #[max_length = 64]
        type_ -> Varchar,
        data -> Jsonb,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    captures (capture_id) {
        #[max_length = 64]
        capture_id -> Varchar,
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        status -> CaptureStatus,
        amount -> Int8,
        currency -> Nullable<Currency>,
        #[max_length = 255]
        connector -> Varchar,
        #[max_length = 255]
        error_message -> Nullable<Varchar>,
        #[max_length = 255]
        error_code -> Nullable<Varchar>,
        #[max_length = 255]
        error_reason -> Nullable<Varchar>,
        tax_amount -> Nullable<Int8>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 64]
        authorized_attempt_id -> Varchar,
        #[max_length = 128]
        connector_capture_id -> Nullable<Varchar>,
        capture_sequence -> Int2,
        #[max_length = 128]
        connector_response_reference_id -> Nullable<Varchar>,
        #[max_length = 512]
        connector_capture_data -> Nullable<Varchar>,
        processor_capture_data -> Nullable<Text>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    cards_info (card_iin) {
        #[max_length = 16]
        card_iin -> Varchar,
        card_issuer -> Nullable<Text>,
        card_network -> Nullable<Text>,
        card_type -> Nullable<Text>,
        card_subtype -> Nullable<Text>,
        card_issuing_country -> Nullable<Text>,
        #[max_length = 32]
        bank_code_id -> Nullable<Varchar>,
        #[max_length = 32]
        bank_code -> Nullable<Varchar>,
        #[max_length = 32]
        country_code -> Nullable<Varchar>,
        date_created -> Timestamp,
        last_updated -> Nullable<Timestamp>,
        last_updated_provider -> Nullable<Text>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    configs (key) {
        #[max_length = 255]
        key -> Varchar,
        config -> Text,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    customers (customer_id, merchant_id) {
        #[max_length = 64]
        customer_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        name -> Nullable<Bytea>,
        email -> Nullable<Bytea>,
        phone -> Nullable<Bytea>,
        #[max_length = 8]
        phone_country_code -> Nullable<Varchar>,
        #[max_length = 255]
        description -> Nullable<Varchar>,
        created_at -> Timestamp,
        metadata -> Nullable<Json>,
        connector_customer -> Nullable<Jsonb>,
        modified_at -> Timestamp,
        #[max_length = 64]
        address_id -> Nullable<Varchar>,
        #[max_length = 64]
        default_payment_method_id -> Nullable<Varchar>,
        #[max_length = 64]
        updated_by -> Nullable<Varchar>,
        version -> ApiVersion,
        tax_registration_id -> Nullable<Bytea>,
        #[max_length = 255]
        created_by -> Nullable<Varchar>,
        #[max_length = 255]
        last_modified_by -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    dashboard_metadata (id) {
        id -> Int4,
        #[max_length = 64]
        user_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        org_id -> Varchar,
        data_key -> DashboardMetadata,
        data_value -> Json,
        #[max_length = 64]
        created_by -> Varchar,
        created_at -> Timestamp,
        #[max_length = 64]
        last_modified_by -> Varchar,
        last_modified_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    dispute (dispute_id) {
        #[max_length = 64]
        dispute_id -> Varchar,
        #[max_length = 255]
        amount -> Varchar,
        #[max_length = 255]
        currency -> Varchar,
        dispute_stage -> DisputeStage,
        dispute_status -> DisputeStatus,
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        attempt_id -> Varchar,
        #[max_length = 255]
        merchant_id -> Varchar,
        #[max_length = 255]
        connector_status -> Varchar,
        #[max_length = 255]
        connector_dispute_id -> Varchar,
        #[max_length = 255]
        connector_reason -> Nullable<Varchar>,
        #[max_length = 255]
        connector_reason_code -> Nullable<Varchar>,
        challenge_required_by -> Nullable<Timestamp>,
        connector_created_at -> Nullable<Timestamp>,
        connector_updated_at -> Nullable<Timestamp>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 255]
        connector -> Varchar,
        evidence -> Jsonb,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
        dispute_amount -> Int8,
        #[max_length = 32]
        organization_id -> Varchar,
        dispute_currency -> Nullable<Currency>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    dynamic_routing_stats (attempt_id, merchant_id) {
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        attempt_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        profile_id -> Varchar,
        amount -> Int8,
        #[max_length = 64]
        success_based_routing_connector -> Varchar,
        #[max_length = 64]
        payment_connector -> Varchar,
        currency -> Nullable<Currency>,
        #[max_length = 64]
        payment_method -> Nullable<Varchar>,
        capture_method -> Nullable<CaptureMethod>,
        authentication_type -> Nullable<AuthenticationType>,
        payment_status -> AttemptStatus,
        conclusive_classification -> SuccessBasedRoutingConclusiveState,
        created_at -> Timestamp,
        #[max_length = 64]
        payment_method_type -> Nullable<Varchar>,
        #[max_length = 64]
        global_success_based_connector -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    events (event_id) {
        #[max_length = 64]
        event_id -> Varchar,
        event_type -> EventType,
        event_class -> EventClass,
        is_webhook_notified -> Bool,
        #[max_length = 64]
        primary_object_id -> Varchar,
        primary_object_type -> EventObjectType,
        created_at -> Timestamp,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        business_profile_id -> Nullable<Varchar>,
        primary_object_created_at -> Nullable<Timestamp>,
        #[max_length = 64]
        idempotent_event_id -> Nullable<Varchar>,
        #[max_length = 64]
        initial_attempt_id -> Nullable<Varchar>,
        request -> Nullable<Bytea>,
        response -> Nullable<Bytea>,
        delivery_attempt -> Nullable<WebhookDeliveryAttempt>,
        metadata -> Nullable<Jsonb>,
        is_overall_delivery_successful -> Nullable<Bool>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    file_metadata (file_id, merchant_id) {
        #[max_length = 64]
        file_id -> Varchar,
        #[max_length = 255]
        merchant_id -> Varchar,
        #[max_length = 255]
        file_name -> Nullable<Varchar>,
        file_size -> Int4,
        #[max_length = 255]
        file_type -> Varchar,
        #[max_length = 255]
        provider_file_id -> Nullable<Varchar>,
        #[max_length = 255]
        file_upload_provider -> Nullable<Varchar>,
        available -> Bool,
        created_at -> Timestamp,
        #[max_length = 255]
        connector_label -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    fraud_check (frm_id, attempt_id, payment_id, merchant_id) {
        #[max_length = 64]
        frm_id -> Varchar,
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        attempt_id -> Varchar,
        created_at -> Timestamp,
        #[max_length = 255]
        frm_name -> Varchar,
        #[max_length = 255]
        frm_transaction_id -> Nullable<Varchar>,
        frm_transaction_type -> FraudCheckType,
        frm_status -> FraudCheckStatus,
        frm_score -> Nullable<Int4>,
        frm_reason -> Nullable<Jsonb>,
        #[max_length = 255]
        frm_error -> Nullable<Varchar>,
        payment_details -> Nullable<Jsonb>,
        metadata -> Nullable<Jsonb>,
        modified_at -> Timestamp,
        #[max_length = 64]
        last_step -> Varchar,
        payment_capture_method -> Nullable<CaptureMethod>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    gateway_status_map (connector, flow, sub_flow, code, message) {
        #[max_length = 64]
        connector -> Varchar,
        #[max_length = 64]
        flow -> Varchar,
        #[max_length = 64]
        sub_flow -> Varchar,
        #[max_length = 255]
        code -> Varchar,
        #[max_length = 1024]
        message -> Varchar,
        #[max_length = 64]
        status -> Varchar,
        #[max_length = 64]
        router_error -> Nullable<Varchar>,
        #[max_length = 64]
        decision -> Varchar,
        created_at -> Timestamp,
        last_modified -> Timestamp,
        step_up_possible -> Bool,
        #[max_length = 255]
        unified_code -> Nullable<Varchar>,
        #[max_length = 1024]
        unified_message -> Nullable<Varchar>,
        #[max_length = 64]
        error_category -> Nullable<Varchar>,
        clear_pan_possible -> Bool,
        feature_data -> Nullable<Jsonb>,
        #[max_length = 64]
        feature -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    generic_link (link_id) {
        #[max_length = 64]
        link_id -> Varchar,
        #[max_length = 64]
        primary_reference -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        expiry -> Timestamp,
        link_data -> Jsonb,
        link_status -> Jsonb,
        link_type -> GenericLinkType,
        url -> Text,
        return_url -> Nullable<Text>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    hyperswitch_ai_interaction (id, created_at) {
        #[max_length = 64]
        id -> Varchar,
        #[max_length = 64]
        session_id -> Nullable<Varchar>,
        #[max_length = 64]
        user_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 64]
        org_id -> Nullable<Varchar>,
        #[max_length = 64]
        role_id -> Nullable<Varchar>,
        user_query -> Nullable<Bytea>,
        response -> Nullable<Bytea>,
        database_query -> Nullable<Text>,
        #[max_length = 64]
        interaction_status -> Nullable<Varchar>,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    hyperswitch_ai_interaction_default (id, created_at) {
        #[max_length = 64]
        id -> Varchar,
        #[max_length = 64]
        session_id -> Nullable<Varchar>,
        #[max_length = 64]
        user_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 64]
        org_id -> Nullable<Varchar>,
        #[max_length = 64]
        role_id -> Nullable<Varchar>,
        user_query -> Nullable<Bytea>,
        response -> Nullable<Bytea>,
        database_query -> Nullable<Text>,
        #[max_length = 64]
        interaction_status -> Nullable<Varchar>,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    incremental_authorization (authorization_id, merchant_id) {
        #[max_length = 64]
        authorization_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        payment_id -> Varchar,
        amount -> Int8,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 64]
        status -> Varchar,
        #[max_length = 255]
        error_code -> Nullable<Varchar>,
        error_message -> Nullable<Text>,
        #[max_length = 64]
        connector_authorization_id -> Nullable<Varchar>,
        previously_authorized_amount -> Int8,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    invoice (id) {
        #[max_length = 64]
        id -> Varchar,
        #[max_length = 128]
        subscription_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 128]
        merchant_connector_id -> Varchar,
        #[max_length = 64]
        payment_intent_id -> Nullable<Varchar>,
        #[max_length = 64]
        payment_method_id -> Nullable<Varchar>,
        #[max_length = 64]
        customer_id -> Varchar,
        amount -> Int8,
        #[max_length = 3]
        currency -> Varchar,
        #[max_length = 64]
        status -> Varchar,
        #[max_length = 128]
        provider_name -> Varchar,
        metadata -> Nullable<Jsonb>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 64]
        connector_invoice_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    locker_mock_up (card_id) {
        #[max_length = 255]
        card_id -> Varchar,
        #[max_length = 255]
        external_id -> Varchar,
        #[max_length = 255]
        card_fingerprint -> Varchar,
        #[max_length = 255]
        card_global_fingerprint -> Varchar,
        #[max_length = 255]
        merchant_id -> Varchar,
        #[max_length = 255]
        card_number -> Varchar,
        #[max_length = 255]
        card_exp_year -> Varchar,
        #[max_length = 255]
        card_exp_month -> Varchar,
        #[max_length = 255]
        name_on_card -> Nullable<Varchar>,
        #[max_length = 255]
        nickname -> Nullable<Varchar>,
        #[max_length = 255]
        customer_id -> Nullable<Varchar>,
        duplicate -> Nullable<Bool>,
        #[max_length = 8]
        card_cvc -> Nullable<Varchar>,
        #[max_length = 64]
        payment_method_id -> Nullable<Varchar>,
        enc_card_data -> Nullable<Text>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    mandate (mandate_id) {
        #[max_length = 64]
        mandate_id -> Varchar,
        #[max_length = 64]
        customer_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        payment_method_id -> Varchar,
        mandate_status -> MandateStatus,
        mandate_type -> MandateType,
        customer_accepted_at -> Nullable<Timestamp>,
        #[max_length = 64]
        customer_ip_address -> Nullable<Varchar>,
        #[max_length = 255]
        customer_user_agent -> Nullable<Varchar>,
        #[max_length = 128]
        network_transaction_id -> Nullable<Varchar>,
        #[max_length = 64]
        previous_attempt_id -> Nullable<Varchar>,
        created_at -> Timestamp,
        mandate_amount -> Nullable<Int8>,
        mandate_currency -> Nullable<Currency>,
        amount_captured -> Nullable<Int8>,
        #[max_length = 64]
        connector -> Varchar,
        #[max_length = 128]
        connector_mandate_id -> Nullable<Varchar>,
        start_date -> Nullable<Timestamp>,
        end_date -> Nullable<Timestamp>,
        metadata -> Nullable<Jsonb>,
        connector_mandate_ids -> Nullable<Jsonb>,
        #[max_length = 64]
        original_payment_id -> Nullable<Varchar>,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
        #[max_length = 64]
        updated_by -> Nullable<Varchar>,
        #[max_length = 2048]
        customer_user_agent_extended -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    merchant_account (merchant_id) {
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 255]
        return_url -> Nullable<Varchar>,
        enable_payment_response_hash -> Bool,
        #[max_length = 255]
        payment_response_hash_key -> Nullable<Varchar>,
        redirect_to_merchant_with_http_post -> Bool,
        merchant_name -> Nullable<Bytea>,
        merchant_details -> Nullable<Bytea>,
        webhook_details -> Nullable<Json>,
        sub_merchants_enabled -> Nullable<Bool>,
        #[max_length = 64]
        parent_merchant_id -> Nullable<Varchar>,
        #[max_length = 128]
        publishable_key -> Nullable<Varchar>,
        storage_scheme -> MerchantStorageScheme,
        #[max_length = 64]
        locker_id -> Nullable<Varchar>,
        metadata -> Nullable<Jsonb>,
        routing_algorithm -> Nullable<Json>,
        primary_business_details -> Json,
        intent_fulfillment_time -> Nullable<Int8>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        frm_routing_algorithm -> Nullable<Jsonb>,
        payout_routing_algorithm -> Nullable<Jsonb>,
        #[max_length = 32]
        organization_id -> Varchar,
        is_recon_enabled -> Bool,
        #[max_length = 64]
        default_profile -> Nullable<Varchar>,
        recon_status -> ReconStatus,
        payment_link_config -> Nullable<Jsonb>,
        pm_collect_link_config -> Nullable<Jsonb>,
        version -> ApiVersion,
        is_platform_account -> Bool,
        #[max_length = 64]
        id -> Nullable<Varchar>,
        #[max_length = 64]
        product_type -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_account_type -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    merchant_connector_account (merchant_connector_id) {
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        connector_name -> Varchar,
        connector_account_details -> Bytea,
        test_mode -> Nullable<Bool>,
        disabled -> Nullable<Bool>,
        #[max_length = 128]
        merchant_connector_id -> Varchar,
        payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,
        connector_type -> ConnectorType,
        metadata -> Nullable<Jsonb>,
        #[max_length = 255]
        connector_label -> Nullable<Varchar>,
        business_country -> Nullable<CountryAlpha2>,
        #[max_length = 255]
        business_label -> Nullable<Varchar>,
        #[max_length = 64]
        business_sub_label -> Nullable<Varchar>,
        frm_configs -> Nullable<Jsonb>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        connector_webhook_details -> Nullable<Jsonb>,
        frm_config -> Nullable<Array<Nullable<Jsonb>>>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        applepay_verified_domains -> Nullable<Array<Nullable<Text>>>,
        pm_auth_config -> Nullable<Jsonb>,
        status -> ConnectorStatus,
        additional_merchant_data -> Nullable<Bytea>,
        connector_wallets_details -> Nullable<Bytea>,
        version -> ApiVersion,
        #[max_length = 64]
        id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    merchant_key_store (merchant_id) {
        #[max_length = 64]
        merchant_id -> Varchar,
        key -> Bytea,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    organization (org_id) {
        #[max_length = 32]
        org_id -> Varchar,
        org_name -> Nullable<Text>,
        organization_details -> Nullable<Jsonb>,
        metadata -> Nullable<Jsonb>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 32]
        id -> Nullable<Varchar>,
        organization_name -> Nullable<Text>,
        version -> ApiVersion,
        #[max_length = 64]
        organization_type -> Nullable<Varchar>,
        #[max_length = 64]
        platform_merchant_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payment_attempt (attempt_id, merchant_id) {
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        attempt_id -> Varchar,
        status -> AttemptStatus,
        amount -> Int8,
        currency -> Nullable<Currency>,
        save_to_locker -> Nullable<Bool>,
        #[max_length = 64]
        connector -> Nullable<Varchar>,
        error_message -> Nullable<Text>,
        offer_amount -> Nullable<Int8>,
        surcharge_amount -> Nullable<Int8>,
        tax_amount -> Nullable<Int8>,
        #[max_length = 64]
        payment_method_id -> Nullable<Varchar>,
        payment_method -> Nullable<Varchar>,
        #[max_length = 128]
        connector_transaction_id -> Nullable<Varchar>,
        capture_method -> Nullable<CaptureMethod>,
        capture_on -> Nullable<Timestamp>,
        confirm -> Bool,
        authentication_type -> Nullable<AuthenticationType>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        last_synced -> Nullable<Timestamp>,
        #[max_length = 255]
        cancellation_reason -> Nullable<Varchar>,
        amount_to_capture -> Nullable<Int8>,
        #[max_length = 64]
        mandate_id -> Nullable<Varchar>,
        browser_info -> Nullable<Jsonb>,
        #[max_length = 255]
        error_code -> Nullable<Varchar>,
        #[max_length = 128]
        payment_token -> Nullable<Varchar>,
        connector_metadata -> Nullable<Jsonb>,
        #[max_length = 50]
        payment_experience -> Nullable<Varchar>,
        #[max_length = 64]
        payment_method_type -> Nullable<Varchar>,
        payment_method_data -> Nullable<Jsonb>,
        #[max_length = 64]
        business_sub_label -> Nullable<Varchar>,
        straight_through_algorithm -> Nullable<Jsonb>,
        preprocessing_step_id -> Nullable<Varchar>,
        mandate_details -> Nullable<Jsonb>,
        error_reason -> Nullable<Text>,
        multiple_capture_count -> Nullable<Int2>,
        #[max_length = 128]
        connector_response_reference_id -> Nullable<Varchar>,
        amount_capturable -> Int8,
        #[max_length = 32]
        updated_by -> Varchar,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
        authentication_data -> Nullable<Json>,
        encoded_data -> Nullable<Text>,
        #[max_length = 255]
        unified_code -> Nullable<Varchar>,
        #[max_length = 1024]
        unified_message -> Nullable<Varchar>,
        net_amount -> Nullable<Int8>,
        external_three_ds_authentication_attempted -> Nullable<Bool>,
        #[max_length = 64]
        authentication_connector -> Nullable<Varchar>,
        #[max_length = 64]
        authentication_id -> Nullable<Varchar>,
        mandate_data -> Nullable<Jsonb>,
        #[max_length = 64]
        fingerprint_id -> Nullable<Varchar>,
        #[max_length = 64]
        payment_method_billing_address_id -> Nullable<Varchar>,
        #[max_length = 64]
        charge_id -> Nullable<Varchar>,
        #[max_length = 64]
        client_source -> Nullable<Varchar>,
        #[max_length = 64]
        client_version -> Nullable<Varchar>,
        customer_acceptance -> Nullable<Jsonb>,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 32]
        organization_id -> Varchar,
        #[max_length = 32]
        card_network -> Nullable<Varchar>,
        shipping_cost -> Nullable<Int8>,
        order_tax_amount -> Nullable<Int8>,
        #[max_length = 512]
        connector_transaction_data -> Nullable<Varchar>,
        connector_mandate_detail -> Nullable<Jsonb>,
        request_extended_authorization -> Nullable<Bool>,
        extended_authorization_applied -> Nullable<Bool>,
        capture_before -> Nullable<Timestamp>,
        processor_transaction_data -> Nullable<Text>,
        card_discovery -> Nullable<CardDiscovery>,
        charges -> Nullable<Jsonb>,
        #[max_length = 64]
        issuer_error_code -> Nullable<Varchar>,
        issuer_error_message -> Nullable<Text>,
        #[max_length = 64]
        processor_merchant_id -> Nullable<Varchar>,
        #[max_length = 255]
        created_by -> Nullable<Varchar>,
        setup_future_usage_applied -> Nullable<FutureUsage>,
        routing_approach -> Nullable<RoutingApproach>,
        #[max_length = 255]
        connector_request_reference_id -> Nullable<Varchar>,
        #[max_length = 255]
        network_transaction_id -> Nullable<Varchar>,
        is_overcapture_enabled -> Nullable<Bool>,
        network_details -> Nullable<Jsonb>,
        is_stored_credential -> Nullable<Bool>,
        authorized_amount -> Nullable<Int8>,
        extended_authorization_last_applied_at -> Nullable<Timestamp>,
        #[max_length = 64]
        tokenization -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payment_intent (payment_id, merchant_id) {
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        status -> IntentStatus,
        amount -> Int8,
        currency -> Nullable<Currency>,
        amount_captured -> Nullable<Int8>,
        #[max_length = 64]
        customer_id -> Nullable<Varchar>,
        #[max_length = 255]
        description -> Nullable<Varchar>,
        #[max_length = 255]
        return_url -> Nullable<Varchar>,
        metadata -> Nullable<Jsonb>,
        #[max_length = 64]
        connector_id -> Nullable<Varchar>,
        #[max_length = 64]
        shipping_address_id -> Nullable<Varchar>,
        #[max_length = 64]
        billing_address_id -> Nullable<Varchar>,
        #[max_length = 255]
        statement_descriptor_name -> Nullable<Varchar>,
        #[max_length = 255]
        statement_descriptor_suffix -> Nullable<Varchar>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        last_synced -> Nullable<Timestamp>,
        setup_future_usage -> Nullable<FutureUsage>,
        off_session -> Nullable<Bool>,
        #[max_length = 128]
        client_secret -> Nullable<Varchar>,
        #[max_length = 64]
        active_attempt_id -> Varchar,
        business_country -> Nullable<CountryAlpha2>,
        #[max_length = 64]
        business_label -> Nullable<Varchar>,
        order_details -> Nullable<Array<Nullable<Jsonb>>>,
        allowed_payment_method_types -> Nullable<Json>,
        connector_metadata -> Nullable<Json>,
        feature_metadata -> Nullable<Json>,
        attempt_count -> Int2,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_decision -> Nullable<Varchar>,
        #[max_length = 255]
        payment_link_id -> Nullable<Varchar>,
        payment_confirm_source -> Nullable<PaymentSource>,
        #[max_length = 32]
        updated_by -> Varchar,
        surcharge_applicable -> Nullable<Bool>,
        request_incremental_authorization -> Nullable<RequestIncrementalAuthorization>,
        incremental_authorization_allowed -> Nullable<Bool>,
        authorization_count -> Nullable<Int4>,
        session_expiry -> Nullable<Timestamp>,
        #[max_length = 64]
        fingerprint_id -> Nullable<Varchar>,
        request_external_three_ds_authentication -> Nullable<Bool>,
        charges -> Nullable<Jsonb>,
        frm_metadata -> Nullable<Jsonb>,
        customer_details -> Nullable<Bytea>,
        billing_details -> Nullable<Bytea>,
        #[max_length = 255]
        merchant_order_reference_id -> Nullable<Varchar>,
        shipping_details -> Nullable<Bytea>,
        is_payment_processor_token_flow -> Nullable<Bool>,
        shipping_cost -> Nullable<Int8>,
        #[max_length = 32]
        organization_id -> Varchar,
        tax_details -> Nullable<Jsonb>,
        skip_external_tax_calculation -> Nullable<Bool>,
        request_extended_authorization -> Nullable<Bool>,
        psd2_sca_exemption_type -> Nullable<ScaExemptionType>,
        split_payments -> Nullable<Jsonb>,
        #[max_length = 64]
        platform_merchant_id -> Nullable<Varchar>,
        force_3ds_challenge -> Nullable<Bool>,
        force_3ds_challenge_trigger -> Nullable<Bool>,
        #[max_length = 64]
        processor_merchant_id -> Nullable<Varchar>,
        #[max_length = 255]
        created_by -> Nullable<Varchar>,
        is_iframe_redirection_enabled -> Nullable<Bool>,
        #[max_length = 2048]
        extended_return_url -> Nullable<Varchar>,
        is_payment_id_from_merchant -> Nullable<Bool>,
        #[max_length = 64]
        payment_channel -> Nullable<Varchar>,
        tax_status -> Nullable<Varchar>,
        discount_amount -> Nullable<Int8>,
        shipping_amount_tax -> Nullable<Int8>,
        duty_amount -> Nullable<Int8>,
        order_date -> Nullable<Timestamp>,
        enable_partial_authorization -> Nullable<Bool>,
        enable_overcapture -> Nullable<Bool>,
        #[max_length = 64]
        mit_category -> Nullable<Varchar>,
        billing_descriptor -> Nullable<Jsonb>,
        #[max_length = 64]
        tokenization -> Nullable<Varchar>,
        partner_merchant_identifier_details -> Nullable<Jsonb>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payment_link (payment_link_id) {
        #[max_length = 255]
        payment_link_id -> Varchar,
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 255]
        link_to_pay -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        amount -> Int8,
        currency -> Nullable<Currency>,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        fulfilment_time -> Nullable<Timestamp>,
        #[max_length = 64]
        custom_merchant_name -> Nullable<Varchar>,
        payment_link_config -> Nullable<Jsonb>,
        #[max_length = 255]
        description -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 255]
        secure_link -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payment_methods (payment_method_id) {
        #[max_length = 64]
        customer_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        payment_method_id -> Varchar,
        accepted_currency -> Nullable<Array<Nullable<Currency>>>,
        #[max_length = 32]
        scheme -> Nullable<Varchar>,
        #[max_length = 128]
        token -> Nullable<Varchar>,
        #[max_length = 255]
        cardholder_name -> Nullable<Varchar>,
        #[max_length = 64]
        issuer_name -> Nullable<Varchar>,
        #[max_length = 64]
        issuer_country -> Nullable<Varchar>,
        payer_country -> Nullable<Array<Nullable<Text>>>,
        is_stored -> Nullable<Bool>,
        #[max_length = 32]
        swift_code -> Nullable<Varchar>,
        #[max_length = 128]
        direct_debit_token -> Nullable<Varchar>,
        created_at -> Timestamp,
        last_modified -> Timestamp,
        payment_method -> Nullable<Varchar>,
        #[max_length = 64]
        payment_method_type -> Nullable<Varchar>,
        #[max_length = 128]
        payment_method_issuer -> Nullable<Varchar>,
        payment_method_issuer_code -> Nullable<PaymentMethodIssuerCode>,
        metadata -> Nullable<Json>,
        payment_method_data -> Nullable<Bytea>,
        #[max_length = 64]
        locker_id -> Nullable<Varchar>,
        last_used_at -> Timestamp,
        connector_mandate_details -> Nullable<Jsonb>,
        customer_acceptance -> Nullable<Jsonb>,
        #[max_length = 64]
        status -> Varchar,
        #[max_length = 255]
        network_transaction_id -> Nullable<Varchar>,
        #[max_length = 128]
        client_secret -> Nullable<Varchar>,
        payment_method_billing_address -> Nullable<Bytea>,
        #[max_length = 64]
        updated_by -> Nullable<Varchar>,
        version -> ApiVersion,
        #[max_length = 128]
        network_token_requestor_reference_id -> Nullable<Varchar>,
        #[max_length = 64]
        network_token_locker_id -> Nullable<Varchar>,
        network_token_payment_method_data -> Nullable<Bytea>,
        #[max_length = 64]
        external_vault_source -> Nullable<Varchar>,
        #[max_length = 64]
        vault_type -> Nullable<Varchar>,
        #[max_length = 255]
        created_by -> Nullable<Varchar>,
        #[max_length = 255]
        last_modified_by -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payout_attempt (merchant_id, payout_attempt_id) {
        #[max_length = 64]
        payout_attempt_id -> Varchar,
        #[max_length = 64]
        payout_id -> Varchar,
        #[max_length = 64]
        customer_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        address_id -> Nullable<Varchar>,
        #[max_length = 64]
        connector -> Nullable<Varchar>,
        #[max_length = 128]
        connector_payout_id -> Nullable<Varchar>,
        #[max_length = 64]
        payout_token -> Nullable<Varchar>,
        status -> PayoutStatus,
        is_eligible -> Nullable<Bool>,
        error_message -> Nullable<Text>,
        #[max_length = 64]
        error_code -> Nullable<Varchar>,
        business_country -> Nullable<CountryAlpha2>,
        #[max_length = 64]
        business_label -> Nullable<Varchar>,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
        routing_info -> Nullable<Jsonb>,
        #[max_length = 255]
        unified_code -> Nullable<Varchar>,
        #[max_length = 1024]
        unified_message -> Nullable<Varchar>,
        additional_payout_method_data -> Nullable<Jsonb>,
        #[max_length = 255]
        merchant_order_reference_id -> Nullable<Varchar>,
        payout_connector_metadata -> Nullable<Jsonb>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    payouts (merchant_id, payout_id) {
        #[max_length = 64]
        payout_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        customer_id -> Nullable<Varchar>,
        #[max_length = 64]
        address_id -> Nullable<Varchar>,
        payout_type -> Nullable<PayoutType>,
        #[max_length = 64]
        payout_method_id -> Nullable<Varchar>,
        amount -> Int8,
        destination_currency -> Currency,
        source_currency -> Currency,
        #[max_length = 255]
        description -> Nullable<Varchar>,
        recurring -> Bool,
        auto_fulfill -> Bool,
        #[max_length = 255]
        return_url -> Nullable<Varchar>,
        #[max_length = 64]
        entity_type -> Varchar,
        metadata -> Nullable<Jsonb>,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        attempt_count -> Int2,
        #[max_length = 64]
        profile_id -> Varchar,
        status -> PayoutStatus,
        confirm -> Nullable<Bool>,
        #[max_length = 255]
        payout_link_id -> Nullable<Varchar>,
        #[max_length = 128]
        client_secret -> Nullable<Varchar>,
        #[max_length = 32]
        priority -> Nullable<Varchar>,
        #[max_length = 32]
        organization_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    process_tracker (id) {
        #[max_length = 127]
        id -> Varchar,
        #[max_length = 64]
        name -> Nullable<Varchar>,
        tag -> Array<Nullable<Text>>,
        #[max_length = 64]
        runner -> Nullable<Varchar>,
        retry_count -> Int4,
        schedule_time -> Nullable<Timestamp>,
        #[max_length = 255]
        rule -> Varchar,
        tracking_data -> Json,
        #[max_length = 255]
        business_status -> Varchar,
        status -> ProcessTrackerStatus,
        event -> Array<Nullable<Text>>,
        created_at -> Timestamp,
        updated_at -> Timestamp,
        version -> ApiVersion,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    refund (merchant_id, refund_id) {
        #[max_length = 64]
        internal_reference_id -> Varchar,
        #[max_length = 64]
        refund_id -> Varchar,
        #[max_length = 64]
        payment_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 128]
        connector_transaction_id -> Varchar,
        #[max_length = 64]
        connector -> Varchar,
        #[max_length = 128]
        connector_refund_id -> Nullable<Varchar>,
        #[max_length = 64]
        external_reference_id -> Nullable<Varchar>,
        refund_type -> RefundType,
        total_amount -> Int8,
        currency -> Currency,
        refund_amount -> Int8,
        refund_status -> RefundStatus,
        sent_to_gateway -> Bool,
        refund_error_message -> Nullable<Text>,
        metadata -> Nullable<Json>,
        #[max_length = 128]
        refund_arn -> Nullable<Varchar>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 255]
        description -> Nullable<Varchar>,
        #[max_length = 64]
        attempt_id -> Varchar,
        #[max_length = 255]
        refund_reason -> Nullable<Varchar>,
        refund_error_code -> Nullable<Text>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 32]
        updated_by -> Varchar,
        #[max_length = 32]
        merchant_connector_id -> Nullable<Varchar>,
        charges -> Nullable<Jsonb>,
        #[max_length = 32]
        organization_id -> Varchar,
        #[max_length = 512]
        connector_refund_data -> Nullable<Varchar>,
        #[max_length = 512]
        connector_transaction_data -> Nullable<Varchar>,
        split_refunds -> Nullable<Jsonb>,
        #[max_length = 255]
        unified_code -> Nullable<Varchar>,
        #[max_length = 1024]
        unified_message -> Nullable<Varchar>,
        processor_refund_data -> Nullable<Text>,
        processor_transaction_data -> Nullable<Text>,
        #[max_length = 64]
        issuer_error_code -> Nullable<Varchar>,
        issuer_error_message -> Nullable<Text>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    relay (id) {
        #[max_length = 64]
        id -> Varchar,
        #[max_length = 128]
        connector_resource_id -> Varchar,
        #[max_length = 64]
        connector_id -> Varchar,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        relay_type -> RelayType,
        request_data -> Nullable<Jsonb>,
        status -> RelayStatus,
        #[max_length = 128]
        connector_reference_id -> Nullable<Varchar>,
        #[max_length = 64]
        error_code -> Nullable<Varchar>,
        error_message -> Nullable<Text>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        response_data -> Nullable<Jsonb>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    reverse_lookup (lookup_id) {
        #[max_length = 128]
        lookup_id -> Varchar,
        #[max_length = 128]
        sk_id -> Varchar,
        #[max_length = 128]
        pk_id -> Varchar,
        #[max_length = 128]
        source -> Varchar,
        #[max_length = 32]
        updated_by -> Varchar,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    roles (role_id) {
        #[max_length = 64]
        role_name -> Varchar,
        #[max_length = 64]
        role_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        org_id -> Varchar,
        groups -> Array<Nullable<Text>>,
        scope -> RoleScope,
        created_at -> Timestamp,
        #[max_length = 64]
        created_by -> Varchar,
        last_modified_at -> Timestamp,
        #[max_length = 64]
        last_modified_by -> Varchar,
        #[max_length = 64]
        entity_type -> Varchar,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 64]
        tenant_id -> Varchar,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    routing_algorithm (algorithm_id) {
        #[max_length = 64]
        algorithm_id -> Varchar,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        name -> Varchar,
        #[max_length = 256]
        description -> Nullable<Varchar>,
        kind -> RoutingAlgorithmKind,
        algorithm_data -> Jsonb,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        algorithm_for -> TransactionType,
        #[max_length = 64]
        decision_engine_routing_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    subscription (id) {
        #[max_length = 128]
        id -> Varchar,
        #[max_length = 128]
        status -> Varchar,
        #[max_length = 128]
        billing_processor -> Nullable<Varchar>,
        #[max_length = 128]
        payment_method_id -> Nullable<Varchar>,
        #[max_length = 128]
        merchant_connector_id -> Nullable<Varchar>,
        #[max_length = 128]
        client_secret -> Nullable<Varchar>,
        #[max_length = 128]
        connector_subscription_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Varchar,
        #[max_length = 64]
        customer_id -> Varchar,
        metadata -> Nullable<Jsonb>,
        created_at -> Timestamp,
        modified_at -> Timestamp,
        #[max_length = 64]
        profile_id -> Varchar,
        #[max_length = 128]
        merchant_reference_id -> Nullable<Varchar>,
        #[max_length = 128]
        plan_id -> Nullable<Varchar>,
        #[max_length = 128]
        item_price_id -> Nullable<Varchar>,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    themes (theme_id) {
        #[max_length = 64]
        theme_id -> Varchar,
        #[max_length = 64]
        tenant_id -> Varchar,
        #[max_length = 64]
        org_id -> Nullable<Varchar>,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        #[max_length = 64]
        entity_type -> Varchar,
        #[max_length = 64]
        theme_name -> Varchar,
        #[max_length = 64]
        email_primary_color -> Varchar,
        #[max_length = 64]
        email_foreground_color -> Varchar,
        #[max_length = 64]
        email_background_color -> Varchar,
        #[max_length = 64]
        email_entity_name -> Varchar,
        email_entity_logo_url -> Text,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    unified_translations (unified_code, unified_message, locale) {
        #[max_length = 255]
        unified_code -> Varchar,
        #[max_length = 1024]
        unified_message -> Varchar,
        #[max_length = 255]
        locale -> Varchar,
        #[max_length = 1024]
        translation -> Varchar,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    user_authentication_methods (id) {
        #[max_length = 64]
        id -> Varchar,
        #[max_length = 64]
        auth_id -> Varchar,
        #[max_length = 64]
        owner_id -> Varchar,
        #[max_length = 64]
        owner_type -> Varchar,
        #[max_length = 64]
        auth_type -> Varchar,
        private_config -> Nullable<Bytea>,
        public_config -> Nullable<Jsonb>,
        allow_signup -> Bool,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        #[max_length = 64]
        email_domain -> Varchar,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    user_key_store (user_id) {
        #[max_length = 64]
        user_id -> Varchar,
        key -> Bytea,
        created_at -> Timestamp,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    user_roles (id) {
        id -> Int4,
        #[max_length = 64]
        user_id -> Varchar,
        #[max_length = 64]
        merchant_id -> Nullable<Varchar>,
        #[max_length = 64]
        role_id -> Varchar,
        #[max_length = 64]
        org_id -> Nullable<Varchar>,
        status -> UserStatus,
        #[max_length = 64]
        created_by -> Varchar,
        #[max_length = 64]
        last_modified_by -> Varchar,
        created_at -> Timestamp,
        last_modified -> Timestamp,
        #[max_length = 64]
        profile_id -> Nullable<Varchar>,
        #[max_length = 64]
        entity_id -> Nullable<Varchar>,
        #[max_length = 64]
        entity_type -> Nullable<Varchar>,
        version -> UserRoleVersion,
        #[max_length = 64]
        tenant_id -> Varchar,
    }
}

diesel::table! {
    use diesel::sql_types::*;
    use crate::enums::diesel_exports::*;

    users (user_id) {
        #[max_length = 64]
        user_id -> Varchar,
        #[max_length = 255]
        email -> Varchar,
        #[max_length = 255]
        name -> Varchar,
        #[max_length = 255]
        password -> Nullable<Varchar>,
        is_verified -> Bool,
        created_at -> Timestamp,
        last_modified_at -> Timestamp,
        totp_status -> TotpStatus,
        totp_secret -> Nullable<Bytea>,
        totp_recovery_codes -> Nullable<Array<Nullable<Text>>>,
        last_password_modified_at -> Nullable<Timestamp>,
        lineage_context -> Nullable<Jsonb>,
    }
}

diesel::allow_tables_to_appear_in_same_query!(
    address,
    api_keys,
    authentication,
    blocklist,
    blocklist_fingerprint,
    blocklist_lookup,
    business_profile,
    callback_mapper,
    captures,
    cards_info,
    configs,
    customers,
    dashboard_metadata,
    dispute,
    dynamic_routing_stats,
    events,
    file_metadata,
    fraud_check,
    gateway_status_map,
    generic_link,
    hyperswitch_ai_interaction,
    hyperswitch_ai_interaction_default,
    incremental_authorization,
    invoice,
    locker_mock_up,
    mandate,
    merchant_account,
    merchant_connector_account,
    merchant_key_store,
    organization,
    payment_attempt,
    payment_intent,
    payment_link,
    payment_methods,
    payout_attempt,
    payouts,
    process_tracker,
    refund,
    relay,
    reverse_lookup,
    roles,
    routing_algorithm,
    subscription,
    themes,
    unified_translations,
    user_authentication_methods,
    user_key_store,
    user_roles,
    users,
);


// File: crates/diesel_models/src/generic_link.rs

use common_utils::{
    consts,
    link_utils::{
        EnabledPaymentMethod, GenericLinkStatus, GenericLinkUiConfig, PaymentMethodCollectStatus,
        PayoutLinkData, PayoutLinkStatus,
    },
};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use masking::Secret;
use serde::{Deserialize, Serialize};
use time::{Duration, PrimitiveDateTime};

use crate::{enums as storage_enums, schema::generic_link};

#[derive(
    Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
)]
#[diesel(table_name = generic_link, primary_key(link_id), check_for_backend(diesel::pg::Pg))]
pub struct GenericLink {
    pub link_id: String,
    pub primary_reference: String,
    pub merchant_id: common_utils::id_type::MerchantId,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub last_modified_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub expiry: PrimitiveDateTime,
    pub link_data: serde_json::Value,
    pub link_status: GenericLinkStatus,
    pub link_type: storage_enums::GenericLinkType,
    pub url: Secret<String>,
    pub return_url: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GenericLinkState {
    pub link_id: String,
    pub primary_reference: String,
    pub merchant_id: common_utils::id_type::MerchantId,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub last_modified_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub expiry: PrimitiveDateTime,
    pub link_data: GenericLinkData,
    pub link_status: GenericLinkStatus,
    pub link_type: storage_enums::GenericLinkType,
    pub url: Secret<String>,
    pub return_url: Option<String>,
}

#[derive(
    Clone,
    Debug,
    Eq,
    PartialEq,
    Insertable,
    serde::Serialize,
    serde::Deserialize,
    router_derive::DebugAsDisplay,
)]
#[diesel(table_name = generic_link)]
pub struct GenericLinkNew {
    pub link_id: String,
    pub primary_reference: String,
    pub merchant_id: common_utils::id_type::MerchantId,
    #[serde(with = "common_utils::custom_serde::iso8601::option")]
    pub created_at: Option<PrimitiveDateTime>,
    #[serde(with = "common_utils::custom_serde::iso8601::option")]
    pub last_modified_at: Option<PrimitiveDateTime>,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub expiry: PrimitiveDateTime,
    pub link_data: serde_json::Value,
    pub link_status: GenericLinkStatus,
    pub link_type: storage_enums::GenericLinkType,
    pub url: Secret<String>,
    pub return_url: Option<String>,
}

impl Default for GenericLinkNew {
    fn default() -> Self {
        let now = common_utils::date_time::now();

        Self {
            link_id: String::default(),
            primary_reference: String::default(),
            merchant_id: common_utils::id_type::MerchantId::default(),
            created_at: Some(now),
            last_modified_at: Some(now),
            expiry: now + Duration::seconds(consts::DEFAULT_SESSION_EXPIRY),
            link_data: serde_json::Value::default(),
            link_status: GenericLinkStatus::default(),
            link_type: common_enums::GenericLinkType::default(),
            url: Secret::default(),
            return_url: Option::default(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GenericLinkData {
    PaymentMethodCollect(PaymentMethodCollectLinkData),
    PayoutLink(PayoutLinkData),
}

impl GenericLinkData {
    pub fn get_payment_method_collect_data(&self) -> Result<&PaymentMethodCollectLinkData, String> {
        match self {
            Self::PaymentMethodCollect(pm) => Ok(pm),
            _ => Err("Invalid link type for fetching payment method collect data".to_string()),
        }
    }
    pub fn get_payout_link_data(&self) -> Result<&PayoutLinkData, String> {
        match self {
            Self::PayoutLink(pl) => Ok(pl),
            _ => Err("Invalid link type for fetching payout link data".to_string()),
        }
    }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PaymentMethodCollectLink {
    pub link_id: String,
    pub primary_reference: String,
    pub merchant_id: common_utils::id_type::MerchantId,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub last_modified_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub expiry: PrimitiveDateTime,
    pub link_data: PaymentMethodCollectLinkData,
    pub link_status: PaymentMethodCollectStatus,
    pub link_type: storage_enums::GenericLinkType,
    pub url: Secret<String>,
    pub return_url: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentMethodCollectLinkData {
    pub pm_collect_link_id: String,
    pub customer_id: common_utils::id_type::CustomerId,
    pub link: Secret<String>,
    pub client_secret: Secret<String>,
    pub session_expiry: u32,
    #[serde(flatten)]
    pub ui_config: GenericLinkUiConfig,
    pub enabled_payment_methods: Option<Vec<EnabledPaymentMethod>>,
}

#[derive(Clone, Debug, Identifiable, Queryable, Serialize, Deserialize)]
#[diesel(table_name = generic_link)]
#[diesel(primary_key(link_id))]
pub struct PayoutLink {
    pub link_id: String,
    pub primary_reference: common_utils::id_type::PayoutId,
    pub merchant_id: common_utils::id_type::MerchantId,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub last_modified_at: PrimitiveDateTime,
    #[serde(with = "common_utils::custom_serde::iso8601")]
    pub expiry: PrimitiveDateTime,
    pub link_data: PayoutLinkData,
    pub link_status: PayoutLinkStatus,
    pub link_type: storage_enums::GenericLinkType,
    pub url: Secret<String>,
    pub return_url: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PayoutLinkUpdate {
    StatusUpdate { link_status: PayoutLinkStatus },
}

#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = generic_link)]
pub struct GenericLinkUpdateInternal {
    pub link_status: Option<GenericLinkStatus>,
}

impl From<PayoutLinkUpdate> for GenericLinkUpdateInternal {
    fn from(generic_link_update: PayoutLinkUpdate) -> Self {
        match generic_link_update {
            PayoutLinkUpdate::StatusUpdate { link_status } => Self {
                link_status: Some(GenericLinkStatus::PayoutLink(link_status)),
            },
        }
    }
}


// File: crates/diesel_models/src/unified_translations.rs

//! Translations

use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use time::PrimitiveDateTime;

use crate::schema::unified_translations;

#[derive(Clone, Debug, Queryable, Selectable, Identifiable)]
#[diesel(table_name = unified_translations, primary_key(unified_code, unified_message, locale), check_for_backend(diesel::pg::Pg))]
pub struct UnifiedTranslations {
    pub unified_code: String,
    pub unified_message: String,
    pub locale: String,
    pub translation: String,
    pub created_at: PrimitiveDateTime,
    pub last_modified_at: PrimitiveDateTime,
}
#[derive(Clone, Debug, Insertable)]
#[diesel(table_name = unified_translations)]
pub struct UnifiedTranslationsNew {
    pub unified_code: String,
    pub unified_message: String,
    pub locale: String,
    pub translation: String,
    pub created_at: PrimitiveDateTime,
    pub last_modified_at: PrimitiveDateTime,
}

#[derive(Clone, Debug, AsChangeset)]
#[diesel(table_name = unified_translations)]
pub struct UnifiedTranslationsUpdateInternal {
    pub translation: Option<String>,
    pub last_modified_at: PrimitiveDateTime,
}

#[derive(Debug)]
pub struct UnifiedTranslationsUpdate {
    pub translation: Option<String>,
}

impl From<UnifiedTranslationsUpdate> for UnifiedTranslationsUpdateInternal {
    fn from(value: UnifiedTranslationsUpdate) -> Self {
        let now = common_utils::date_time::now();
        let UnifiedTranslationsUpdate { translation } = value;
        Self {
            translation,
            last_modified_at: now,
        }
    }
}


// File: crates/diesel_models/src/api_keys.rs

use diesel::{AsChangeset, AsExpression, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;

use crate::schema::api_keys;

#[derive(
    serde::Serialize, serde::Deserialize, Debug, Clone, Identifiable, Queryable, Selectable,
)]
#[diesel(table_name = api_keys, primary_key(key_id), check_for_backend(diesel::pg::Pg))]
pub struct ApiKey {
    pub key_id: common_utils::id_type::ApiKeyId,
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: String,
    pub description: Option<String>,
    pub hashed_api_key: HashedApiKey,
    pub prefix: String,
    pub created_at: PrimitiveDateTime,
    pub expires_at: Option<PrimitiveDateTime>,
    pub last_used: Option<PrimitiveDateTime>,
}

#[derive(Debug, Insertable)]
#[diesel(table_name = api_keys)]
pub struct ApiKeyNew {
    pub key_id: common_utils::id_type::ApiKeyId,
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: String,
    pub description: Option<String>,
    pub hashed_api_key: HashedApiKey,
    pub prefix: String,
    pub created_at: PrimitiveDateTime,
    pub expires_at: Option<PrimitiveDateTime>,
    pub last_used: Option<PrimitiveDateTime>,
}

#[derive(Debug)]
pub enum ApiKeyUpdate {
    Update {
        name: Option<String>,
        description: Option<String>,
        expires_at: Option<Option<PrimitiveDateTime>>,
        last_used: Option<PrimitiveDateTime>,
    },
    LastUsedUpdate {
        last_used: PrimitiveDateTime,
    },
}

#[derive(Debug, AsChangeset)]
#[diesel(table_name = api_keys)]
pub(crate) struct ApiKeyUpdateInternal {
    pub name: Option<String>,
    pub description: Option<String>,
    pub expires_at: Option<Option<PrimitiveDateTime>>,
    pub last_used: Option<PrimitiveDateTime>,
}

impl From<ApiKeyUpdate> for ApiKeyUpdateInternal {
    fn from(api_key_update: ApiKeyUpdate) -> Self {
        match api_key_update {
            ApiKeyUpdate::Update {
                name,
                description,
                expires_at,
                last_used,
            } => Self {
                name,
                description,
                expires_at,
                last_used,
            },
            ApiKeyUpdate::LastUsedUpdate { last_used } => Self {
                last_used: Some(last_used),
                name: None,
                description: None,
                expires_at: None,
            },
        }
    }
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, AsExpression, PartialEq)]
#[diesel(sql_type = diesel::sql_types::Text)]
pub struct HashedApiKey(String);

impl HashedApiKey {
    pub fn into_inner(self) -> String {
        self.0
    }
}

impl From<String> for HashedApiKey {
    fn from(hashed_api_key: String) -> Self {
        Self(hashed_api_key)
    }
}

mod diesel_impl {
    use diesel::{
        backend::Backend,
        deserialize::FromSql,
        serialize::{Output, ToSql},
        sql_types::Text,
        Queryable,
    };

    impl<DB> ToSql<Text, DB> for super::HashedApiKey
    where
        DB: Backend,
        String: ToSql<Text, DB>,
    {
        fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> diesel::serialize::Result {
            self.0.to_sql(out)
        }
    }

    impl<DB> FromSql<Text, DB> for super::HashedApiKey
    where
        DB: Backend,
        String: FromSql<Text, DB>,
    {
        fn from_sql(bytes: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
            Ok(Self(String::from_sql(bytes)?))
        }
    }

    impl<DB> Queryable<Text, DB> for super::HashedApiKey
    where
        DB: Backend,
        Self: FromSql<Text, DB>,
    {
        type Row = Self;

        fn build(row: Self::Row) -> diesel::deserialize::Result<Self> {
            Ok(row)
        }
    }
}

// Tracking data by process_tracker
#[derive(Default, Debug, Deserialize, Serialize, Clone)]
pub struct ApiKeyExpiryTrackingData {
    pub key_id: common_utils::id_type::ApiKeyId,
    pub merchant_id: common_utils::id_type::MerchantId,
    pub api_key_name: String,
    pub prefix: String,
    pub api_key_expiry: Option<PrimitiveDateTime>,
    // Days on which email reminder about api_key expiry has to be sent, prior to it's expiry.
    pub expiry_reminder_days: Vec<u8>,
}


// File: crates/diesel_models/src/errors.rs

#[derive(Copy, Clone, Debug, thiserror::Error)]
pub enum DatabaseError {
    #[error("An error occurred when obtaining database connection")]
    DatabaseConnectionError,
    #[error("The requested resource was not found in the database")]
    NotFound,
    #[error("A unique constraint violation occurred")]
    UniqueViolation,
    #[error("No fields were provided to be updated")]
    NoFieldsToUpdate,
    #[error("An error occurred when generating typed SQL query")]
    QueryGenerationFailed,
    // InsertFailed,
    #[error("An unknown error occurred")]
    Others,
}

impl From<diesel::result::Error> for DatabaseError {
    fn from(error: diesel::result::Error) -> Self {
        match error {
            diesel::result::Error::DatabaseError(
                diesel::result::DatabaseErrorKind::UniqueViolation,
                _,
            ) => Self::UniqueViolation,
            diesel::result::Error::NotFound => Self::NotFound,
            diesel::result::Error::QueryBuilderError(_) => Self::QueryGenerationFailed,
            _ => Self::Others,
        }
    }
}


// File: crates/diesel_models/src/customers.rs

use common_enums::ApiVersion;
use common_utils::{encryption::Encryption, pii, types::Description};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use time::PrimitiveDateTime;

#[cfg(feature = "v1")]
use crate::schema::customers;
#[cfg(feature = "v2")]
use crate::{
    diesel_impl::RequiredFromNullableWithDefault, enums::DeleteStatus, schema_v2::customers,
};

#[cfg(feature = "v1")]
#[derive(
    Clone, Debug, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize, Insertable,
)]
#[diesel(table_name = customers)]
pub struct CustomerNew {
    pub customer_id: common_utils::id_type::CustomerId,
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub description: Option<Description>,
    pub phone_country_code: Option<String>,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub connector_customer: Option<pii::SecretSerdeValue>,
    pub created_at: PrimitiveDateTime,
    pub modified_at: PrimitiveDateTime,
    pub address_id: Option<String>,
    pub updated_by: Option<String>,
    pub version: ApiVersion,
    pub tax_registration_id: Option<Encryption>,
    pub created_by: Option<String>,
    pub last_modified_by: Option<String>,
}

#[cfg(feature = "v1")]
impl CustomerNew {
    pub fn update_storage_scheme(&mut self, storage_scheme: common_enums::MerchantStorageScheme) {
        self.updated_by = Some(storage_scheme.to_string());
    }
}

#[cfg(feature = "v1")]
impl From<CustomerNew> for Customer {
    fn from(customer_new: CustomerNew) -> Self {
        Self {
            customer_id: customer_new.customer_id,
            merchant_id: customer_new.merchant_id,
            name: customer_new.name,
            email: customer_new.email,
            phone: customer_new.phone,
            phone_country_code: customer_new.phone_country_code,
            description: customer_new.description,
            created_at: customer_new.created_at,
            metadata: customer_new.metadata,
            connector_customer: customer_new.connector_customer,
            modified_at: customer_new.modified_at,
            address_id: customer_new.address_id,
            default_payment_method_id: None,
            updated_by: customer_new.updated_by,
            version: customer_new.version,
            tax_registration_id: customer_new.tax_registration_id,
            created_by: customer_new.created_by,
            last_modified_by: customer_new.last_modified_by,
        }
    }
}

#[cfg(feature = "v2")]
#[derive(
    Clone, Debug, Insertable, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers, primary_key(id))]
pub struct CustomerNew {
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub phone_country_code: Option<String>,
    pub description: Option<Description>,
    pub created_at: PrimitiveDateTime,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
    pub modified_at: PrimitiveDateTime,
    pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
    pub updated_by: Option<String>,
    pub version: ApiVersion,
    pub tax_registration_id: Option<Encryption>,
    pub merchant_reference_id: Option<common_utils::id_type::CustomerId>,
    pub default_billing_address: Option<Encryption>,
    pub default_shipping_address: Option<Encryption>,
    pub status: DeleteStatus,
    pub id: common_utils::id_type::GlobalCustomerId,
    pub created_by: Option<String>,
    pub last_modified_by: Option<String>,
}

#[cfg(feature = "v2")]
impl CustomerNew {
    pub fn update_storage_scheme(&mut self, storage_scheme: common_enums::MerchantStorageScheme) {
        self.updated_by = Some(storage_scheme.to_string());
    }
}

#[cfg(feature = "v2")]
impl From<CustomerNew> for Customer {
    fn from(customer_new: CustomerNew) -> Self {
        Self {
            merchant_id: customer_new.merchant_id,
            name: customer_new.name,
            email: customer_new.email,
            phone: customer_new.phone,
            phone_country_code: customer_new.phone_country_code,
            description: customer_new.description,
            created_at: customer_new.created_at,
            metadata: customer_new.metadata,
            connector_customer: customer_new.connector_customer,
            modified_at: customer_new.modified_at,
            default_payment_method_id: None,
            updated_by: customer_new.updated_by,
            tax_registration_id: customer_new.tax_registration_id,
            merchant_reference_id: customer_new.merchant_reference_id,
            default_billing_address: customer_new.default_billing_address,
            default_shipping_address: customer_new.default_shipping_address,
            id: customer_new.id,
            version: customer_new.version,
            status: customer_new.status,
            created_by: customer_new.created_by,
            last_modified_by: customer_new.last_modified_by,
        }
    }
}

#[cfg(feature = "v1")]
#[derive(
    Clone, Debug, Identifiable, Queryable, Selectable, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers, primary_key(customer_id, merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct Customer {
    pub customer_id: common_utils::id_type::CustomerId,
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub phone_country_code: Option<String>,
    pub description: Option<Description>,
    pub created_at: PrimitiveDateTime,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub connector_customer: Option<pii::SecretSerdeValue>,
    pub modified_at: PrimitiveDateTime,
    pub address_id: Option<String>,
    pub default_payment_method_id: Option<String>,
    pub updated_by: Option<String>,
    pub version: ApiVersion,
    pub tax_registration_id: Option<Encryption>,
    pub created_by: Option<String>,
    pub last_modified_by: Option<String>,
}

#[cfg(feature = "v2")]
#[derive(
    Clone, Debug, Identifiable, Queryable, Selectable, serde::Serialize, serde::Deserialize,
)]
#[diesel(table_name = customers, primary_key(id))]
pub struct Customer {
    pub merchant_id: common_utils::id_type::MerchantId,
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub phone_country_code: Option<String>,
    pub description: Option<Description>,
    pub created_at: PrimitiveDateTime,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
    pub modified_at: PrimitiveDateTime,
    pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
    pub updated_by: Option<String>,
    pub version: ApiVersion,
    pub tax_registration_id: Option<Encryption>,
    pub created_by: Option<String>,
    pub last_modified_by: Option<String>,
    pub merchant_reference_id: Option<common_utils::id_type::CustomerId>,
    pub default_billing_address: Option<Encryption>,
    pub default_shipping_address: Option<Encryption>,
    #[diesel(deserialize_as = RequiredFromNullableWithDefault<DeleteStatus>)]
    pub status: DeleteStatus,
    pub id: common_utils::id_type::GlobalCustomerId,
}

#[cfg(feature = "v1")]
#[derive(
    Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers)]
pub struct CustomerUpdateInternal {
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub description: Option<Description>,
    pub phone_country_code: Option<String>,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub modified_at: PrimitiveDateTime,
    pub connector_customer: Option<pii::SecretSerdeValue>,
    pub address_id: Option<String>,
    pub default_payment_method_id: Option<Option<String>>,
    pub updated_by: Option<String>,
    pub tax_registration_id: Option<Encryption>,
    pub last_modified_by: Option<String>,
}

#[cfg(feature = "v1")]
impl CustomerUpdateInternal {
    pub fn apply_changeset(self, source: Customer) -> Customer {
        let Self {
            name,
            email,
            phone,
            description,
            phone_country_code,
            metadata,
            connector_customer,
            address_id,
            default_payment_method_id,
            tax_registration_id,
            last_modified_by,
            ..
        } = self;

        Customer {
            name: name.map_or(source.name, Some),
            email: email.map_or(source.email, Some),
            phone: phone.map_or(source.phone, Some),
            description: description.map_or(source.description, Some),
            phone_country_code: phone_country_code.map_or(source.phone_country_code, Some),
            metadata: metadata.map_or(source.metadata, Some),
            modified_at: common_utils::date_time::now(),
            connector_customer: connector_customer.map_or(source.connector_customer, Some),
            address_id: address_id.map_or(source.address_id, Some),
            default_payment_method_id: default_payment_method_id
                .flatten()
                .map_or(source.default_payment_method_id, Some),
            tax_registration_id: tax_registration_id.map_or(source.tax_registration_id, Some),
            last_modified_by: last_modified_by.or(source.last_modified_by),
            ..source
        }
    }
}

#[cfg(feature = "v2")]
#[derive(
    Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers)]
pub struct CustomerUpdateInternal {
    pub name: Option<Encryption>,
    pub email: Option<Encryption>,
    pub phone: Option<Encryption>,
    pub description: Option<Description>,
    pub phone_country_code: Option<String>,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub modified_at: PrimitiveDateTime,
    pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
    pub default_payment_method_id: Option<Option<common_utils::id_type::GlobalPaymentMethodId>>,
    pub updated_by: Option<String>,
    pub default_billing_address: Option<Encryption>,
    pub default_shipping_address: Option<Encryption>,
    pub status: Option<DeleteStatus>,
    pub tax_registration_id: Option<Encryption>,
    pub last_modified_by: Option<String>,
}

#[cfg(feature = "v2")]
impl CustomerUpdateInternal {
    pub fn apply_changeset(self, source: Customer) -> Customer {
        let Self {
            name,
            email,
            phone,
            description,
            phone_country_code,
            metadata,
            connector_customer,
            default_payment_method_id,
            default_billing_address,
            default_shipping_address,
            status,
            tax_registration_id,
            last_modified_by,
            ..
        } = self;

        Customer {
            name: name.map_or(source.name, Some),
            email: email.map_or(source.email, Some),
            phone: phone.map_or(source.phone, Some),
            description: description.map_or(source.description, Some),
            phone_country_code: phone_country_code.map_or(source.phone_country_code, Some),
            metadata: metadata.map_or(source.metadata, Some),
            modified_at: common_utils::date_time::now(),
            connector_customer: connector_customer.map_or(source.connector_customer, Some),
            default_payment_method_id: default_payment_method_id
                .flatten()
                .map_or(source.default_payment_method_id, Some),
            default_billing_address: default_billing_address
                .map_or(source.default_billing_address, Some),
            default_shipping_address: default_shipping_address
                .map_or(source.default_shipping_address, Some),
            status: status.unwrap_or(source.status),
            tax_registration_id: tax_registration_id.map_or(source.tax_registration_id, Some),
            last_modified_by: last_modified_by.or(source.last_modified_by),
            ..source
        }
    }
}


// File: crates/diesel_models/src/gsm.rs

//! Gateway status mapping
use common_enums::ErrorCategory;
use common_utils::{
    custom_serde,
    events::{ApiEventMetric, ApiEventsType},
};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use time::PrimitiveDateTime;

use crate::schema::gateway_status_map;

#[derive(
    Clone,
    Debug,
    Eq,
    PartialEq,
    router_derive::DebugAsDisplay,
    Identifiable,
    Queryable,
    Selectable,
    serde::Serialize,
)]
#[diesel(table_name = gateway_status_map, primary_key(connector, flow, sub_flow, code, message), check_for_backend(diesel::pg::Pg))]
pub struct GatewayStatusMap {
    pub connector: String,
    pub flow: String,
    pub sub_flow: String,
    pub code: String,
    pub message: String,
    pub status: String,
    pub router_error: Option<String>,
    pub decision: String,
    #[serde(with = "custom_serde::iso8601")]
    pub created_at: PrimitiveDateTime,
    #[serde(with = "custom_serde::iso8601")]
    pub last_modified: PrimitiveDateTime,
    pub step_up_possible: bool,
    pub unified_code: Option<String>,
    pub unified_message: Option<String>,
    pub error_category: Option<ErrorCategory>,
    pub clear_pan_possible: bool,
    pub feature_data: Option<common_types::domain::GsmFeatureData>,
    pub feature: Option<common_enums::GsmFeature>,
}

#[derive(Clone, Debug, Eq, PartialEq, Insertable)]
#[diesel(table_name = gateway_status_map)]
pub struct GatewayStatusMappingNew {
    pub connector: String,
    pub flow: String,
    pub sub_flow: String,
    pub code: String,
    pub message: String,
    pub status: String,
    pub router_error: Option<String>,
    pub decision: String,
    pub step_up_possible: bool,
    pub unified_code: Option<String>,
    pub unified_message: Option<String>,
    pub error_category: Option<ErrorCategory>,
    pub clear_pan_possible: bool,
    pub feature_data: Option<common_types::domain::GsmFeatureData>,
    pub feature: Option<common_enums::GsmFeature>,
}

#[derive(
    Clone, Debug, PartialEq, Eq, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize,
)]
#[diesel(table_name = gateway_status_map)]
pub struct GatewayStatusMapperUpdateInternal {
    pub connector: Option<String>,
    pub flow: Option<String>,
    pub sub_flow: Option<String>,
    pub code: Option<String>,
    pub message: Option<String>,
    pub status: Option<String>,
    pub router_error: Option<Option<String>>,
    pub decision: Option<String>,
    pub step_up_possible: Option<bool>,
    pub unified_code: Option<String>,
    pub unified_message: Option<String>,
    pub error_category: Option<ErrorCategory>,
    pub last_modified: PrimitiveDateTime,
    pub clear_pan_possible: Option<bool>,
    pub feature_data: Option<common_types::domain::GsmFeatureData>,
    pub feature: Option<common_enums::GsmFeature>,
}

#[derive(Debug)]
pub struct GatewayStatusMappingUpdate {
    pub status: Option<String>,
    pub router_error: Option<Option<String>>,
    pub decision: Option<String>,
    pub step_up_possible: Option<bool>,
    pub unified_code: Option<String>,
    pub unified_message: Option<String>,
    pub error_category: Option<ErrorCategory>,
    pub clear_pan_possible: Option<bool>,
    pub feature_data: Option<common_types::domain::GsmFeatureData>,
    pub feature: Option<common_enums::GsmFeature>,
}

impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
    fn from(value: GatewayStatusMappingUpdate) -> Self {
        let GatewayStatusMappingUpdate {
            decision,
            status,
            router_error,
            step_up_possible,
            unified_code,
            unified_message,
            error_category,
            clear_pan_possible,
            feature_data,
            feature,
        } = value;
        Self {
            status,
            router_error,
            decision,
            step_up_possible,
            unified_code,
            unified_message,
            error_category,
            last_modified: common_utils::date_time::now(),
            connector: None,
            flow: None,
            sub_flow: None,
            code: None,
            message: None,
            clear_pan_possible,
            feature_data,
            feature,
        }
    }
}

impl ApiEventMetric for GatewayStatusMap {
    fn get_api_event_type(&self) -> Option<ApiEventsType> {
        Some(ApiEventsType::Gsm)
    }
}


// File: crates/diesel_models/src/hyperswitch_ai_interaction.rs

use common_utils::encryption::Encryption;
use diesel::{self, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;

use crate::schema::hyperswitch_ai_interaction;

#[derive(
    Clone,
    Debug,
    Deserialize,
    Identifiable,
    Queryable,
    Selectable,
    Serialize,
    router_derive::DebugAsDisplay,
)]
#[diesel(table_name = hyperswitch_ai_interaction, primary_key(id, created_at), check_for_backend(diesel::pg::Pg))]
pub struct HyperswitchAiInteraction {
    pub id: String,
    pub session_id: Option<String>,
    pub user_id: Option<String>,
    pub merchant_id: Option<String>,
    pub profile_id: Option<String>,
    pub org_id: Option<String>,
    pub role_id: Option<String>,
    pub user_query: Option<Encryption>,
    pub response: Option<Encryption>,
    pub database_query: Option<String>,
    pub interaction_status: Option<String>,
    pub created_at: PrimitiveDateTime,
}

#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = hyperswitch_ai_interaction)]
pub struct HyperswitchAiInteractionNew {
    pub id: String,
    pub session_id: Option<String>,
    pub user_id: Option<String>,
    pub merchant_id: Option<String>,
    pub profile_id: Option<String>,
    pub org_id: Option<String>,
    pub role_id: Option<String>,
    pub user_query: Option<Encryption>,
    pub response: Option<Encryption>,
    pub database_query: Option<String>,
    pub interaction_status: Option<String>,
    pub created_at: PrimitiveDateTime,
}