Issue:
feat: Add schema to store chat request response

- add schema for chat, to store request and response
- store chats to chat schema asynchronously
- encrypt the sensitive data
- have endpoint to list the chat data and decrypt it properly


Resolution:
<think>
PR Context:
- Title: feat: add hyperswitch ai chats table
- Merged: 2025-09-16T09:14:36Z
- Files changed: 30 files
- Commits: 27 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->

- Store the user query and response from the ai service for the analysis.
- Allow the api only for internal user

### Additional Changes
This pull request introduces support for encrypted chat conversations and adds database models and A
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat: add hyperswitch ai chats table (#8831)
Co-authored-by: Apoorv Dixit <apoorv.dixit@juspay.in>
C
Files to modify:


**crates/api_models/src/chat.rs**
  Add:
    - struct: pub::ChatListRequest
    - struct: pub::ChatConversation
    - struct: pub::ChatListResponse

**crates/api_models/src/events/chat.rs**
  Modify existing code

**crates/common_utils/src/consts.rs**
  Modify existing code

**crates/diesel_models/src/hyperswitch_ai_interaction.rs**
  Add:
    - struct: pub::HyperswitchAiInteraction
    - struct: pub::HyperswitchAiInteractionNew

**crates/diesel_models/src/lib.rs**
  Add:
    - mod: pub::hyperswitch_ai_interaction

**crates/diesel_models/src/query.rs**
  Add:
    - mod: pub::hyperswitch_ai_interaction

**crates/diesel_models/src/query/hyperswitch_ai_interaction.rs**
  Add:
    - function: pub::insert
    - function: pub::filter_by_optional_merchant_id
    - impl: impl HyperswitchAiInteractionNew
    - impl: impl HyperswitchAiInteraction

**crates/diesel_models/src/query/utils.rs**
  Add:
    - function: private::get_local_unique_key
    - impl: impl CompositeKey for <schema::hyperswitch_ai_interaction::table as diesel::Table>::PrimaryKey

**crates/diesel_models/src/schema.rs**
  Modify existing code

**crates/diesel_models/src/schema_v2.rs**
  Modify existing code

**crates/hyperswitch_domain_models/src/chat.rs**
  Modify existing code

**crates/router/src/configs/secrets_transformers.rs**
  Add:
    - function: private::convert_to_raw_secret
    - impl: impl SecretsHandler for settings::ChatSettings

**crates/router/src/configs/settings.rs**
  Modify existing code

**crates/router/src/core/chat.rs**
  Modify existing code

**crates/router/src/core/errors/chat.rs**
  Modify existing code

**crates/router/src/db.rs**
  Add:
    - mod: pub::hyperswitch_ai_interaction

**crates/router/src/db/hyperswitch_ai_interaction.rs**
  Add:
    - function: private::insert_hyperswitch_ai_interaction
    - function: private::list_hyperswitch_ai_interactions
    - function: private::insert_hyperswitch_ai_interaction
    - function: private::list_hyperswitch_ai_interactions
    - trait: pub::HyperswitchAiInteractionInterface
    - impl: impl HyperswitchAiInteractionInterface for Store
    - impl: impl HyperswitchAiInteractionInterface for MockDb

**crates/router/src/db/kafka_store.rs**
  Add:
    - function: private::insert_hyperswitch_ai_interaction
    - function: private::list_hyperswitch_ai_interactions
    - impl: impl HyperswitchAiInteractionInterface for KafkaStore

**crates/router/src/routes/app.rs**
  Modify existing code

**crates/router/src/routes/chat.rs**
  Add:
    - function: pub::get_all_conversations

**crates/router/src/routes/lock_utils.rs**
  Modify existing code

**crates/router/src/types/storage.rs**
  Add:
    - mod: pub::hyperswitch_ai_interaction

**crates/router/src/types/storage/hyperswitch_ai_interaction.rs**
  Modify existing code

**crates/router/src/utils.rs**
  Add:
    - mod: pub::chat

**crates/router/src/utils/chat.rs**
  Add:
    - function: pub::construct_hyperswitch_ai_interaction

**crates/router_env/src/logger/types.rs**
  Modify existing code

**crates/storage_impl/src/mock_db.rs**
  Modify existing code