CREATE TABLE IF NOT EXISTS entity_translate_charges (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  job_id INT UNSIGNED NOT NULL,
  reference_id VARCHAR(190) NOT NULL,
  amount DECIMAL(10,4) NOT NULL DEFAULT 0,
  unit_count INT UNSIGNED NOT NULL DEFAULT 0,
  units MEDIUMTEXT NULL DEFAULT NULL,
  refund_amount DECIMAL(10,4) NOT NULL DEFAULT 0,
  refunded_at DATETIME NULL DEFAULT NULL,
  refund_attempts TINYINT UNSIGNED NOT NULL DEFAULT 0,
  refund_error VARCHAR(255) NULL DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE KEY uniq_reference (reference_id),
  KEY idx_job (job_id, refunded_at),
  KEY idx_pending (refunded_at, refund_attempts)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
