-- Migration: 006_seed_initial_data.sql
-- Initial data for multi-agent coordination system
-- Author: Rivet (Ops)
-- Target: Supabase Database (rateright-growth)

BEGIN;

-- Initialize bot status records for all 6 agents
INSERT INTO bot_status (bot_id, status, last_heartbeat, metadata) VALUES
    ('rivet', 'online', NOW(), '{"role": "Operations & Coordination", "capabilities": ["task_management", "system_monitoring", "audit"], "model": "opus"}'),
    ('builder', 'offline', NOW() - INTERVAL '1 hour', '{"role": "Code Development", "capabilities": ["coding", "deployment", "git_management"], "model": "sonnet", "workspace": "/home/ccuser/the-50-dollar-app"}'),
    ('susan', 'offline', NOW() - INTERVAL '1 hour', '{"role": "Sales & Marketing", "capabilities": ["lead_generation", "email_outreach", "crm_management"], "model": "kimi"}'),
    ('harper', 'offline', NOW() - INTERVAL '1 hour', '{"role": "Customer Success", "capabilities": ["customer_support", "onboarding", "retention"], "model": "sonnet"}'),
    ('sentinel', 'offline', NOW() - INTERVAL '1 hour', '{"role": "Legal & Compliance", "capabilities": ["contract_review", "compliance_check", "risk_assessment"], "model": "opus"}'),
    ('radar', 'offline', NOW() - INTERVAL '1 hour', '{"role": "Research & Intelligence", "capabilities": ["market_research", "competitive_analysis", "data_collection"], "model": "kimi"}')
ON CONFLICT (bot_id) DO UPDATE SET
    metadata = EXCLUDED.metadata;

-- Create initial audit log entries for system setup
INSERT INTO bot_audit_log (bot_id, action, details) VALUES
    ('rivet', 'system_setup', '{"event": "multi_agent_system_initialized", "agents_count": 6, "timestamp": "' || NOW()::text || '"}'),
    ('rivet', 'schema_migration', '{"migration": "001-006_complete", "tables_created": ["bot_tasks", "bot_comms_queue", "bot_handoffs", "bot_audit_log", "bot_status"], "status": "success"}');

-- Create sample high-priority tasks for initial system testing
INSERT INTO bot_tasks (bot_id, title, description, priority, status) VALUES
    ('rivet', 'Multi-Agent System Health Check', 'Verify all bots can connect to database and perform basic operations', 'high', 'pending'),
    ('rivet', 'Implement Heartbeat Monitoring', 'Set up automated heartbeat updates for all bot instances', 'high', 'pending'),
    ('rivet', 'Database Connection Testing', 'Test RLS policies and ensure each bot can only access appropriate data', 'medium', 'pending');

-- Create sample communication templates for common scenarios
INSERT INTO bot_comms_queue (requesting_bot, channel, recipient, message_body, status, review_notes) VALUES
    ('rivet', 'telegram', 'system_admin', 'Multi-agent coordination system has been successfully initialized. All database tables, indexes, triggers, and RLS policies are in place.', 'approved', 'System notification - auto-approved'),
    ('susan', 'email', 'test@example.com', 'Sample email template for lead outreach - this is a test message', 'draft', 'Template for testing communication approval workflow');

-- Create sample handoff scenarios for testing
INSERT INTO bot_handoffs (from_bot, to_bot, task_summary, context, status) VALUES
    ('rivet', 'builder', 'Deploy database migrations', '{"priority": "high", "migrations": ["001-006"], "environment": "production", "backup_required": true}', 'pending'),
    ('radar', 'susan', 'Process market research findings', '{"research_type": "competitor_analysis", "target_market": "construction", "findings_location": "memory/research/2026-02-16/"}', 'pending');

COMMIT;