-- 到货交接单表创建脚本
CREATE TABLE IF NOT EXISTS `arrival_handover_forms` (
  `Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `HandoverNumber` VARCHAR(100) NOT NULL COMMENT '交接单号',
  `LogisticsProviderArrivalTime` DATETIME NULL COMMENT '头程物流商送达时间',
  `ReceiptTime` DATETIME NULL COMMENT '收货时间',
  `POD` TEXT NULL COMMENT 'POD (Proof of Delivery) 图片链接，多张用逗号隔开',
  `Remarks` TEXT NULL COMMENT '备注',
  `Creator` VARCHAR(50) NOT NULL COMMENT '创建人',
  `CreatedAt` DATETIME NOT NULL COMMENT '创建时间',
  `UpdatedAt` DATETIME NOT NULL COMMENT '更新时间',
  `TimeZone` VARCHAR(50) NULL COMMENT '时区',
  `Status` INT NOT NULL DEFAULT 0 COMMENT '状态：0=草稿，1=已到货',
  PRIMARY KEY (`Id`),
  UNIQUE INDEX `UQ_HandoverNumber` (`HandoverNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 出货交接单表创建脚本
CREATE TABLE IF NOT EXISTS `shipping_handover_forms` (
  `Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `HandoverNumber` VARCHAR(100) NOT NULL COMMENT '交接单号',
  `BigBagCount` INT NOT NULL COMMENT '大包数（袋牌数量）',
  `SmallBagCount` INT NOT NULL COMMENT '小包数（包裹数量）',
  `Channel` VARCHAR(100) NOT NULL COMMENT '渠道',
  `DeliveryTime` DATETIME NULL COMMENT '交货时间',
  `POD` TEXT NULL COMMENT 'POD (Proof of Delivery) 图片链接，多张用逗号隔开',
  `Remarks` TEXT NULL COMMENT '备注',
  `Creator` VARCHAR(50) NOT NULL COMMENT '创建人',
  `CreatedAt` DATETIME NOT NULL COMMENT '创建时间',
  `UpdatedAt` DATETIME NOT NULL COMMENT '更新时间',
  `TimeZone` VARCHAR(50) NULL COMMENT '时区',
  `Status` INT NOT NULL DEFAULT 0 COMMENT '状态：0=草稿，1=已出库',
  PRIMARY KEY (`Id`),
  UNIQUE INDEX `UQ_HandoverNumber` (`HandoverNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 出货交接单与袋牌关联表创建脚本
CREATE TABLE IF NOT EXISTS `shipping_handover_form_bag_tags` (
  `Id` INT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `ShippingHandoverFormId` INT NOT NULL COMMENT '出货交接单ID',
  `BagTagId` INT NOT NULL COMMENT '袋牌ID',
  `TagNumber` VARCHAR(100) NOT NULL COMMENT '袋牌号码',
  `CreatedAt` DATETIME NOT NULL COMMENT '创建时间',
  PRIMARY KEY (`Id`),
  INDEX `IX_ShippingHandoverFormId` (`ShippingHandoverFormId`),
  INDEX `IX_BagTagId` (`BagTagId`),
  UNIQUE INDEX `UQ_BagTagId` (`BagTagId`),
  CONSTRAINT `FK_shipping_handover_form_bag_tags_shipping_handover_forms` FOREIGN KEY (`ShippingHandoverFormId`) REFERENCES `shipping_handover_forms` (`Id`) ON DELETE CASCADE,
  CONSTRAINT `FK_shipping_handover_form_bag_tags_bag_tags` FOREIGN KEY (`BagTagId`) REFERENCES `bag_tags` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;