Issue:
feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [x] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
Introducing OrgLevel, MerchantLevel and ProfileLevel authentication for analytics, the following changes are done:

- refactored the existing MerchantLevel APIs
- introduced new OrgLevel APIs
- introduced new ProfileLevel APIs

The levels are described as:
```bash
    OrgLevel {
        org_id: id_type::OrganizationId,
    },
    MerchantLevel {
        org_id: id_type::OrganizationId,
        merchant_ids: Vec<id_type::MerchantId>,
    },
    ProfileLevel {
        org_id: id_type::OrganizationId,
        merchant_id: id_type::MerchantId,
        profile_ids: Vec<id_type::ProfileId>,
    }
```

- Introduced `ProfileId` as a dimension and filter for analytics:
  - Payments v1
  - Payments v2
  - Refunds
 
- Changed the clickhouse query to search in `UTC timezone` by converting the timestamp into epoch
The API's added are as follows:
- Merchant Level

Merchant Level |  
-- | --
Payment Metrics V1 | /analytics/v1/merchant/metrics/payments
Payment Filters V1 | /analytics/v1/merchant/filters/payments
Refund Metrics | /analytics/v1/merchant/metrics/refunds
Refund Filters | /analytics/v1/merchant/filters/refunds
Payment Report | /analytics/v1/merchant/report/payments
Refund Report | /analytics/v1/merchant/report/refunds
Dispute Report | /analytics/v1/merchant/report/dispute
API Event Metrics | /analytics/v1/merchant/metrics/api_events
API Event Filters | /analytics/v1/merchant/filters/api_events
Dispute Metrics | /analytics/v1/merchant/metrics/disputes
Dispute Filters | /analytics/v1/merchant/filters/disputes
Info | /analytics/v1/merchant/{domain}/info
Payment Metrics V2 | /analytics/v2/merchant/metrics/payments
- Org Level

Org Level |  
-- | --
Payment Metrics V1 | /analytics/v1/org/metrics/payments
Payment Filters V1 | /analytics/v1/org/filters/payments
Refund Metrics | /analytics/v1/org/metrics/refunds
Refund Filters | /analytics/v1/org/filters/refunds
Payment Report | /analytics/v1/org/report/payments
Refund Report | /analytics/v1/org/report/refunds
Dispute Report | /analytics/v1/org/report/dispute
Dispute Metrics | /analytics/v1/org/metrics/disputes
Dispute Filters | /analytics/v1/org/filters/disputes
Info | /analytics/v1/org/{domain}/info
Payment Metrics V2 | /analytics/v2/org/metrics/payments

- Profile Level

Profile Level |  
-- | --
Payment Metrics V1 | /analytics/v1/profile/metrics/payments
Payment Filters V1 | /analytics/v1/profile/filters/payments
Refund Metrics | /analytics/v1/profile/metrics/refunds
Refund Filters | /analytics/v1/profile/filters/refunds
Payment Report | /analytics/v1/profile/report/payments
Refund Report | /analytics/v1/profile/report/refunds
Dispute Report | /analytics/v1/profile/report/dispute
Dispute Metrics | /analytics/v1/profile/metrics/disputes
Dispute Filters | /analytics/v1/profile/filters/disputes
Info | /analytics/v1/profile/{domain}/info
Connector Logs | /analytics/v1/profile/connector_event_logs
Outgoing Webhook Event Logs | /analytics/v1/profile/outgoing_webhook_event_logs
API Event Logs | /analytics/v1/profile/api_event_logs
SDK Event Logs | /analytics/v1/profile/sdk_event_logs
Payment Metrics V2 | /analytics/v2/profile/metrics/payments

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
OrgLevel, MerchantLevel and ProfileLevel provide for enhanced analytics insights on metrics, filters etc of Payments, Refunds, Disputes etc.



## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
- Can be tested once Frontend support is added and the respective OrgLevel, MerchantLevel and ProfileLevel APIs are hit
- ProfileId is added as a filter for Payments and Refunds
<img width="1429" alt="Screenshot 2024-09-03 at 11 08 18 AM" src="https://github.com/user-attachments/assets/a7be2814-af4c-42cb-bd65-646100b49c74">
<img width="1428" alt="Screenshot 2024-09-03 at 11 08 28 AM" src="https://github.com/user-attachments/assets/7dc2089e-4cab-422c-8803-5c4e4088ad41">
<img width="1424" alt="Screenshot 2024-09-03 at 11 08 35 AM" src="https://github.com/user-attachments/assets/d4e26dbd-b5d5-465e-ba07-f71c95ab75ea">

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible


Resolution:
<think>
PR Context:
- Title: feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication
- Merged: 2024-09-04T18:09:07Z
- Files changed: 30 files
- Commits: 3 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
Cherry picked the commit for #5729

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links 
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and Pr
Files to modify:


**crates/analytics/src/api_event/core.rs**
  Modify existing code

**crates/analytics/src/api_event/filters.rs**
  Modify existing code

**crates/analytics/src/api_event/metrics.rs**
  Modify existing code

**crates/analytics/src/api_event/metrics/api_count.rs**
  Modify existing code

**crates/analytics/src/api_event/metrics/latency.rs**
  Modify existing code

**crates/analytics/src/api_event/metrics/status_code_count.rs**
  Modify existing code

**crates/analytics/src/clickhouse.rs**
  Modify existing code

**crates/analytics/src/disputes/core.rs**
  Modify existing code

