





















const db = require('../models');
const Users = db.users;






const AiModels = db.ai_models;

const ApiKeys = db.api_keys;

const Extensions = db.extensions;

const Surveys = db.surveys;

const FillSessions = db.fill_sessions;

const RequestQueue = db.request_queue;

const ConnectionLogs = db.connection_logs;

const Profiles = db.profiles;

const Settings = db.settings;







const AiModelsData = [
    
    {
    
        
        
            
                "name": "Groq Llama HighSpeed",
            
        
    
        
        
            
                "provider": "gemini",
            
        
    
        
        
            
                "model_name": "llama-3-13b",
            
        
    
        
        
            
                "base_url": "https://api.groq.com/v1",
            
        
    
        
        
            
                "default_config": "{temperature:0.2,max_tokens:512}",
            
        
    
        
        
            
                "typical_latency_ms": 80,
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Gemini 2.5 Flash",
            
        
    
        
        
            
                "provider": "groq",
            
        
    
        
        
            
                "model_name": "gemini-2.5-flash",
            
        
    
        
        
            
                "base_url": "https://api.gemini.google/v1",
            
        
    
        
        
            
                "default_config": "{temperature:0.1,max_tokens:512}",
            
        
    
        
        
            
                "typical_latency_ms": 60,
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "DeepSeek Free",
            
        
    
        
        
            
                "provider": "deepseek",
            
        
    
        
        
            
                "model_name": "deepseek-free-v1",
            
        
    
        
        
            
                "base_url": "https://api.deepseek.ai/v1",
            
        
    
        
        
            
                "default_config": "{temperature:0.3,max_tokens:400}",
            
        
    
        
        
            
                "typical_latency_ms": 120,
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Mixtral HighSpeed",
            
        
    
        
        
            
                "provider": "groq",
            
        
    
        
        
            
                "model_name": "mixtral-8x8",
            
        
    
        
        
            
                "base_url": "https://api.groq.com/v1/mixtral",
            
        
    
        
        
            
                "default_config": "{temperature:0.25,max_tokens:600}",
            
        
    
        
        
            
                "typical_latency_ms": 90,
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Custom Async Model",
            
        
    
        
        
            
                "provider": "groq",
            
        
    
        
        
            
                "model_name": "custom-async-1",
            
        
    
        
        
            
                "base_url": "https://internal.example.com/custom-model",
            
        
    
        
        
            
                "default_config": "{temperature:0.2,max_tokens:300}",
            
        
    
        
        
            
                "typical_latency_ms": 150,
            
        
    
        
        
            
                "is_enabled": true,
            
        
    
    },
    
];



