/**
 * ============================================================
 * 表结构定义文件
 * ============================================================
 * 
 * 严格参考:
 *   - claude-dds.md (完善的7张数据表 + 字段设计)
 *   - gemini-dds.md (核心锚表 + 部署实例模型)
 *   - 金山多维数据表格-PRD.md (原始字段需求)
 * 
 * 综合以上文档，最终确定 7 张数据表的完整字段定义。
 * 
 * 字段类型参考 (WPS 开放平台 多维表格参数说明):
 * ┌──────────────────┬─────────────────────────┐
 * │ 类型标识          │ 说明                     │
 * ├──────────────────┼─────────────────────────┤
 * │ SingleLineText   │ 单行文本                 │
 * │ MultiLineText    │ 多行文本 (支持富文本)     │
 * │ Number           │ 数值                     │
 * │ SingleSelect     │ 单选                     │
 * │ MultipleSelect   │ 多选                     │
 * │ Date             │ 日期                     │
 * │ Checkbox         │ 复选框 (是/否)            │
 * │ Url              │ 超链接                    │
 * │ Phone            │ 电话                     │
 * │ Email            │ 电子邮箱                  │
 * │ AutoNumber       │ 自动编号                  │
 * │ Attachment       │ 附件                     │
 * │ Member           │ 成员/人员                 │
 * │ Formula          │ 公式                     │
 * │ Currency         │ 货币                     │
 * │ Percent          │ 百分比                    │
 * │ Rating           │ 等级/星级                 │
 * │ Complete         │ 进度条                    │
 * └──────────────────┴─────────────────────────┘
 * 
 * 注意: 关联字段 (Link) 和引用字段 (Lookup) 需要目标表的 sheet_id，
 *       因此需要在所有表创建完成后，通过第二轮 API 调用来建立。
 */

// ============================================================
// 表1: 项目基本信息表 <行业组/售前人员填写>
// ============================================================
const TABLE_PROJECT_INFO = {
  name: "项目基本信息表",
  description: "行业组/售前人员通过表单提交，记录项目的基本信息和部署前提条件",
  fields: [
    {
      name: "项目名称",
      type: "SingleLineText",
    },
    {
      name: "行业组接口人",
      type: "SingleLineText",
    },
    {
      name: "行业组接口人电话",
      type: "Phone",
    },
    {
      name: "省份",
      type: "SingleSelect",
      data: {
        options: [
          { name: "北京" }, { name: "天津" }, { name: "河北" },
          { name: "山西" }, { name: "内蒙古" }, { name: "辽宁" },
          { name: "吉林" }, { name: "黑龙江" }, { name: "上海" },
          { name: "江苏" }, { name: "浙江" }, { name: "安徽" },
          { name: "福建" }, { name: "江西" }, { name: "山东" },
          { name: "河南" }, { name: "湖北" }, { name: "湖南" },
          { name: "广东" }, { name: "广西" }, { name: "海南" },
          { name: "重庆" }, { name: "四川" }, { name: "贵州" },
          { name: "云南" }, { name: "西藏" }, { name: "陕西" },
          { name: "甘肃" }, { name: "青海" }, { name: "宁夏" },
          { name: "新疆" },
        ],
      },
    },
    {
      name: "城市",
      type: "SingleLineText",
    },
    {
      name: "项目类型",
      type: "SingleSelect",
      data: {
        options: [
          { name: "新部署", color_index: 1 },
          { name: "升级", color_index: 2 },
          { name: "迁移", color_index: 3 },
          { name: "扩容", color_index: 4 },
        ],
      },
    },
    {
      name: "部署优先级",
      type: "SingleSelect",
      data: {
        options: [
          { name: "P0-紧急", color_index: 7 },
          { name: "P1-高", color_index: 6 },
          { name: "P2-中", color_index: 3 },
          { name: "P3-低", color_index: 1 },
        ],
      },
    },
    {
      name: "部署飞服平台",
      type: "Checkbox",
    },
    {
      name: "飞服平台版本",
      type: "SingleLineText",
    },
    {
      name: "部署监管平台",
      type: "Checkbox",
    },
    {
      name: "监管平台版本",
      type: "SingleLineText",
    },
    {
      name: "期望部署日期",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd",
      },
    },
    {
      name: "部署必要条件说明",
      type: "MultiLineText",
    },
    {
      name: "必要条件是否满足",
      type: "SingleSelect",
      data: {
        options: [
          { name: "是", color_index: 1 },
          { name: "否", color_index: 7 },
          { name: "部分满足", color_index: 3 },
        ],
      },
    },
    {
      name: "条件不满足说明",
      type: "MultiLineText",
    },
    {
      name: "部署资源信息",
      type: "Attachment",
    },
    {
      name: "特殊要求备注",
      type: "MultiLineText",
    },
  ],
};

