-- Actual production schema (as already deployed / provided by the user).
-- Replaces the earlier placeholder "calls" table from the first draft of this port.
--
-- Two tables because the flattened record has more columns than comfortably fit in one
-- table/row (MySQL's own limits on row size and index-key length), so it was split in two,
-- both keyed on the same task_id. part2.task_id is effectively a 1:1 extension of part1.

CREATE TABLE `kserve_ai_voice_lead_qualification_received_part1` (
  `timestamp` datetime DEFAULT NULL,
  `run_id` varchar(255) DEFAULT NULL,
  `task_id` varchar(255) NOT NULL,
  `agent` varchar(255) DEFAULT NULL,
  `status` varchar(100) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `task_objective` text DEFAULT NULL,
  `input_lead_id` varchar(255) DEFAULT NULL,
  `input_name` varchar(255) DEFAULT NULL,
  `input_email` varchar(100) DEFAULT NULL,
  `input_contact_number` varchar(100) DEFAULT NULL,
  `input_alternate_number` varchar(100) DEFAULT NULL,
  `input_subject` text DEFAULT NULL,
  `input_inquiry` text DEFAULT NULL,
  `input_ivr_url` text DEFAULT NULL,
  `input_data_source` varchar(255) DEFAULT NULL,
  `input_created` datetime DEFAULT NULL,
  `input_quality` varchar(100) DEFAULT NULL,
  `output_call_id` varchar(255) DEFAULT NULL,
  `output_customer` varchar(255) DEFAULT NULL,
  `output_contact_number` varchar(50) DEFAULT NULL,
  `output_start_time` datetime DEFAULT NULL,
  `output_end_time` datetime DEFAULT NULL,
  `output_duration` varchar(50) DEFAULT NULL,
  `output_recording_url` text DEFAULT NULL,
  `output_transcript` longtext DEFAULT NULL,
  `output_call_status` varchar(100) DEFAULT NULL,
  `output_call_type` varchar(100) DEFAULT NULL,
  `output_call_end_reason` text DEFAULT NULL,
  `output_post_call_data_classification_summary` text DEFAULT NULL,
  `output_post_call_data_summary_status` varchar(100) DEFAULT NULL,
  `output_post_call_data_summary_summary` longtext DEFAULT NULL,
  `output_post_call_data_summary_name` varchar(255) DEFAULT NULL,
  `output_post_call_data_summary_contact` varchar(255) DEFAULT NULL,
  `output_post_call_data_summary_callback_datetime` datetime DEFAULT NULL,
  `output_post_call_data_summary_hours_from_now` decimal(10,2) DEFAULT NULL,
  `output_post_call_data_follow_up_required` varchar(50) DEFAULT NULL,
  `output_post_call_data_call_evaluation_session_id` varchar(255) DEFAULT NULL,
  `output_post_call_data_call_evaluation_evaluation_results` longtext DEFAULT NULL,
  `eval_quality_total_turns` int(11) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_total_turns',
  `eval_quality_avg_response_time` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_avg_response_time',
  `eval_quality_avg_similarity` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_avg_similarity',
  `eval_quality_avg_relevancy` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_avg_relevancy',
  `eval_quality_avg_completeness` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_avg_completeness',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`task_id`),
  KEY `idx_timestamp` (`timestamp`),
  KEY `idx_run_id` (`run_id`),
  KEY `idx_input_lead_id` (`input_lead_id`),
  KEY `idx_output_call_id` (`output_call_id`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `kserve_ai_voice_lead_qualification_received_part2` (
  `task_id` varchar(255) NOT NULL,
  `eval_quality_avg_accuracy` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_avg_accuracy',
  `eval_quality_questions_matched` int(11) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_questions_matched',
  `eval_quality_overall_quality_score` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_call_evaluation_quality_metrics_overall_quality_score',
  `output_post_call_data_profile_summary_tone` varchar(100) DEFAULT NULL,
  `output_post_call_data_profile_summary_engagement` varchar(100) DEFAULT NULL,
  `output_post_call_data_profile_summary_interest_level` varchar(100) DEFAULT NULL,
  `output_post_call_data_profile_summary_objections` text DEFAULT NULL,
  `output_post_call_data_profile_summary_questions_asked` text DEFAULT NULL,
  `output_post_call_data_profile_summary_pain_points` text DEFAULT NULL,
  `output_post_call_data_profile_summary_outcome` text DEFAULT NULL,
  `output_post_call_data_profile_summary_next_action` text DEFAULT NULL,
  `output_post_call_data_profile_summary_callback_requested` varchar(50) DEFAULT NULL,
  `output_post_call_data_profile_summary_summary_text` longtext DEFAULT NULL,
  `output_post_call_data_realtime_agent_evaluation_session_id` varchar(255) DEFAULT NULL,
  `output_post_call_data_realtime_agent_evaluation_agent_id` varchar(255) DEFAULT NULL,
  `realtime_llm_latency_count` int(11) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_count',
  `realtime_llm_latency_avg` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_avg',
  `realtime_llm_latency_min` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_min',
  `realtime_llm_latency_max` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_max',
  `realtime_llm_latency_p95` decimal(10,4) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_p95',
  `realtime_llm_latency_unit` varchar(50) DEFAULT NULL COMMENT 'output_post_call_data_realtime_agent_evaluation_llm_latency_unit',
  `output_post_call_data_realtime_agent_evaluation_status` varchar(100) DEFAULT NULL,
  `output_post_call_data_realtime_agent_evaluation_reason` text DEFAULT NULL,
  `output_post_call_data_structured_data_city` varchar(255) DEFAULT NULL,
  `output_post_call_data_structured_data_status` varchar(100) DEFAULT NULL,
  `output_post_call_data_structured_data_context` text DEFAULT NULL,
  `output_post_call_data_structured_data_urgency` varchar(100) DEFAULT NULL,
  `output_post_call_data_structured_data_email_id` varchar(255) DEFAULT NULL,
  `output_post_call_data_structured_data_lead_name` varchar(255) DEFAULT NULL,
  `output_post_call_data_structured_data_date_time` datetime DEFAULT NULL,
  `output_post_call_data_structured_data_lead_intent` text DEFAULT NULL,
  `output_post_call_data_structured_data_contact_number` varchar(50) DEFAULT NULL,
  `output_post_call_data_structured_data_additional_notes` text DEFAULT NULL,
  `output_post_call_data_structured_data_service_category` varchar(255) DEFAULT NULL,
  `output_post_call_data_structured_data_source_confidence` varchar(250) DEFAULT NULL,
  `output_post_call_data_structured_data_alternate_contact_number` varchar(50) DEFAULT NULL,
  `output_post_call_data_structured_data_outcome` text DEFAULT NULL,
  `output_post_call_data_follow_up_time` varchar(250) DEFAULT NULL,
  `output_post_call_data_follow_up_reason` text DEFAULT NULL,
  `output_post_call_data_follow_up_status` varchar(100) DEFAULT NULL,
  `output_post_call_data_structured_data_company_name` varchar(255) DEFAULT NULL,
  `input_company` varchar(255) DEFAULT NULL,
  `output_post_call_data_structured_data_end_call_reason` text DEFAULT NULL,
  `output_post_call_data_structured_data_customer_type` varchar(100) DEFAULT NULL,
  `transfer_status` varchar(100) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`task_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
