-- 租户访客默认楼层策略（电梯应用库）
-- 设计说明：docs/business/租户访客默认楼层-数据库配置阶段技术设计.md

CREATE TABLE IF NOT EXISTS tenant_visitor_floor_policy (
  id              VARCHAR(32)  NOT NULL COMMENT '主键',
  business_id     VARCHAR(64)  NOT NULL COMMENT '机构/租户 ID',
  policy_type     VARCHAR(32)  NOT NULL DEFAULT 'INTERSECT_ALLOWLIST' COMMENT '策略类型',
  allow_zone_ids  TEXT         NULL COMMENT 'JSON 数组，zoneId 列表',
  building_id     VARCHAR(64)  NULL COMMENT '预留：楼栋维度；租户默认填 NULL',
  enabled         TINYINT(1)   NOT NULL DEFAULT 1 COMMENT '1 启用 0 停用',
  policy_version  BIGINT       NOT NULL DEFAULT 1 COMMENT '配置版本号',
  remark          VARCHAR(256) NULL,
  created_by      VARCHAR(64)  NULL,
  created_at      BIGINT       NULL,
  updated_by      VARCHAR(64)  NULL,
  updated_at      BIGINT       NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uk_biz_building (business_id, building_id),
  KEY idx_business_enabled (business_id, enabled)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='租户访客默认楼层策略（与组织 floorList 求交）';

-- 示例（实施时替换占位符后执行）
-- INSERT INTO tenant_visitor_floor_policy
-- (id, business_id, policy_type, allow_zone_ids, building_id, enabled, policy_version, remark, created_at, updated_at)
-- VALUES
-- (REPLACE(UUID(),'-',''), 'REPLACE_WITH_BUSINESS_ID', 'INTERSECT_ALLOWLIST',
--  '["REPLACE_ZONE_A","REPLACE_ZONE_B"]', NULL, 1, 1, '实施录入', UNIX_TIMESTAMP(NOW())*1000, UNIX_TIMESTAMP(NOW())*1000);