const ApiKeysData = [
    
    {
    
        
        
            
                "name": "Groq Primary Key",
            
        
    
        
        
            
                "encrypted_key": "enc:groq_primary_abc123",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "expires_at": new Date('2027-01-01T00:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Gemini Flash Key",
            
        
    
        
        
            
                "encrypted_key": "enc:gemini_flash_def456",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "expires_at": new Date('2026-12-01T00:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "DeepSeek Free Key",
            
        
    
        
        
            
                "encrypted_key": "enc:deepseek_free_ghi789",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "expires_at": new Date('2028-01-01T00:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Mixtral Key",
            
        
    
        
        
            
                "encrypted_key": "enc:mixtral_key_jkl012",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "expires_at": new Date('2026-06-01T00:00:00Z'),
            
        
    
        
        
            
                "is_active": true,
            
        
    
    },
    
    {
    
        
        
            
                "name": "Custom Local Key",
            
        
    
        
        
            
                "encrypted_key": "enc:custom_local_mno345",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "expires_at": new Date('2026-03-01T00:00:00Z'),
            
        
    
        
        
            
                "is_active": false,
            
        
    
    },
    
];



const ExtensionsData = [
    
    {
    
        
        
            
                "title": "Smart Survey Filler",
            
        
    
        
        
            
                "slug": "smart-survey-filler",
            
        
    
        
        
            
                "description": "Core Chrome extension for automatic survey completion and management",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "paused",
            
        
    
        
        
            
                "created": new Date('2025-12-01T09:00:00Z'),
            
        
    
        
        
            
                "updated": new Date('2026-01-10T12:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "title": "Smart Survey Filler Beta",
            
        
    
        
        
            
                "slug": "smart-survey-filler-beta",
            
        
    
        
        
            
                "description": "Beta channel with advanced connection bridge and experimental UI",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                "created": new Date('2026-01-05T10:00:00Z'),
            
        
    
        
        
            
                "updated": new Date('2026-01-20T11:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "title": "Survey UI Theme Pack",
            
        
    
        
        
            
                "slug": "survey-ui-theme-pack",
            
        
    
        
        
            
                "description": "Optional UI theme variants for the floating bubble and popup",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "draft",
            
        
    
        
        
            
                "created": new Date('2025-11-20T08:00:00Z'),
            
        
    
        
        
            
                "updated": new Date('2026-01-15T09:30:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "title": "Connection Diagnostics",
            
        
    
        
        
            
                "slug": "connection-diagnostics",
            
        
    
        
        
            
                "description": "Diagnostic extension for monitoring connection bridge and logs",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "active",
            
        
    
        
        
            
                "created": new Date('2025-10-10T07:00:00Z'),
            
        
    
        
        
            
                "updated": new Date('2026-01-12T14:45:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "title": "Human Simulator Pack",
            
        
    
        
        
            
                "slug": "human-simulator-pack",
            
        
    
        
        
            
                "description": "Advanced human behavior simulation utilities for form interaction",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "paused",
            
        
    
        
        
            
                "created": new Date('2025-09-15T16:00:00Z'),
            
        
    
        
        
            
                "updated": new Date('2026-01-18T17:00:00Z'),
            
        
    
    },
    
];



const SurveysData = [
    
    {
    
        
        
            
                "title": "Customer Satisfaction Q1",
            
        
    
        
        
            
                "url": "https://example.com/surveys/customer-q1",
            
        
    
        
        
            
                "detected_on": new Date('2026-01-20T09:00:00Z'),
            
        
    
        
        
            
                "form_schema": "{fields:[{name:satisfaction,type:scale}]}",
            
        
    
        
        
            
                "page_context": "multiple_choice",
            
        
    
        
        
            
                "language": "english",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "filled",
            
        
    
    },
    
    {
    
        
        
            
                "title": "Product Feedback Form",
            
        
    
        
        
            
                "url": "https://example.org/forms/product-feedback",
            
        
    
        
        
            
                "detected_on": new Date('2026-01-18T11:30:00Z'),
            
        
    
        
        
            
                "form_schema": "{fields:[{name:feedback,type:open_ended}]}",
            
        
    
        
        
            
                "page_context": "multiple_choice",
            
        
    
        
        
            
                "language": "arabic",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "filled",
            
        
    
    },
    
    {
    
        
        
            
                "title": "Arabic Market Survey",
            
        
    
        
        
            
                "url": "https://arab.example.com/survey/market",
            
        
    
        
        
            
                "detected_on": new Date('2026-01-17T13:15:00Z'),
            
        
    
        
        
            
                "form_schema": "{fields:[{name:preference,type:multiple_choice}]}",
            
        
    
        
        
            
                "page_context": "multiple_choice",
            
        
    
        
        
            
                "language": "english",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "pending",
            
        
    
    },
    
    {
    
        
        
            
                "title": "Employee Pulse Check",
            
        
    
        
        
            
                "url": "https://intra.example.com/pulse",
            
        
    
        
        
            
                "detected_on": new Date('2026-01-15T09:45:00Z'),
            
        
    
        
        
            
                "form_schema": "{fields:[{name:mood,type:scale}]}",
            
        
    
        
        
            
                "page_context": "open_ended",
            
        
    
        
        
            
                "language": "english",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "filled",
            
        
    
    },
    
    {
    
        
        
            
                "title": "Usability Study Form",
            
        
    
        
        
            
                "url": "https://research.example.com/usability",
            
        
    
        
        
            
                "detected_on": new Date('2026-01-10T08:00:00Z'),
            
        
    
        
        
            
                "form_schema": "{fields:[{name:usability,type:open_ended}]}",
            
        
    
        
        
            
                "page_context": "open_ended",
            
        
    
        
        
            
                "language": "arabic",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "status": "pending",
            
        
    
    },
    
];



const FillSessionsData = [
    
    {
    
        
        
            
                "session_name": "Session 2026-001",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "started": new Date('2026-01-20T09:05:00Z'),
            
        
    
        
        
            
                "ended": new Date('2026-01-20T09:06:00Z'),
            
        
    
        
        
            
                "status": "queued",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "response_cache": "{answers:[{field:satisfaction,value:5}]}",
            
        
    
        
        
            
                "progress_percent": 100,
            
        
    
    },
    
    {
    
        
        
            
                "session_name": "Session 2026-002",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "started": new Date('2026-01-18T11:35:00Z'),
            
        
    
        
        
            
                "ended": new Date('2026-01-18T11:40:00Z'),
            
        
    
        
        
            
                "status": "processing",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "response_cache": "{answers:[{field:feedback,value:Good}]}",
            
        
    
        
        
            
                "progress_percent": 100,
            
        
    
    },
    
    {
    
        
        
            
                "session_name": "Session 2026-003",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "started": new Date('2026-01-17T13:20:00Z'),
            
        
    
        
        
            
                "ended": new Date('2026-01-17T13:30:00Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "response_cache": "{error:network_timeout}",
            
        
    
        
        
            
                "progress_percent": 45,
            
        
    
    },
    
    {
    
        
        
            
                "session_name": "Session 2026-004",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "started": new Date('2026-01-15T10:00:00Z'),
            
        
    
        
        
            
                "ended": new Date('2026-01-15T10:05:00Z'),
            
        
    
        
        
            
                "status": "processing",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "response_cache": "{answers:[{field:mood,value:4}]}",
            
        
    
        
        
            
                "progress_percent": 100,
            
        
    
    },
    
    {
    
        
        
            
                "session_name": "Session 2026-005",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "started": new Date('2026-01-10T08:10:00Z'),
            
        
    
        
        
            
                "ended": new Date('2026-01-10T08:12:00Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "response_cache": "{progress:50}",
            
        
    
        
        
            
                "progress_percent": 50,
            
        
    
    },
    
];



const RequestQueueData = [
    
    {
    
        
        
            
                "request_id": "req-0001",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "payload": "{task:fill_field,field:satisfaction}",
            
        
    
        
        
            
                "priority": 10,
            
        
    
        
        
            
                "attempts": 0,
            
        
    
        
        
            
                "next_retry": new Date('2026-01-20T09:05:30Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
    },
    
    {
    
        
        
            
                "request_id": "req-0002",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "payload": "{task:analyze_form,timeout:30000}",
            
        
    
        
        
            
                "priority": 8,
            
        
    
        
        
            
                "attempts": 1,
            
        
    
        
        
            
                "next_retry": new Date('2026-01-18T11:36:00Z'),
            
        
    
        
        
            
                "status": "failed",
            
        
    
    },
    
    {
    
        
        
            
                "request_id": "req-0003",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "payload": "{task:submit,retry:true}",
            
        
    
        
        
            
                "priority": 9,
            
        
    
        
        
            
                "attempts": 3,
            
        
    
        
        
            
                "next_retry": new Date('2026-01-17T13:35:00Z'),
            
        
    
        
        
            
                "status": "processing",
            
        
    
    },
    
    {
    
        
        
            
                "request_id": "req-0004",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "payload": "{task:continue_fill,progress:50}",
            
        
    
        
        
            
                "priority": 7,
            
        
    
        
        
            
                "attempts": 0,
            
        
    
        
        
            
                "next_retry": new Date('2026-01-10T08:12:00Z'),
            
        
    
        
        
            
                "status": "completed",
            
        
    
    },
    
    {
    
        
        
            
                "request_id": "req-0005",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "payload": "{task:diagnostics,level:full}",
            
        
    
        
        
            
                "priority": 5,
            
        
    
        
        
            
                "attempts": 0,
            
        
    
        
        
            
                "next_retry": new Date('2026-01-15T10:06:00Z'),
            
        
    
        
        
            
                "status": "processing",
            
        
    
    },
    
];



const ConnectionLogsData = [
    
    {
    
        
        
            
                "event": "Service worker started",
            
        
    
        
        
            
                "source": "content_script",
            
        
    
        
        
            
                "severity": "info",
            
        
    
        
        
            
                "timestamp": new Date('2026-01-20T09:00:00Z'),
            
        
    
        
        
            
                "details": "Service worker initialized and keep alive started",
            
        
    
    },
    
    {
    
        
        
            
                "event": "Content script connected",
            
        
    
        
        
            
                "source": "service_worker",
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "timestamp": new Date('2026-01-20T09:01:15Z'),
            
        
    
        
        
            
                "details": "Content script handshake completed with bridge",
            
        
    
    },
    
    {
    
        
        
            
                "event": "API request failed",
            
        
    
        
        
            
                "source": "content_script",
            
        
    
        
        
            
                "severity": "warning",
            
        
    
        
        
            
                "timestamp": new Date('2026-01-17T13:25:00Z'),
            
        
    
        
        
            
                "details": "Timeout contacting deepseek endpoint, scheduled retry",
            
        
    
    },
    
    {
    
        
        
            
                "event": "Keep alive lost and restored",
            
        
    
        
        
            
                "source": "api",
            
        
    
        
        
            
                "severity": "info",
            
        
    
        
        
            
                "timestamp": new Date('2026-01-18T11:40:00Z'),
            
        
    
        
        
            
                "details": "Temporary disconnect detected and reconnected automatically",
            
        
    
    },
    
    {
    
        
        
            
                "event": "Popup opened",
            
        
    
        
        
            
                "source": "api",
            
        
    
        
        
            
                "severity": "info",
            
        
    
        
        
            
                "timestamp": new Date('2026-01-15T10:02:00Z'),
            
        
    
        
        
            
                "details": "User opened popup for settings review",
            
        
    
    },
    
];



const ProfilesData = [
    
    {
    
        
        
            
                "name": "Default Profile",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "description": "Default auto-fill profile with conservative defaults",
            
        
    
        
        
            
                "created": new Date('2025-12-01T09:05:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "name": "Aggressive Fill",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "description": "Aggressive heuristics and fastest model selection",
            
        
    
        
        
            
                "created": new Date('2026-01-05T10:10:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "name": "Privacy First",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "description": "Minimal data retention and strict API selection",
            
        
    
        
        
            
                "created": new Date('2026-01-08T11:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "name": "Mobile Optimized",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "description": "Optimized delays and animations for mobile devices",
            
        
    
        
        
            
                "created": new Date('2025-11-20T08:20:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "name": "Research Mode",
            
        
    
        
        
            
                // type code here for "relation_one" field
            
        
    
        
        
            
                "description": "Detailed logging and extended context retention",
            
        
    
        
        
            
                "created": new Date('2025-10-10T07:30:00Z'),
            
        
    
    },
    
];



const SettingsData = [
    
    {
    
        
        
            
                "key": "keep_alive_interval",
            
        
    
        
        
            
                "value": "300000",
            
        
    
        
        
            
                "encrypted": false,
            
        
    
        
        
            
                "updated": new Date('2026-01-10T12:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "key": "max_retry_attempts",
            
        
    
        
        
            
                "value": "5",
            
        
    
        
        
            
                "encrypted": false,
            
        
    
        
        
            
                "updated": new Date('2026-01-15T09:30:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "key": "api_key_encryption_enabled",
            
        
    
        
        
            
                "value": "true",
            
        
    
        
        
            
                "encrypted": true,
            
        
    
        
        
            
                "updated": new Date('2026-01-12T14:45:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "key": "default_profile",
            
        
    
        
        
            
                "value": "Default Profile",
            
        
    
        
        
            
                "encrypted": true,
            
        
    
        
        
            
                "updated": new Date('2026-01-18T17:00:00Z'),
            
        
    
    },
    
    {
    
        
        
            
                "key": "telemetry_opt_in",
            
        
    
        
        
            
                "value": "false",
            
        
    
        
        
            
                "encrypted": false,
            
        
    
        
        
            
                "updated": new Date('2026-01-20T09:10:00Z'),
            
        
    
    },
    
];




    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            // Similar logic for "relation_many"
        
    

    
    
    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
            
            async function associateApiKeyWithModel() {
            
                const relatedModel0 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const ApiKey0 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ApiKey0?.setModel)
                {
                    await
                    ApiKey0.
                    setModel(relatedModel0);
                }
            
                const relatedModel1 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const ApiKey1 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ApiKey1?.setModel)
                {
                    await
                    ApiKey1.
                    setModel(relatedModel1);
                }
            
                const relatedModel2 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const ApiKey2 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ApiKey2?.setModel)
                {
                    await
                    ApiKey2.
                    setModel(relatedModel2);
                }
            
                const relatedModel3 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const ApiKey3 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ApiKey3?.setModel)
                {
                    await
                    ApiKey3.
                    setModel(relatedModel3);
                }
            
                const relatedModel4 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const ApiKey4 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (ApiKey4?.setModel)
                {
                    await
                    ApiKey4.
                    setModel(relatedModel4);
                }
            
        }
        
    
        
            
            async function associateApiKeyWithOwner() {
            
                const relatedOwner0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ApiKey0 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (ApiKey0?.setOwner)
                {
                    await
                    ApiKey0.
                    setOwner(relatedOwner0);
                }
            
                const relatedOwner1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ApiKey1 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (ApiKey1?.setOwner)
                {
                    await
                    ApiKey1.
                    setOwner(relatedOwner1);
                }
            
                const relatedOwner2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ApiKey2 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (ApiKey2?.setOwner)
                {
                    await
                    ApiKey2.
                    setOwner(relatedOwner2);
                }
            
                const relatedOwner3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ApiKey3 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (ApiKey3?.setOwner)
                {
                    await
                    ApiKey3.
                    setOwner(relatedOwner3);
                }
            
                const relatedOwner4 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const ApiKey4 = await ApiKeys.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (ApiKey4?.setOwner)
                {
                    await
                    ApiKey4.
                    setOwner(relatedOwner4);
                }
            
        }
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
            
            async function associateExtensionWithOwner() {
            
                const relatedOwner0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Extension0 = await Extensions.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Extension0?.setOwner)
                {
                    await
                    Extension0.
                    setOwner(relatedOwner0);
                }
            
                const relatedOwner1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Extension1 = await Extensions.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Extension1?.setOwner)
                {
                    await
                    Extension1.
                    setOwner(relatedOwner1);
                }
            
                const relatedOwner2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Extension2 = await Extensions.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Extension2?.setOwner)
                {
                    await
                    Extension2.
                    setOwner(relatedOwner2);
                }
            
                const relatedOwner3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Extension3 = await Extensions.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Extension3?.setOwner)
                {
                    await
                    Extension3.
                    setOwner(relatedOwner3);
                }
            
                const relatedOwner4 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Extension4 = await Extensions.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (Extension4?.setOwner)
                {
                    await
                    Extension4.
                    setOwner(relatedOwner4);
                }
            
        }
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
            async function associateSurveyWithExtension() {
            
                const relatedExtension0 = await Extensions.findOne({
                    offset: Math.floor(Math.random() * (await Extensions.count())),
                });
                const Survey0 = await Surveys.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Survey0?.setExtension)
                {
                    await
                    Survey0.
                    setExtension(relatedExtension0);
                }
            
                const relatedExtension1 = await Extensions.findOne({
                    offset: Math.floor(Math.random() * (await Extensions.count())),
                });
                const Survey1 = await Surveys.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Survey1?.setExtension)
                {
                    await
                    Survey1.
                    setExtension(relatedExtension1);
                }
            
                const relatedExtension2 = await Extensions.findOne({
                    offset: Math.floor(Math.random() * (await Extensions.count())),
                });
                const Survey2 = await Surveys.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Survey2?.setExtension)
                {
                    await
                    Survey2.
                    setExtension(relatedExtension2);
                }
            
                const relatedExtension3 = await Extensions.findOne({
                    offset: Math.floor(Math.random() * (await Extensions.count())),
                });
                const Survey3 = await Surveys.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Survey3?.setExtension)
                {
                    await
                    Survey3.
                    setExtension(relatedExtension3);
                }
            
                const relatedExtension4 = await Extensions.findOne({
                    offset: Math.floor(Math.random() * (await Extensions.count())),
                });
                const Survey4 = await Surveys.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (Survey4?.setExtension)
                {
                    await
                    Survey4.
                    setExtension(relatedExtension4);
                }
            
        }
        
    
        
    

    
    
    
        
    
        
            
            async function associateFillSessionWithSurvey() {
            
                const relatedSurvey0 = await Surveys.findOne({
                    offset: Math.floor(Math.random() * (await Surveys.count())),
                });
                const FillSession0 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FillSession0?.setSurvey)
                {
                    await
                    FillSession0.
                    setSurvey(relatedSurvey0);
                }
            
                const relatedSurvey1 = await Surveys.findOne({
                    offset: Math.floor(Math.random() * (await Surveys.count())),
                });
                const FillSession1 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FillSession1?.setSurvey)
                {
                    await
                    FillSession1.
                    setSurvey(relatedSurvey1);
                }
            
                const relatedSurvey2 = await Surveys.findOne({
                    offset: Math.floor(Math.random() * (await Surveys.count())),
                });
                const FillSession2 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FillSession2?.setSurvey)
                {
                    await
                    FillSession2.
                    setSurvey(relatedSurvey2);
                }
            
                const relatedSurvey3 = await Surveys.findOne({
                    offset: Math.floor(Math.random() * (await Surveys.count())),
                });
                const FillSession3 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FillSession3?.setSurvey)
                {
                    await
                    FillSession3.
                    setSurvey(relatedSurvey3);
                }
            
                const relatedSurvey4 = await Surveys.findOne({
                    offset: Math.floor(Math.random() * (await Surveys.count())),
                });
                const FillSession4 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (FillSession4?.setSurvey)
                {
                    await
                    FillSession4.
                    setSurvey(relatedSurvey4);
                }
            
        }
        
    
        
    
        
    
        
    
        
            
            async function associateFillSessionWithAi_model() {
            
                const relatedAi_model0 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const FillSession0 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FillSession0?.setAi_model)
                {
                    await
                    FillSession0.
                    setAi_model(relatedAi_model0);
                }
            
                const relatedAi_model1 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const FillSession1 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FillSession1?.setAi_model)
                {
                    await
                    FillSession1.
                    setAi_model(relatedAi_model1);
                }
            
                const relatedAi_model2 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const FillSession2 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FillSession2?.setAi_model)
                {
                    await
                    FillSession2.
                    setAi_model(relatedAi_model2);
                }
            
                const relatedAi_model3 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const FillSession3 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FillSession3?.setAi_model)
                {
                    await
                    FillSession3.
                    setAi_model(relatedAi_model3);
                }
            
                const relatedAi_model4 = await AiModels.findOne({
                    offset: Math.floor(Math.random() * (await AiModels.count())),
                });
                const FillSession4 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (FillSession4?.setAi_model)
                {
                    await
                    FillSession4.
                    setAi_model(relatedAi_model4);
                }
            
        }
        
    
        
            
            async function associateFillSessionWithApi_key() {
            
                const relatedApi_key0 = await ApiKeys.findOne({
                    offset: Math.floor(Math.random() * (await ApiKeys.count())),
                });
                const FillSession0 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (FillSession0?.setApi_key)
                {
                    await
                    FillSession0.
                    setApi_key(relatedApi_key0);
                }
            
                const relatedApi_key1 = await ApiKeys.findOne({
                    offset: Math.floor(Math.random() * (await ApiKeys.count())),
                });
                const FillSession1 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (FillSession1?.setApi_key)
                {
                    await
                    FillSession1.
                    setApi_key(relatedApi_key1);
                }
            
                const relatedApi_key2 = await ApiKeys.findOne({
                    offset: Math.floor(Math.random() * (await ApiKeys.count())),
                });
                const FillSession2 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (FillSession2?.setApi_key)
                {
                    await
                    FillSession2.
                    setApi_key(relatedApi_key2);
                }
            
                const relatedApi_key3 = await ApiKeys.findOne({
                    offset: Math.floor(Math.random() * (await ApiKeys.count())),
                });
                const FillSession3 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (FillSession3?.setApi_key)
                {
                    await
                    FillSession3.
                    setApi_key(relatedApi_key3);
                }
            
                const relatedApi_key4 = await ApiKeys.findOne({
                    offset: Math.floor(Math.random() * (await ApiKeys.count())),
                });
                const FillSession4 = await FillSessions.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (FillSession4?.setApi_key)
                {
                    await
                    FillSession4.
                    setApi_key(relatedApi_key4);
                }
            
        }
        
    
        
    
        
    

    
    
    
        
    
        
            
            async function associateRequestQueueWithSession() {
            
                const relatedSession0 = await FillSessions.findOne({
                    offset: Math.floor(Math.random() * (await FillSessions.count())),
                });
                const RequestQueue0 = await RequestQueue.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (RequestQueue0?.setSession)
                {
                    await
                    RequestQueue0.
                    setSession(relatedSession0);
                }
            
                const relatedSession1 = await FillSessions.findOne({
                    offset: Math.floor(Math.random() * (await FillSessions.count())),
                });
                const RequestQueue1 = await RequestQueue.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (RequestQueue1?.setSession)
                {
                    await
                    RequestQueue1.
                    setSession(relatedSession1);
                }
            
                const relatedSession2 = await FillSessions.findOne({
                    offset: Math.floor(Math.random() * (await FillSessions.count())),
                });
                const RequestQueue2 = await RequestQueue.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (RequestQueue2?.setSession)
                {
                    await
                    RequestQueue2.
                    setSession(relatedSession2);
                }
            
                const relatedSession3 = await FillSessions.findOne({
                    offset: Math.floor(Math.random() * (await FillSessions.count())),
                });
                const RequestQueue3 = await RequestQueue.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (RequestQueue3?.setSession)
                {
                    await
                    RequestQueue3.
                    setSession(relatedSession3);
                }
            
                const relatedSession4 = await FillSessions.findOne({
                    offset: Math.floor(Math.random() * (await FillSessions.count())),
                });
                const RequestQueue4 = await RequestQueue.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (RequestQueue4?.setSession)
                {
                    await
                    RequestQueue4.
                    setSession(relatedSession4);
                }
            
        }
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    
        
    

    
    
    
        
    
        
            
            async function associateProfileWithOwner() {
            
                const relatedOwner0 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Profile0 = await Profiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 0
                });
                if (Profile0?.setOwner)
                {
                    await
                    Profile0.
                    setOwner(relatedOwner0);
                }
            
                const relatedOwner1 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Profile1 = await Profiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 1
                });
                if (Profile1?.setOwner)
                {
                    await
                    Profile1.
                    setOwner(relatedOwner1);
                }
            
                const relatedOwner2 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Profile2 = await Profiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 2
                });
                if (Profile2?.setOwner)
                {
                    await
                    Profile2.
                    setOwner(relatedOwner2);
                }
            
                const relatedOwner3 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Profile3 = await Profiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 3
                });
                if (Profile3?.setOwner)
                {
                    await
                    Profile3.
                    setOwner(relatedOwner3);
                }
            
                const relatedOwner4 = await Users.findOne({
                    offset: Math.floor(Math.random() * (await Users.count())),
                });
                const Profile4 = await Profiles.findOne({
                    order: [['id', 'ASC']],
                    offset: 4
                });
                if (Profile4?.setOwner)
                {
                    await
                    Profile4.
                    setOwner(relatedOwner4);
                }
            
        }
        
    
        
    
        
    

    
    
    
        
    
        
    
        
    
        
    