// ============================================================
// 表2: 项目本地化部署升级信息表 <行业组人员填写>
// ============================================================
const TABLE_UPGRADE_INFO = {
  name: "项目本地化部署升级信息表",
  description: "行业组提交升级需求，关联已有项目",
  fields: [
    {
      name: "项目名称",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目基本信息表」
    },
    {
      name: "升级类型",
      type: "SingleSelect",
      data: {
        options: [
          { name: "全量升级", color_index: 1 },
          { name: "增量升级", color_index: 2 },
          { name: "热修复", color_index: 3 },
          { name: "回滚", color_index: 7 },
        ],
      },
    },
    {
      name: "当前版本（飞服）",
      type: "SingleLineText",
    },
    {
      name: "目标版本（飞服）",
      type: "SingleLineText",
    },
    {
      name: "当前版本（监管）",
      type: "SingleLineText",
    },
    {
      name: "目标版本（监管）",
      type: "SingleLineText",
    },
    {
      name: "升级影响评估",
      type: "MultiLineText",
    },
    {
      name: "回滚方案",
      type: "MultiLineText",
    },
    {
      name: "期望升级开始时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd",
      },
    },
    {
      name: "期望升级结束时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd",
      },
    },
    {
      name: "部署资源信息",
      type: "Attachment",
    },
  ],
};

// ============================================================
// 表3: 项目本地化部署状态表 <核心锚表> <交付部署特战队填写>
// ============================================================
const TABLE_DEPLOY_STATUS = {
  name: "项目本地化部署状态表",
  description: "核心锚表 — 每次部署/升级对应一行，所有子表关联到此表",
  fields: [
    {
      name: "部署编号",
      type: "AutoNumber",
      data: {
        number_format: "000000",
      },
    },
    {
      name: "来源类型",
      type: "SingleSelect",
      data: {
        options: [
          { name: "首次部署", color_index: 1 },
          { name: "升级部署", color_index: 2 },
        ],
      },
    },
    {
      name: "关联项目",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目基本信息表」
    },
    {
      name: "关联升级记录",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目本地化部署升级信息表」
    },
    {
      name: "部署状态",
      type: "SingleSelect",
      data: {
        options: [
          { name: "待排期", color_index: 0 },
          { name: "已排期", color_index: 1 },
          { name: "环境准备中", color_index: 2 },
          { name: "部署中", color_index: 3 },
          { name: "验证中", color_index: 4 },
          { name: "已完成", color_index: 5 },
          { name: "部署异常", color_index: 7 },
          { name: "已暂停", color_index: 6 },
          { name: "已取消", color_index: 8 },
        ],
      },
    },
    {
      name: "部署结果",
      type: "SingleSelect",
      data: {
        options: [
          { name: "成功", color_index: 1 },
          { name: "失败", color_index: 7 },
          { name: "部分成功", color_index: 3 },
        ],
      },
    },
    {
      name: "部署优先级",
      type: "SingleSelect",
      data: {
        options: [
          { name: "P0-紧急", color_index: 7 },
          { name: "P1-高", color_index: 6 },
          { name: "P2-中", color_index: 3 },
          { name: "P3-低", color_index: 1 },
        ],
      },
    },
    {
      name: "当前进度/卡点说明",
      type: "MultiLineText",
    },
    {
      name: "计划开始时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd HH:mm",
      },
    },
    {
      name: "计划结束时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd HH:mm",
      },
    },
    {
      name: "实际开始时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd HH:mm",
      },
    },
    {
      name: "实际结束时间",
      type: "Date",
      data: {
        number_format: "yyyy-MM-dd HH:mm",
      },
    },
    {
      name: "命名空间",
      type: "SingleLineText",
      // 唯一标识，如 fs-xiongan-prod
    },
    {
      name: "部署负责人",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后可改为「成员 (Member)」字段类型
    },
    {
      name: "部署人电话",
      type: "Phone",
    },
    {
      name: "备注",
      type: "MultiLineText",
    },
  ],
};

