-- +goose Up

CREATE TABLE IF NOT EXISTS listing_status_events (
  id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
  listing_id BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
  owner_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '号主ID',
  event_type VARCHAR(32) NOT NULL COMMENT '事件类型: published/offline/rented/completed/sealed/abnormal',
  from_status VARCHAR(32) NOT NULL DEFAULT '' COMMENT '变更前状态',
  to_status VARCHAR(32) NOT NULL DEFAULT '' COMMENT '变更后状态',
  source VARCHAR(32) NOT NULL DEFAULT '' COMMENT '来源: seller/admin/review/order/pickup/dispute/system',
  actor_type VARCHAR(16) NOT NULL DEFAULT '' COMMENT '操作者类型: user/admin/system',
  actor_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '操作者ID',
  remark VARCHAR(255) NOT NULL DEFAULT '' COMMENT '备注',
  created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '事件时间',
  KEY idx_listing_status_events_day_type (created_at, event_type),
  KEY idx_listing_status_events_type_source_day (event_type, source, created_at),
  KEY idx_listing_status_events_listing (listing_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商品上架/下架/交易离架状态事件';

-- +goose Down

DROP TABLE IF EXISTS listing_status_events;
