-- 05: CREATE ocr_document_creation_log (sin foreign keys)
SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `ocr_document_creation_log` (
  `id` BIGINT AUTO_INCREMENT NOT NULL,
  `maincompany_id` INT NOT NULL,
  `user_id` INT DEFAULT NULL,
  `dimensioner_measurement_log_id` BIGINT UNSIGNED DEFAULT NULL,
  `document_type` VARCHAR(32) NOT NULL,
  `document_id` INT DEFAULT NULL,
  `document_number` VARCHAR(80) DEFAULT NULL,
  `status` VARCHAR(32) NOT NULL,
  `error_reason` LONGTEXT DEFAULT NULL,
  `raw_text` LONGTEXT DEFAULT NULL,
  `image_path` VARCHAR(255) DEFAULT NULL,
  `metadata` JSON DEFAULT NULL,
  `created_at` DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)',
  INDEX `IDX_1D14178618C8CC62` (`maincompany_id`),
  INDEX `IDX_1D141786A76ED395` (`user_id`),
  INDEX `IDX_1D141786BA7F5D5D` (`dimensioner_measurement_log_id`),
  INDEX `idx_ocr_doc_log_company_created` (`maincompany_id`, `created_at`),
  INDEX `idx_ocr_doc_log_type_status_created` (`document_type`, `status`, `created_at`),
  PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