// ============================================================
// 表4: 项目部署环境信息表 <交付部署特战队填写>
// ============================================================
const TABLE_ENV_INFO = {
  name: "项目部署环境信息表",
  description: "一机一行，记录每台主机的详细信息",
  fields: [
    {
      name: "所属部署",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目本地化部署状态表」
    },
    {
      name: "公网IP",
      type: "SingleLineText",
    },
    {
      name: "能否访问公网",
      type: "Checkbox",
    },
    {
      name: "内网IP",
      type: "SingleLineText",
    },
    {
      name: "SSH端口",
      type: "Number",
      data: {
        number_format: "0",
      },
    },
    {
      name: "SSH用户名",
      type: "SingleLineText",
    },
    {
      name: "密码存储方式",
      type: "SingleSelect",
      data: {
        options: [
          { name: "密码管理器", color_index: 1 },
          { name: "加密文档", color_index: 2 },
          { name: "其他", color_index: 3 },
        ],
      },
    },
    {
      name: "主机功能",
      type: "SingleSelect",
      data: {
        options: [
          { name: "master", color_index: 1 },
          { name: "worker", color_index: 2 },
          { name: "storage", color_index: 3 },
          { name: "doris", color_index: 4 },
        ],
      },
    },
    {
      name: "CPU架构",
      type: "SingleSelect",
      data: {
        options: [
          { name: "amd64", color_index: 1 },
          { name: "arm64", color_index: 2 },
        ],
      },
    },
    {
      name: "主机状态",
      type: "SingleSelect",
      data: {
        options: [
          { name: "待交付", color_index: 0 },
          { name: "已交付", color_index: 1 },
          { name: "已初始化", color_index: 2 },
          { name: "运行中", color_index: 3 },
          { name: "异常", color_index: 7 },
        ],
      },
    },
    {
      name: "操作系统",
      type: "SingleSelect",
      data: {
        options: [
          { name: "CentOS 7", color_index: 1 },
          { name: "CentOS 8", color_index: 2 },
          { name: "Ubuntu 20.04", color_index: 3 },
          { name: "Ubuntu 22.04", color_index: 4 },
          { name: "其他", color_index: 5 },
        ],
      },
    },
    {
      name: "CPU核心数",
      type: "Number",
      data: {
        number_format: "0",
      },
    },
    {
      name: "CPU型号",
      type: "SingleLineText",
    },
    {
      name: "内存大小(GB)",
      type: "Number",
      data: {
        number_format: "0",
      },
    },
    {
      name: "系统盘大小(GB)",
      type: "Number",
      data: {
        number_format: "0",
      },
    },
    {
      name: "数据盘大小(GB)",
      type: "Number",
      data: {
        number_format: "0",
      },
    },
    {
      name: "GPU信息",
      type: "SingleLineText",
    },
    {
      name: "备注信息",
      type: "MultiLineText",
    },
  ],
};

// ============================================================
// 表5: 项目部署网络信息表 <交付部署特战队填写>
// ============================================================
const TABLE_NET_INFO = {
  name: "项目部署网络信息表",
  description: "记录每次部署的网络访问信息",
  fields: [
    {
      name: "所属部署",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目本地化部署状态表」
    },
    {
      name: "访问地址",
      type: "Url",
    },
    {
      name: "是否开启SSL",
      type: "Checkbox",
    },
    {
      name: "端口信息说明",
      type: "MultiLineText",
    },
    {
      name: "网络环境",
      type: "SingleSelect",
      data: {
        options: [
          { name: "完全内网", color_index: 1 },
          { name: "单主机公网", color_index: 2 },
          { name: "全访问公网", color_index: 3 },
        ],
      },
    },
    {
      name: "主机管理方式",
      type: "SingleSelect",
      data: {
        options: [
          { name: "堡垒机", color_index: 1 },
          { name: "跳板机", color_index: 2 },
          { name: "直接访问", color_index: 3 },
          { name: "VPN", color_index: 4 },
        ],
      },
    },
    {
      name: "管理后台地址",
      type: "Url",
    },
    {
      name: "VPN下载地址",
      type: "Url",
    },
    {
      name: "VPN账号信息存储位置",
      type: "SingleLineText",
      // 安全策略: 实际密码不存入多维表格，仅记录密码管理平台的路径/编号
    },
    {
      name: "备注",
      type: "MultiLineText",
    },
  ],
};

