--liquibase formatted sql
--changeset fai:20260512_m18_bom_shop_sync_log

CREATE TABLE IF NOT EXISTS `m18_bom_shop_sync_log` (
    `id`              BIGINT        NOT NULL AUTO_INCREMENT,
    `created`         DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `createdBy`       VARCHAR(30)   NULL     DEFAULT NULL,
    `version`         INT           NOT NULL DEFAULT '0',
    `modified`        DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `modifiedBy`      VARCHAR(30)   NULL     DEFAULT NULL,
    `deleted`         TINYINT(1)    NOT NULL DEFAULT '0',

    `bom_id`          BIGINT        NOT NULL COMMENT 'FPSMS bom.id',
    `m18_record_id`   BIGINT        NULL     DEFAULT NULL COMMENT 'M18 udfBomForShop record id when returned',
    `m18_api_status`  TINYINT(1)    NOT NULL COMMENT 'M18 response status field',
    `synced`         TINYINT(1)    NOT NULL COMMENT 'FPSMS treat as success (e.g. updated bom.m18Id)',
    `message`         VARCHAR(4000) NULL     DEFAULT NULL COMMENT 'Summary / errors',
    `request_json`    LONGTEXT      NULL COMMENT 'PUT body sent to M18',
    `response_json`   LONGTEXT      NULL COMMENT 'Parsed M18 response or error JSON',

    CONSTRAINT pk_m18_bom_shop_sync_log PRIMARY KEY (`id`),
    KEY `idx_m18_bom_shop_sync_log_bom_id` (`bom_id`),
    KEY `idx_m18_bom_shop_sync_log_created` (`created`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
