CREATE TABLE IF NOT EXISTS fact_review_feedback (
  id CHAR(36) NOT NULL PRIMARY KEY,
  law_firm_id CHAR(36) NOT NULL,
  client_id CHAR(36) NOT NULL,
  case_id CHAR(36) NULL,
  case_fact_id CHAR(36) NULL,
  data_field_id CHAR(36) NOT NULL,
  review_action VARCHAR(30) NOT NULL,
  previous_raw_value TEXT NULL,
  previous_normalized_hash CHAR(64) NULL,
  corrected_raw_value TEXT NULL,
  corrected_normalized_hash CHAR(64) NULL,
  source_hint TEXT NULL,
  search_hint TEXT NULL,
  feedback_note TEXT NULL,
  created_by_user_id CHAR(36) NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted_at TIMESTAMP NULL DEFAULT NULL,
  KEY idx_fact_review_feedback_case_fact (case_fact_id, created_at),
  KEY idx_fact_review_feedback_case (case_id, created_at),
  KEY idx_fact_review_feedback_client_field (client_id, data_field_id, created_at),
  KEY idx_fact_review_feedback_action (review_action, created_at),
  KEY idx_fact_review_feedback_prev_hash (data_field_id, previous_normalized_hash)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