module.exports = {
    up: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
                
                await AiModels.bulkCreate(AiModelsData);
                
            
            
                
                await ApiKeys.bulkCreate(ApiKeysData);
                
            
            
                
                await Extensions.bulkCreate(ExtensionsData);
                
            
            
                
                await Surveys.bulkCreate(SurveysData);
                
            
            
                
                await FillSessions.bulkCreate(FillSessionsData);
                
            
            
                
                await RequestQueue.bulkCreate(RequestQueueData);
                
            
            
                
                await ConnectionLogs.bulkCreate(ConnectionLogsData);
                
            
            
                
                await Profiles.bulkCreate(ProfilesData);
                
            
            
                
                await Settings.bulkCreate(SettingsData);
                
            
            await Promise.all([
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        // Similar logic for "relation_many"
                    
                
            
                
                
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                        
                        await associateApiKeyWithModel(),
                    
                
                    
                        
                        await associateApiKeyWithOwner(),
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                        
                        await associateExtensionWithOwner(),
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateSurveyWithExtension(),
                    
                
                    
                
            
                
                
                    
                
                    
                        
                        await associateFillSessionWithSurvey(),
                    
                
                    
                
                    
                
                    
                
                    
                        
                        await associateFillSessionWithAi_model(),
                    
                
                    
                        
                        await associateFillSessionWithApi_key(),
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                        
                        await associateRequestQueueWithSession(),
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                        
                        await associateProfileWithOwner(),
                    
                
                    
                
                    
                
            
                
                
                    
                
                    
                
                    
                
                    
                
            
            ]);
        
    },

    down: async (queryInterface, Sequelize) => {
        
            
            
            
            
            
            await queryInterface.bulkDelete('ai_models', null, {});
            
            
            await queryInterface.bulkDelete('api_keys', null, {});
            
            
            await queryInterface.bulkDelete('extensions', null, {});
            
            
            await queryInterface.bulkDelete('surveys', null, {});
            
            
            await queryInterface.bulkDelete('fill_sessions', null, {});
            
            
            await queryInterface.bulkDelete('request_queue', null, {});
            
            
            await queryInterface.bulkDelete('connection_logs', null, {});
            
            
            await queryInterface.bulkDelete('profiles', null, {});
            
            
            await queryInterface.bulkDelete('settings', null, {});
            
        
    },
};