**crates/analytics/src/disputes/filters.rs**
  Modify existing code

**crates/analytics/src/disputes/metrics.rs**
  Modify existing code

**crates/analytics/src/disputes/metrics/dispute_status_metric.rs**
  Modify existing code

**crates/analytics/src/disputes/metrics/total_amount_disputed.rs**
  Modify existing code

**crates/analytics/src/disputes/metrics/total_dispute_lost_amount.rs**
  Modify existing code

**crates/analytics/src/enums.rs**
  Modify existing code

**crates/analytics/src/errors.rs**
  Modify existing code

**crates/analytics/src/lib.rs**
  Remove:
    - mod: pub::active_payments
    - mod: pub::api_event
    - mod: pub::auth_events
    - mod: pub::connector_events
    - mod: pub::health_check
    - mod: pub::opensearch
    - mod: pub::outgoing_webhook_event
  Add:
    - mod: pub::active_payments
    - mod: pub::api_event
    - mod: pub::auth_events
    - mod: pub::connector_events
    - mod: pub::enums
    - mod: pub::health_check
    - mod: pub::opensearch
    - mod: pub::outgoing_webhook_event

**crates/analytics/src/outgoing_webhook_event/events.rs**
  Modify existing code

**crates/analytics/src/payment_intents/core.rs**
  Modify existing code

**crates/analytics/src/payment_intents/filters.rs**
  Modify existing code

**crates/analytics/src/payment_intents/metrics.rs**
  Modify existing code

**crates/analytics/src/payment_intents/metrics/payment_intent_count.rs**
  Modify existing code

**crates/analytics/src/payment_intents/metrics/smart_retried_amount.rs**
  Modify existing code

**crates/analytics/src/payment_intents/metrics/successful_smart_retries.rs**
  Modify existing code

**crates/analytics/src/payment_intents/metrics/total_smart_retries.rs**
  Modify existing code

**crates/analytics/src/payment_intents/types.rs**
  Modify existing code

**crates/analytics/src/payments/core.rs**
  Modify existing code

**crates/analytics/src/payments/distribution.rs**
  Modify existing code

**crates/analytics/src/payments/distribution/payment_error_message.rs**
  Modify existing code

**crates/analytics/src/payments/filters.rs**
  Remove:
    - struct: private::FilterRow
    - trait: pub::PaymentFilterAnalytics
  Add:
    - struct: private::PaymentFilterRow
    - trait: pub::PaymentFilterAnalytics

**crates/analytics/src/payments/metrics.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/avg_ticket_size.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/connector_success_rate.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/payment_count.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/payment_processed_amount.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/payment_success_count.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/retries_count.rs**
  Modify existing code

**crates/analytics/src/payments/metrics/success_rate.rs**
  Modify existing code

**crates/analytics/src/payments/types.rs**
  Modify existing code

**crates/analytics/src/query.rs**
  Remove:
    - impl: impl ToSql<T> for &common_utils::id_type::MerchantId
  Add:
    - function: private::to_sql
    - function: private::to_sql
    - function: private::to_sql
    - function: private::set_filter_clause
    - impl: impl ToSql<T> for &MerchantId
    - impl: impl ToSql<T> for MerchantId
    - impl: impl ToSql<T> for &OrganizationId
    - impl: impl ToSql<T> for ProfileId
    - impl: impl QueryFilter<T> for AuthInfo

**crates/analytics/src/refunds/core.rs**
  Modify existing code

**crates/analytics/src/refunds/filters.rs**
  Modify existing code

**crates/analytics/src/refunds/metrics.rs**
  Modify existing code

**crates/analytics/src/refunds/metrics/refund_count.rs**
  Modify existing code

**crates/analytics/src/refunds/metrics/refund_processed_amount.rs**
  Modify existing code

**crates/analytics/src/refunds/metrics/refund_success_count.rs**
  Modify existing code

**crates/analytics/src/refunds/metrics/refund_success_rate.rs**
  Modify existing code

**crates/analytics/src/refunds/types.rs**
  Modify existing code

**crates/analytics/src/sqlx.rs**
  Add:
    - impl: impl FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow

**crates/api_models/src/analytics.rs**
  Modify existing code

**crates/api_models/src/analytics/payment_intents.rs**
  Modify existing code

**crates/api_models/src/analytics/payments.rs**
  Modify existing code

**crates/api_models/src/analytics/refunds.rs**
  Modify existing code

**crates/common_utils/src/types.rs**
  Add:
    - mod: pub::authentication

**crates/common_utils/src/types/authentication.rs**
  Add:
    - enum: pub::AuthInfo

**crates/hyperswitch_domain_models/src/merchant_account.rs**
  Add:
    - function: pub::get_org_id

**crates/router/src/analytics.rs**
  Add:
    - function: pub::get_org_payment_metrics
    - function: pub::get_org_payment_intent_metrics
    - function: pub::get_profile_payment_intent_metrics
    - function: pub::get_merchant_refund_metrics
    - function: pub::get_org_refund_metrics
    - function: pub::get_profile_refund_filters
    - function: pub::get_profile_outgoing_webhook_events
    - function: pub::generate_org_dispute_report
    - function: pub::generate_profile_dispute_report
    - function: pub::get_profile_api_events_metrics
    - function: pub::get_merchant_api_event_filters

**crates/router/src/core/verification/utils.rs**
  Add:
    - function: pub::check_if_profile_id_is_present_in_payment_intent

**crates/router/src/types/domain/user.rs**
  Modify existing code