// ============================================================
// 表6: 项目部署中间件信息表 <交付部署特战队填写>
// ============================================================
const TABLE_MIDDLEWARE_INFO = {
  name: "项目部署中间件信息表",
  description: "每行一个中间件实例，每次部署固定创建7条记录",
  fields: [
    {
      name: "所属部署",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目本地化部署状态表」
    },
    {
      name: "中间件类型",
      type: "SingleSelect",
      data: {
        options: [
          { name: "MySQL", color_index: 1 },
          { name: "Redis", color_index: 2 },
          { name: "RabbitMQ", color_index: 3 },
          { name: "EMQX", color_index: 4 },
          { name: "NACOS", color_index: 5 },
          { name: "K8S Dashboard", color_index: 6 },
          { name: "MINIO", color_index: 7 },
        ],
      },
    },
    {
      name: "中间件版本",
      type: "SingleLineText",
    },
    {
      name: "部署方式",
      type: "SingleSelect",
      data: {
        options: [
          { name: "容器化", color_index: 1 },
          { name: "主机部署", color_index: 2 },
          { name: "云服务", color_index: 3 },
        ],
      },
    },
    {
      name: "是否暴露公网",
      type: "Checkbox",
    },
    {
      name: "公网端口",
      type: "SingleLineText",
    },
    {
      name: "内网IP",
      type: "SingleLineText",
    },
    {
      name: "内网端口",
      type: "SingleLineText",
    },
    {
      name: "用户名",
      type: "SingleLineText",
    },
    {
      name: "密码存储位置",
      type: "SingleLineText",
      // 安全策略: 实际密码不存入多维表格
    },
    {
      name: "管理后台地址",
      type: "Url",
    },
  ],
};

// ============================================================
// 表7: 项目部署业务信息表 <交付部署特战队填写>
// ============================================================
const TABLE_BIZ_INFO = {
  name: "项目部署业务信息表",
  description: "记录每个微服务的部署信息",
  fields: [
    {
      name: "所属部署",
      type: "SingleLineText",
      // 🔧 人工操作: 创建完成后需改为「关联字段」→ 关联「项目本地化部署状态表」
    },
    {
      name: "微服务名称",
      type: "SingleLineText",
    },
    {
      name: "微服务分支",
      type: "SingleLineText",
    },
    {
      name: "微服务镜像",
      type: "SingleLineText",
      // gemini-dds: 需严格保持三段式规范，如 ${HARBOR_HOST}/cmii/nginx:latest
    },
    {
      name: "微服务版本",
      type: "SingleLineText",
    },
    {
      name: "部署状态",
      type: "SingleSelect",
      data: {
        options: [
          { name: "待部署", color_index: 0 },
          { name: "部署中", color_index: 3 },
          { name: "运行中", color_index: 1 },
          { name: "异常", color_index: 7 },
          { name: "已下线", color_index: 6 },
        ],
      },
    },
  ],
};

// ============================================================
// 导出所有表定义 (按创建顺序)
// ============================================================
const ALL_TABLES = [
  TABLE_PROJECT_INFO,       // 1. 项目基本信息表
  TABLE_UPGRADE_INFO,       // 2. 升级信息表
  TABLE_DEPLOY_STATUS,      // 3. 部署状态表 (核心锚表)
  TABLE_ENV_INFO,           // 4. 环境信息表
  TABLE_NET_INFO,           // 5. 网络信息表
  TABLE_MIDDLEWARE_INFO,    // 6. 中间件信息表
  TABLE_BIZ_INFO,           // 7. 业务信息表
];

module.exports = {
  ALL_TABLES,
  TABLE_PROJECT_INFO,
  TABLE_UPGRADE_INFO,
  TABLE_DEPLOY_STATUS,
  TABLE_ENV_INFO,
  TABLE_NET_INFO,
  TABLE_MIDDLEWARE_INFO,
  TABLE_BIZ_INFO,
};
