# `emi_repository.py` ## Overview This file contains the `EMIRepository` class, which serves as the Data Access Layer (DAL) for the application. It inherits from a base `Repository` class and uses the pre-defined raw SQL queries from `sql_query_config.py` to interact with the database safely. ## Core Responsibilities - **Application CRUD**: Creates and manages the lifecycle states of `consumer_application` (e.g., `create_application`, `add_solar_application`, `update_application_state`). - **Identity & KYC Tracking**: Handles records related to KYC operations (e.g., `insert_ckyc`, `insert_digio_vkyc`, `insert_kyc_details`, `update_pan_dob`). - **OTP Management**: Records OTP generation, cooldown periods, and validation statuses (`insert_otp`, `validate_otp`, `cooldown_time`, `update_otp`). - **Document Management**: Handles inserting metadata about uploaded documents (like file paths in S3 or local paths) using methods like `insert_document` and checking for their existence via `check_document` and `check_solar_files`. - **Merchant Verification**: Checks if provided merchants and centers are valid (`check_merchant_id`, `check_center_id`, `get_merchants`). - **Offers & Payments**: Interacts with the `emi_calculation` tables to save offers and payment statuses (`save_offer`, `get_emi_calculation_details`, `get_payment_log`). ## Key Method Examples - **`create_application(...)`**: Executes deduplication checks before inserting a new user/customer and a new `consumer_application` row. - **`check_duplicate(...)`**: Validates if an application already exists based on `mobile_number`, `pan_card`, or `email` within a 90-day (configurable) cooldown period. - **`insert_document(...)`**: Saves S3 pointers of uploaded files mapping them securely to the application ID. ## Dependencies - `sql_query_config` (for all SQL strings) - `datetime` (for timestamping and TTL comparisons) - Encryption/Decryption utils (to secure PII at rest in the database).