erDiagram
    %% ============================================
    %% DEALER ONBOARDING BACKEND SCHEMA
    %% Based on Re_New_Dealer_Onboard_TWO.md (v1.4)
    %% Comprehensive Database Schema Design
    %% ============================================

    %% ============================================
    %% USER MANAGEMENT & AUTHENTICATION
    %% ============================================
    %% ============================================
    %% FINANCE & PAYMENTS
    %% ============================================
    FINANCE_PAYMENTS {
        uuid payment_id PK
        uuid application_id FK
        string payment_type
        decimal amount
        string payment_status
        string transaction_id
        date payment_date
        uuid verified_by FK
        timestamp verification_date
        text remarks
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% EXIT FEEDBACK & SLA BREACHES
    %% ============================================
    EXIT_FEEDBACK {
        uuid feedback_id PK
        uuid resignation_id FK
        uuid termination_request_id FK
        string feedback_type
        json ratings
        text comments
        timestamp submitted_at
        uuid submitted_by FK
    }

    SLA_BREACHES {
        uuid breach_id PK
        uuid tracking_id FK
        timestamp breached_at
        string notified_to
        string status
        text action_taken
        timestamp created_at
    }

    USERS {
        uuid user_id PK
        string employee_id UK
        string email UK
        string full_name
        string mobile_number
        string department
        string designation
        uuid role_code FK
        string role_code UK
        uuid zone_id FK
        uuid region_id FK
        uuid state_id FK
        uuid district_id FK
        uuid area_id FK
        uuid dealer_id FK
        boolean is_active
        boolean is_external
        string sso_provider
        string status
        timestamp last_login
        timestamp created_at
        timestamp updated_at
    }

    ROLES {
        uuid role_id PK
        string role_code UK
        string role_name
        string description
        string category
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    PERMISSIONS {
        uuid permission_id PK
        string permission_code UK
        string permission_name
        string module
        string permission_category
        string action
        string description
        timestamp created_at
    }

    ROLE_PERMISSIONS {
        uuid role_permission_id PK
        uuid role_id FK
        uuid permission_id FK
        timestamp created_at
    }

    USER_ROLES {
        uuid user_role_id PK
        uuid user_id FK
        uuid role_id FK
        uuid zone_id FK
        uuid region_id FK
        uuid area_id FK
        timestamp assigned_at
        uuid assigned_by FK
        timestamp created_at
    }

    %% ============================================
    %% ORGANIZATIONAL HIERARCHY
    %% ============================================
    ZONES {
        uuid zone_id PK
        string zone_code UK
        string zone_name
        string description
        boolean is_active
        uuid zonal_business_head_id FK
        timestamp created_at
        timestamp updated_at
    }

    REGIONS {
        uuid region_id PK
        uuid zone_id FK
        uuid state_id FK
        string region_code UK
        string region_name
        string description
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    STATES {
        uuid state_id PK
        string state_name UK
        uuid zone_id FK
        boolean is_active
        timestamp created_at
    }

    DISTRICTS {
        uuid district_id PK
        uuid state_id FK
        uuid zone_id FK
        uuid region_id FK
        string district_name
        boolean is_active
        timestamp created_at
    }

    AREAS {
        uuid area_id PK
        uuid zone_id FK
        uuid region_id FK
        uuid state_id FK
        uuid district_id FK
        string area_code UK
        string area_name
        string city
        string pincode
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    ZONE_MANAGERS {
        uuid zone_manager_id PK
        uuid zone_id FK
        uuid user_id FK
        string manager_type
        boolean is_active
        timestamp assigned_at
        timestamp created_at
    }

    REGION_MANAGERS {
        uuid region_manager_id PK
        uuid region_id FK
        uuid user_id FK
        string manager_type
        boolean is_active
        timestamp assigned_at
        timestamp created_at
    }

    AREA_MANAGERS {
        uuid area_manager_id PK
        uuid area_id FK
        uuid user_id FK
        string manager_type
        boolean is_active
        timestamp assigned_at
        timestamp created_at
    }

    DISTRICT_MANAGERS {
        uuid district_manager_id PK
        uuid district_id FK
        uuid user_id FK
        string manager_type
        boolean is_active
        timestamp assigned_at
        timestamp created_at
    }

    %% ============================================
    %% OPPORTUNITY MANAGEMENT
    %% ============================================
    OPPORTUNITIES {
        uuid opportunity_id PK
        uuid zone_id FK
        uuid region_id FK
        uuid state_id FK
        uuid district_id FK
        string city
        string opportunity_type
        integer capacity
        string priority
        date open_from
        date open_to
        string status
        text notes
        uuid created_by FK
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% DEALER ENTITY (POST-ONBOARDING)
    %% ============================================
    DEALERS {
        uuid id PK
        uuid applicationId FK
        uuid dealerCodeId FK
        string legalName
        string businessName
        string constitutionType
        text registeredAddress
        string gstNumber
        string panNumber
        string status
        timestamp onboardedAt
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% ONBOARDING APPLICATION (ONBOARDING PHASE)
    %% ============================================
    APPLICATIONS {
        uuid id PK
        string applicationId UK
        uuid opportunityId FK
        string applicantName
        string email UK
        string phone
        string businessType
        string preferredLocation
        string city
        string state
        integer experienceYears
        string investmentCapacity
        integer age
        string education
        string companyName
        string source
        string existingDealer
        string ownRoyalEnfield
        string royalEnfieldModel
        text description
        text address
        string pincode
        string locationType
        string currentStage
        string overallStatus
        integer progressPercentage
        boolean isShortlisted
        boolean ddLeadShortlisted
        decimal score
        uuid assignedTo FK
        uuid architectureAssignedTo FK
        string architectureStatus
        uuid submittedBy FK
        uuid zoneId FK
        uuid regionId FK
        uuid areaId FK
        json documents
        json timeline
        timestamp created_at
        timestamp updated_at
    }

    APPLICATION_PROGRESS {
        uuid id PK
        uuid application_id FK
        string stage_name
        integer stage_order
        string status
        integer completion_percentage
        timestamp stage_started_at
        timestamp stage_completed_at
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% QUESTIONNAIRE MANAGEMENT
    %% ============================================
    QUESTIONNAIRES {
        uuid questionnaire_id PK
        string questionnaire_code UK
        string version
        string title
        text description
        boolean is_active
        uuid created_by FK
        timestamp created_at
        timestamp updated_at
    }

    QUESTIONNAIRE_SECTIONS {
        uuid section_id PK
        uuid questionnaire_id FK
        string section_name
        string section_type
        integer section_order
        decimal section_weightage
        boolean is_active
        timestamp created_at
    }

    QUESTIONNAIRE_QUESTIONS {
        uuid question_id PK
        uuid section_id FK
        string question_text
        string question_type
        integer question_order
        decimal question_weightage
        json options
        boolean is_mandatory
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    QUESTIONNAIRE_RESPONSES {
        uuid response_id PK
        uuid application_id FK
        uuid questionnaire_id FK
        uuid question_id FK
        text response_text
        json response_data
        decimal score_obtained
        decimal max_score
        timestamp submitted_at
        timestamp created_at
        timestamp updated_at
    }

    QUESTIONNAIRE_SCORES {
        uuid score_id PK
        uuid application_id FK
        uuid questionnaire_id FK
        decimal total_score
        decimal max_score
        decimal percentage_score
        integer rank_in_city
        integer rank_in_region
        timestamp calculated_at
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% INTERVIEW MANAGEMENT
    %% ============================================
    INTERVIEWS {
        uuid interview_id PK
        uuid application_id FK
        integer interview_level
        string interview_type
        string interview_mode
        date interview_date
        time interview_time
        string meeting_link
        string venue_address
        string status
        uuid scheduled_by FK
        timestamp scheduled_at
        timestamp created_at
        timestamp updated_at
    }

    INTERVIEW_PARTICIPANTS {
        uuid participant_id PK
        uuid interview_id FK
        uuid user_id FK
        string participant_role
        boolean is_required
        boolean has_attended
        timestamp created_at
    }

    INTERVIEW_EVALUATIONS {
        uuid evaluation_id PK
        uuid interview_id FK
        uuid application_id FK
        uuid evaluator_id FK
        integer interview_level
        decimal kt_matrix_score
        decimal feedback_score
        decimal overall_score
        string recommendation
        text remarks
        text feedback_summary
        timestamp submitted_at
        timestamp created_at
        timestamp updated_at
    }

    KT_MATRIX_SCORES {
        uuid kt_score_id PK
        uuid evaluation_id FK
        string parameter_name
        decimal parameter_weightage
        decimal score_obtained
        text remarks
        timestamp created_at
    }

    INTERVIEW_FEEDBACK {
        uuid feedback_id PK
        uuid evaluation_id FK
        string feedback_category
        text feedback_text
        decimal category_score
        timestamp created_at
    }

    AI_SUMMARIES {
        uuid summary_id PK
        uuid application_id FK
        integer interview_level
        text ai_generated_summary
        text nbh_edited_summary
        boolean is_approved
        uuid approved_by FK
        timestamp generated_at
        timestamp approved_at
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% WORK NOTES & COMMUNICATION
    %% ============================================
    WORK_NOTES {
        uuid work_note_id PK
        uuid application_id FK
        uuid created_by FK
        text note_content
        json tagged_users
        json attachments
        string note_type
        uuid parent_note_id FK
        boolean is_internal
        boolean is_deleted
        timestamp created_at
        timestamp updated_at
    }

    WORK_NOTE_TAGS {
        uuid tag_id PK
        uuid work_note_id FK
        uuid tagged_user_id FK
        boolean is_notified
        timestamp notified_at
        timestamp created_at
    }

    WORK_NOTE_ATTACHMENTS {
        uuid attachment_id PK
        uuid work_note_id FK
        uuid document_id FK
        timestamp created_at
    }

    %% ============================================
    %% DOCUMENT MANAGEMENT
    %% ============================================
    DOCUMENTS {
        uuid document_id PK
        uuid application_id FK
        uuid uploaded_by FK
        string document_type
        string document_category
        string file_name
        string file_type
        bigint file_size
        string file_path
        string storage_url
        string mime_type
        integer version
        string status
        uuid verified_by FK
        timestamp verified_at
        boolean is_deleted
        timestamp uploaded_at
        timestamp created_at
        timestamp updated_at
    }

    DOCUMENT_VERSIONS {
        uuid version_id PK
        uuid document_id FK
        integer version_number
        string file_path
        string storage_url
        uuid uploaded_by FK
        timestamp uploaded_at
        timestamp created_at
    }

    LOI_DOCUMENTS {
        uuid loi_doc_id PK
        uuid application_id FK
        string document_name
        string document_type
        uuid document_id FK
        boolean is_mandatory
        boolean is_uploaded
        boolean is_verified
        timestamp required_at
        timestamp uploaded_at
        timestamp verified_at
    }

    STATUTORY_DOCUMENTS {
        uuid statutory_doc_id PK
        uuid application_id FK
        string document_name
        string document_type
        uuid document_id FK
        boolean is_mandatory
        boolean is_uploaded
        boolean is_verified
        uuid verified_by FK
        timestamp verified_at
        timestamp created_at
    }

    %% ============================================
    %% FDD PROCESS
    %% ============================================
    FDD_ASSIGNMENTS {
        uuid fdd_assignment_id PK
        uuid application_id FK
        uuid fdd_user_id FK
        string assignment_status
        date assigned_at
        date due_date
        timestamp created_at
        timestamp updated_at
    }

    FDD_REPORTS {
        uuid fdd_report_id PK
        uuid fdd_assignment_id FK
        uuid application_id FK
        string report_type
        string report_level
        uuid document_id FK
        text remarks
        string status
        timestamp submitted_at
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% LOI PROCESS
    %% ============================================
    LOI_REQUESTS {
        uuid loi_request_id PK
        uuid application_id FK
        string request_status
        date document_request_date
        date security_deposit_request_date
        boolean documents_complete
        boolean security_deposit_verified
        boolean can_send_back
        boolean can_revoke
        timestamp created_at
        timestamp updated_at
    }

    LOI_APPROVALS {
        uuid loi_approval_id PK
        uuid loi_request_id FK
        uuid application_id FK
        integer approval_level
        uuid approver_id FK
        string approval_status
        text approval_remarks
        timestamp approved_at
        timestamp created_at
        timestamp updated_at
    }

    LOI_DOCUMENTS_GENERATED {
        uuid loi_doc_gen_id PK
        uuid application_id FK
        uuid loi_request_id FK
        uuid document_id FK
        date issue_date
        uuid authorized_signatory FK
        string document_version
        timestamp generated_at
        timestamp uploaded_at
    }

    LOI_ACKNOWLEDGEMENTS {
        uuid loi_ack_id PK
        uuid application_id FK
        uuid loi_doc_gen_id FK
        uuid document_id FK
        timestamp acknowledged_at
        timestamp created_at
    }

    %% ============================================
    %% SECURITY DEPOSIT
    %% ============================================
    SECURITY_DEPOSITS {
        uuid deposit_id PK
        uuid application_id FK
        decimal deposit_amount
        string payment_mode
        string transaction_id
        date transaction_date
        string bank_name
        string account_number
        uuid proof_document_id FK
        string verification_status
        uuid verified_by FK
        timestamp verified_at
        text verification_remarks
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% OUTLET MANAGEMENT
    %% ============================================
    OUTLETS {
        uuid id PK
        string code UK
        string name
        string type
        text address
        string city
        string state
        string pincode
        decimal latitude
        decimal longitude
        string status
        date establishedDate
        uuid dealerId FK
        string region
        string zone
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% DEALER CODE GENERATION
    %% ============================================
    DEALER_CODES {
        uuid dealer_code_id PK
        uuid application_id FK
        string dealer_code UK
        string sales_code
        string service_code
        string gma_code
        string gear_code
        string sap_dealer_id
        boolean is_active
        timestamp generated_at
        uuid generated_by FK
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% DEALER SERVICE APPLICATIONS (POST-ONBOARDING)
    %% Also known as Self-Service or Lifecycle Requests
    %% ============================================
    RESIGNATIONS {
        uuid id PK
        string resignationId UK
        uuid outletId FK
        uuid dealerId FK
        string resignationType
        date lastOperationalDateSales
        date lastOperationalDateServices
        text reason
        text additionalInfo
        string currentStage
        string status
        integer progressPercentage
        timestamp submittedOn
        json documents
        json timeline
        text rejectionReason
        json departmentalClearances
        timestamp created_at
        timestamp updated_at
    }

    RELOCATION_REQUESTS {
        uuid id PK
        string requestId UK
        uuid outletId FK
        uuid dealerId FK
        string relocationType
        text newAddress
        string newCity
        string newState
        text reason
        string currentStage
        string status
        integer progressPercentage
        json documents
        json timeline
        timestamp created_at
        timestamp updated_at
    }

    CONSTITUTIONAL_CHANGES {
        uuid id PK
        string requestId UK
        uuid outletId FK
        uuid dealerId FK
        string changeType
        text description
        string currentStage
        string status
        integer progressPercentage
        json documents
        json timeline
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% ARCHITECTURAL WORK
    %% ============================================
    ARCHITECTURAL_ASSIGNMENTS {
        uuid arch_assignment_id PK
        uuid application_id FK
        uuid assigned_to_team FK
        string assignment_status
        date assigned_at
        date due_date
        timestamp created_at
        timestamp updated_at
    }

    ARCHITECTURAL_DOCUMENTS {
        uuid arch_doc_id PK
        uuid arch_assignment_id FK
        uuid application_id FK
        string document_type
        uuid document_id FK
        string layout_type
        boolean dealer_consent_received
        date consent_date
        timestamp uploaded_at
        timestamp created_at
    }

    CONSTRUCTION_PROGRESS {
        uuid progress_id PK
        uuid application_id FK
        string progress_type
        text progress_description
        uuid document_id FK
        integer progress_percentage
        timestamp reported_at
        timestamp created_at
    }

    %% ============================================
    %% EOR CHECKLIST
    %% ============================================
    EOR_CHECKLISTS {
        uuid eor_checklist_id PK
        uuid application_id FK
        string checklist_name
        string status
        integer total_items
        integer completed_items
        integer percentage_complete
        timestamp created_at
        timestamp updated_at
    }

    EOR_CHECKLIST_ITEMS {
        uuid eor_item_id PK
        uuid eor_checklist_id FK
        string item_name
        string item_category
        string responsible_team
        string status
        text remarks
        uuid verified_by FK
        timestamp verified_at
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% LOA PROCESS
    %% ============================================
    LOA_REQUESTS {
        uuid loa_request_id PK
        uuid application_id FK
        string request_status
        boolean eor_complete
        boolean loa_issued_before_eor
        timestamp created_at
        timestamp updated_at
    }

    LOA_APPROVALS {
        uuid loa_approval_id PK
        uuid loa_request_id FK
        uuid application_id FK
        uuid approver_id FK
        string approval_status
        text approval_remarks
        timestamp approved_at
        timestamp created_at
        timestamp updated_at
    }

    LOA_DOCUMENTS_GENERATED {
        uuid loa_doc_gen_id PK
        uuid application_id FK
        uuid loa_request_id FK
        uuid document_id FK
        date issue_date
        uuid authorized_signatory FK
        string document_version
        timestamp generated_at
        timestamp uploaded_at
    }

    %% ============================================
    %% INAUGURATION
    %% ============================================
    INAUGURATIONS {
        uuid inauguration_id PK
        uuid application_id FK
        date inauguration_date
        string venue
        text event_summary
        uuid organized_by FK
        string status
        timestamp created_at
        timestamp updated_at
    }

    INAUGURATION_ATTENDEES {
        uuid attendee_id PK
        uuid inauguration_id FK
        uuid user_id FK
        string attendee_role
        boolean is_confirmed
        timestamp created_at
    }

    INAUGURATION_DOCUMENTS {
        uuid inauguration_doc_id PK
        uuid inauguration_id FK
        uuid document_id FK
        string document_type
        timestamp uploaded_at
    }

    %% ============================================
    %% TERMINATION (A TYPE OF SERVICE APPLICATION)
    %% ============================================
    TERMINATION_REQUESTS {
        uuid id PK
        uuid dealerId FK
        string category
        text reason
        date proposedLwd
        string status
        string currentStage
        uuid initiatedBy FK
        text comments
        json timeline
        json documents
        timestamp created_at
        timestamp updated_at
    }

    TERMINATION_APPROVALS {
        uuid approval_id PK
        uuid termination_id FK
        integer level
        string approver_role
        uuid approver_id FK
        string action
        text remarks
        timestamp created_at
    }

    FNF_SETTLEMENTS {
        uuid id PK
        uuid resignationId FK
        uuid terminationRequestId FK
        uuid outletId FK
        uuid dealerId FK
        string status
        decimal totalReceivables
        decimal totalPayables
        decimal netAmount
        date settlementDate
        json clearanceDocuments
        timestamp created_at
        timestamp updated_at
    }

    FNF_DEPARTMENT_CLEARANCES {
        uuid clearance_id PK
        uuid fnf_id FK
        string department_name
        string clearance_status
        decimal payable_amount
        decimal recovery_amount
        text remarks
        uuid cleared_by FK
        timestamp cleared_at
    }

    FNF_LINE_ITEMS {
        uuid line_item_id PK
        uuid fnf_id FK
        uuid clearance_id FK
        string item_type
        string department
        string description
        decimal amount
        uuid added_by FK
        timestamp created_at
    }

    FNF_SETTLEMENT_SUMMARIES {
        uuid summary_id PK
        uuid fnf_id FK
        decimal total_payables
        decimal total_receivables
        decimal total_deductions
        decimal net_settlement_amount
        string status
        uuid verified_by FK
        timestamp verified_at
    }

    %% ============================================
    %% NOTIFICATIONS
    %% ============================================
    NOTIFICATIONS {
        uuid notification_id PK
        uuid user_id FK
        uuid application_id FK
        string notification_type
        string title
        text message
        string priority
        boolean is_read
        json metadata
        timestamp read_at
        timestamp created_at
    }

    EMAIL_LOGS {
        uuid email_log_id PK
        uuid application_id FK
        uuid user_id FK
        string email_type
        string recipient_email
        string subject
        text email_body
        string status
        text error_message
        timestamp sent_at
        timestamp created_at
    }

    WHATSAPP_LOGS {
        uuid whatsapp_log_id PK
        uuid application_id FK
        string recipient_number
        string message_type
        text message_content
        string status
        text error_message
        timestamp sent_at
        timestamp created_at
    }

    %% ============================================
    %% SLA & TAT TRACKING
    %% ============================================
    SLA_CONFIGURATIONS {
        uuid sla_config_id PK
        string activity_name
        string owner_role
        integer tat_hours
        string tat_unit
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    SLA_CONFIG_REMINDERS {
        uuid reminder_id PK
        uuid sla_config_id FK
        integer time_value
        string time_unit
        boolean is_enabled
        timestamp created_at
    }

    SLA_CONFIG_ESCALATIONS {
        uuid escalation_config_id PK
        uuid sla_config_id FK
        integer level
        integer time_value
        string time_unit
        string notify_email
        timestamp created_at
    }

    SLA_TRACKING {
        uuid sla_tracking_id PK
        uuid application_id FK
        uuid sla_config_id FK
        string activity_name
        uuid owner_id FK
        timestamp start_time
        timestamp due_time
        timestamp completed_time
        string status
        integer completion_percentage
        timestamp created_at
        timestamp updated_at
    }

    SLA_ESCALATIONS {
        uuid escalation_id PK
        uuid sla_tracking_id FK
        integer escalation_level
        uuid escalated_to FK
        text escalation_reason
        timestamp escalated_at
        timestamp resolved_at
    }

    %% ============================================
    %% EMAIL TEMPLATES
    %% ============================================
    EMAIL_TEMPLATES {
        uuid template_id PK
        string template_name UK
        string template_code UK
        string subject
        text template_body
        string trigger_event
        json system_variables
        boolean is_active
        string version
        timestamp created_at
        timestamp updated_at
    }

    %% ============================================
    %% AUDIT TRAIL
    %% ============================================
    AUDIT_LOGS {
        uuid audit_log_id PK
        uuid application_id FK
        uuid user_id FK
        string action_type
        string entity_type
        uuid entity_id
        text description
        json before_state
        json after_state
        json metadata
        string ip_address
        string user_agent
        timestamp created_at
    }

    ACTIVITY_LOGS {
        uuid activity_id PK
        uuid application_id FK
        uuid user_id FK
        string activity_type
        text activity_description
        json activity_data
        timestamp created_at
    }

    %% ============================================
    %% APPLICATION STATUS TRACKING
    %% ============================================
    APPLICATION_STATUS_HISTORY {
        uuid status_history_id PK
        uuid application_id FK
        string previous_status
        string new_status
        uuid changed_by FK
        text change_reason
        timestamp changed_at
    }

    APPLICATION_PROGRESS {
        uuid progress_id PK
        uuid application_id FK
        string stage_name
        integer stage_order
        string status
        integer completion_percentage
        timestamp stage_started_at
        timestamp stage_completed_at
        timestamp created_at
        timestamp updated_at
    }

    WORKFLOW_STAGES_CONFIG {
        uuid stage_config_id PK
        string stage_name UK
        integer stage_order
        string color_code
        boolean is_parallel
        json default_evaluators
        boolean is_active
        timestamp created_at
    }

    %% ============================================
    %% DEALER PORTAL ACCESS CONFIG
    %% ============================================
    DEALER_PORTAL_CONFIG {
        uuid config_id PK
        uuid dealer_id FK
        boolean allows_resignation
        boolean allows_relocation
        boolean allows_constitution_change
        timestamp access_revoked_at
    }

    REQUEST_PARTICIPANTS {
        uuid id PK
        uuid requestId FK
        string requestType
        uuid userId FK
        string role
        boolean isActive
        timestamp created_at
        timestamp updated_at
    }

    %% NOTE: Polymorphic Relationships
    %% DOCUMENTS, WORK_NOTES, and REQUEST_PARTICIPANTS 
    %% use 'requestType' and 'requestId' to link with:
    %% - APPLICATIONS (Onboarding)
    %% - RESIGNATIONS
    %% - RELOCATION_REQUESTS
    %% - CONSTITUTIONAL_CHANGES
    %% - TERMINATION_REQUESTS

    %% ============================================
    %% RELATIONSHIPS
    %% ============================================
    USERS ||--o{ USER_ROLES : "has"
    ROLES ||--o{ USERS : "assigned_to"
    ROLES ||--o{ ROLE_PERMISSIONS : "has"
    PERMISSIONS ||--o{ ROLE_PERMISSIONS : "granted_in"
    
    ZONES ||--o{ STATES : "contains"
    STATES ||--o{ DISTRICTS : "contains"
    ZONES ||--o{ DISTRICTS : "contains"
    REGIONS ||--o{ DISTRICTS : "contains"
    ZONES ||--o{ REGIONS : "contains"
    STATES ||--o{ REGIONS : "contains"
    ZONES ||--o{ AREAS : "contains"
    REGIONS ||--o{ AREAS : "contains"
    STATES ||--o{ AREAS : "contains"
    DISTRICTS ||--o{ AREAS : "contains"
    
    ZONES ||--o{ ZONE_MANAGERS : "managed_by"
    REGIONS ||--o{ REGION_MANAGERS : "managed_by"
    AREAS ||--o{ AREA_MANAGERS : "managed_by"
    USERS ||--o{ ZONE_MANAGERS : "is"
    USERS ||--o{ REGION_MANAGERS : "is"
    USERS ||--o{ AREA_MANAGERS : "is"
    
    DISTRICTS ||--o{ DISTRICT_MANAGERS : "managed_by"
    USERS ||--o{ DISTRICT_MANAGERS : "is"
    
    ZONES ||--o{ OPPORTUNITIES : "has"
    REGIONS ||--o{ OPPORTUNITIES : "has"
    STATES ||--o{ OPPORTUNITIES : "has"
    DISTRICTS ||--o{ OPPORTUNITIES : "has"
    
    ZONES ||--o{ APPLICATIONS : "belongs_to"
    REGIONS ||--o{ APPLICATIONS : "belongs_to"
    AREAS ||--o{ APPLICATIONS : "belongs_to"
    USERS ||--o{ APPLICATIONS : "assigned_to"
    
    APPLICATIONS ||--o{ QUESTIONNAIRE_RESPONSES : "has"
    QUESTIONNAIRES ||--o{ QUESTIONNAIRE_RESPONSES : "used_in"
    QUESTIONNAIRE_QUESTIONS ||--o{ QUESTIONNAIRE_RESPONSES : "answered_by"
    APPLICATIONS ||--o{ QUESTIONNAIRE_SCORES : "has"
    
    APPLICATIONS ||--o{ INTERVIEWS : "has"
    INTERVIEWS ||--o{ INTERVIEW_PARTICIPANTS : "includes"
    INTERVIEWS ||--o{ INTERVIEW_EVALUATIONS : "evaluated_in"
    INTERVIEW_EVALUATIONS ||--o{ KT_MATRIX_SCORES : "contains"
    INTERVIEW_EVALUATIONS ||--o{ INTERVIEW_FEEDBACK : "has"
    APPLICATIONS ||--o{ AI_SUMMARIES : "has"
    
    APPLICATIONS ||--o{ WORK_NOTES : "has"
    WORK_NOTES ||--o{ WORK_NOTE_TAGS : "tags"
    WORK_NOTES ||--o{ WORK_NOTE_ATTACHMENTS : "has"
    DOCUMENTS ||--o{ WORK_NOTE_ATTACHMENTS : "attached_to"
    
    APPLICATIONS ||--o{ DOCUMENTS : "has"
    DOCUMENTS ||--o{ DOCUMENT_VERSIONS : "has"
    APPLICATIONS ||--o{ LOI_DOCUMENTS : "requires"
    APPLICATIONS ||--o{ STATUTORY_DOCUMENTS : "requires"
    
    APPLICATIONS ||--o{ FDD_ASSIGNMENTS : "assigned_to"
    FDD_ASSIGNMENTS ||--o{ FDD_REPORTS : "generates"
    FDD_REPORTS ||--o{ DOCUMENTS : "stored_as"
    
    APPLICATIONS ||--o{ LOI_REQUESTS : "has"
    LOI_REQUESTS ||--o{ LOI_APPROVALS : "requires"
    LOI_REQUESTS ||--o{ LOI_DOCUMENTS_GENERATED : "generates"
    LOI_DOCUMENTS_GENERATED ||--o{ LOI_ACKNOWLEDGEMENTS : "acknowledged_by"
    
    APPLICATIONS ||--o{ SECURITY_DEPOSITS : "has"
    SECURITY_DEPOSITS ||--o{ DOCUMENTS : "proof_document"
    
    APPLICATIONS ||--o{ DEALER_CODES : "has"
    APPLICATIONS ||--o{ DEALERS : "onboarded_as"
    DEALERS ||--o{ USERS : "has_portal_users"
    
    DEALERS ||--o{ RESIGNATIONS : "initiates"
    DEALERS ||--o{ RELOCATION_REQUESTS : "requests"
    DEALERS ||--o{ CONSTITUTIONAL_CHANGES : "proposes"
    
    DEALERS ||--o{ TERMINATION_REQUESTS : "terminated_by"
    TERMINATION_REQUESTS ||--o{ TERMINATION_APPROVALS : "requires"
    
    DEALERS ||--o{ FNF_SETTLEMENTS : "settled_in"
    RESIGNATIONS ||--o{ FNF_SETTLEMENTS : "triggers"
    TERMINATION_REQUESTS ||--o{ FNF_SETTLEMENTS : "triggers"
    FNF_SETTLEMENTS ||--o{ FNF_DEPARTMENT_CLEARANCES : "requires_NOC_from"
    FNF_SETTLEMENTS ||--o{ FNF_SETTLEMENT_SUMMARIES : "consolidated_in"
    
    DEALERS ||--o{ DEALER_PORTAL_CONFIG : "governed_by"
    
    APPLICATIONS ||--o{ ARCHITECTURAL_ASSIGNMENTS : "assigned_to"
    ARCHITECTURAL_ASSIGNMENTS ||--o{ ARCHITECTURAL_DOCUMENTS : "has"
    APPLICATIONS ||--o{ CONSTRUCTION_PROGRESS : "tracks"
    
    APPLICATIONS ||--o{ EOR_CHECKLISTS : "has"
    EOR_CHECKLISTS ||--o{ EOR_CHECKLIST_ITEMS : "contains"
    
    APPLICATIONS ||--o{ LOA_REQUESTS : "has"
    LOA_REQUESTS ||--o{ LOA_APPROVALS : "requires"
    LOA_REQUESTS ||--o{ LOA_DOCUMENTS_GENERATED : "generates"
    
    APPLICATIONS ||--o{ INAUGURATIONS : "has"
    INAUGURATIONS ||--o{ INAUGURATION_ATTENDEES : "includes"
    INAUGURATIONS ||--o{ INAUGURATION_DOCUMENTS : "has"
    
    USERS ||--o{ NOTIFICATIONS : "receives"
    APPLICATIONS ||--o{ NOTIFICATIONS : "triggers"
    APPLICATIONS ||--o{ EMAIL_LOGS : "triggers"
    APPLICATIONS ||--o{ WHATSAPP_LOGS : "triggers"
    
    SLA_CONFIGURATIONS ||--o{ SLA_TRACKING : "tracks"
    APPLICATIONS ||--o{ SLA_TRACKING : "monitored_by"
    SLA_TRACKING ||--o{ SLA_ESCALATIONS : "escalates"
    
    APPLICATIONS ||--o{ AUDIT_LOGS : "logged_in"
    USERS ||--o{ AUDIT_LOGS : "performed_by"
    APPLICATIONS ||--o{ ACTIVITY_LOGS : "logged_in"
    APPLICATIONS ||--o{ APPLICATION_STATUS_HISTORY : "tracks"
    APPLICATIONS ||--o{ APPLICATION_PROGRESS : "tracks"

    SLA_CONFIGURATIONS ||--o{ SLA_CONFIG_REMINDERS : "defines"
    SLA_CONFIGURATIONS ||--o{ SLA_CONFIG_ESCALATIONS : "defines"
    FNF_SETTLEMENTS ||--o{ FNF_LINE_ITEMS : "has"
    FNF_DEPARTMENT_CLEARANCES ||--o{ FNF_LINE_ITEMS : "details"
    USERS ||--o{ FNF_LINE_ITEMS : "added"
    USERS ||--o{ APPLICATIONS : "currently_assigned"
    
    USERS ||--o{ OUTLETS : "has_outlets"
    OUTLETS ||--o{ CONSTITUTIONAL_CHANGES : "requests_change"
    OUTLETS ||--o{ RELOCATION_REQUESTS : "requests_relocation"
    OUTLETS ||--o{ RESIGNATIONS : "initiates_resignation"
    
    APPLICATIONS ||--o{ FINANCE_PAYMENTS : "has_payments"
    USERS ||--o{ FINANCE_PAYMENTS : "verifies_payments"
    
    RESIGNATIONS ||--o{ EXIT_FEEDBACK : "has_feedback"
    TERMINATION_REQUESTS ||--o{ EXIT_FEEDBACK : "has_feedback"
    USERS ||--o{ EXIT_FEEDBACK : "submitted_by"
    
    SLA_TRACKING ||--o{ SLA_BREACHES : "has_breaches"

    APPLICATIONS ||--o{ REQUEST_PARTICIPANTS : "has_participants"
    RESIGNATIONS ||--o{ REQUEST_PARTICIPANTS : "has_participants"
    TERMINATION_REQUESTS ||--o{ REQUEST_PARTICIPANTS : "has_participants"
    RELOCATION_REQUESTS ||--o{ REQUEST_PARTICIPANTS : "has_participants"
    CONSTITUTIONAL_CHANGES ||--o{ REQUEST_PARTICIPANTS : "has_participants"
    

