-- M002 OPERA 模拟骨架：每个已确认任务固定生成两条模拟操作。
CREATE TABLE workflow_reservation_opera_operation (
    id BIGINT NOT NULL COMMENT 'OPERA 模拟操作 ID',
    hotel_id VARCHAR(64) NOT NULL COMMENT '酒店或业务上下文 ID',
    order_id BIGINT NOT NULL COMMENT '关联订单 ID',
    task_id BIGINT NOT NULL COMMENT '关联任务 ID',
    operation_sequence INT NOT NULL COMMENT '任务内模拟操作顺序，从 1 开始',
    operation_code VARCHAR(64) NOT NULL COMMENT '模拟操作代码，第一版固定两类',
    operation_name VARCHAR(128) NOT NULL COMMENT '模拟操作展示名称',
    operation_status VARCHAR(32) NOT NULL COMMENT '操作状态：PENDING、SUCCEEDED、FAILED',
    request_payload_json LONGTEXT NULL COMMENT '模拟请求 JSON，来源于 confirmed_payload_json 的低耦合摘要',
    attempt_count INT NOT NULL DEFAULT 0 COMMENT '已执行 attempt 次数',
    last_attempt_id BIGINT NULL COMMENT '最近一次 attempt ID',
    last_error_message VARCHAR(512) NULL COMMENT '最近一次失败原因摘要',
    created_at DATETIME(6) NOT NULL COMMENT '记录创建 UTC 时间',
    updated_at DATETIME(6) NOT NULL COMMENT '记录更新 UTC 时间',
    PRIMARY KEY (id),
    UNIQUE KEY uk_reservation_opera_operation_sequence (hotel_id, task_id, operation_sequence),
    KEY idx_reservation_opera_operation_task_status (hotel_id, task_id, operation_status),
    KEY idx_reservation_opera_operation_order (hotel_id, order_id, operation_sequence)
) COMMENT='Reservation OPERA 模拟操作表，第一版每个任务固定两条操作';

-- M002 OPERA 模拟骨架：每次执行或重试都会生成一条 attempt。
CREATE TABLE workflow_reservation_opera_operation_attempt (
    id BIGINT NOT NULL COMMENT 'OPERA 模拟操作 attempt ID',
    hotel_id VARCHAR(64) NOT NULL COMMENT '酒店或业务上下文 ID',
    order_id BIGINT NOT NULL COMMENT '关联订单 ID',
    task_id BIGINT NOT NULL COMMENT '关联任务 ID',
    operation_id BIGINT NOT NULL COMMENT '关联 OPERA 模拟操作 ID',
    attempt_number INT NOT NULL COMMENT '同一操作内第几次 attempt，从 1 开始',
    attempt_status VARCHAR(32) NOT NULL COMMENT 'attempt 状态：SUCCEEDED、FAILED',
    request_payload_json LONGTEXT NULL COMMENT '本次模拟请求 JSON',
    response_payload_json LONGTEXT NULL COMMENT '本次模拟响应 JSON',
    error_message VARCHAR(512) NULL COMMENT '失败原因摘要',
    started_at DATETIME(6) NOT NULL COMMENT 'attempt 开始 UTC 时间',
    finished_at DATETIME(6) NOT NULL COMMENT 'attempt 结束 UTC 时间',
    created_at DATETIME(6) NOT NULL COMMENT '记录创建 UTC 时间',
    PRIMARY KEY (id),
    UNIQUE KEY uk_reservation_opera_attempt_number (hotel_id, operation_id, attempt_number),
    KEY idx_reservation_opera_attempt_task (hotel_id, task_id, created_at),
    KEY idx_reservation_opera_attempt_operation (hotel_id, operation_id, attempt_number)
) COMMENT='Reservation OPERA 模拟操作 attempt 表，记录执行和重试结果';
