/**
 * 测试用例数据 — 对应 .rn-ohos-adaptation/04-test-cases.json
 *
 * 三级页面结构:模块列表 → 用例列表 → 用例详情。
 * 每个用例在 TestCaseDetail 中按 `caseId` 派发到真实的功能实现(render case)。
 */

export interface TestCase {
  id: string;
  title: string;
  level: string;
  api: string;
  /** 触发按钮文本(与测试套件 test_steps 中【按钮】一致) */
  btnLabel: string;
  /** 按钮 testID(供下一阶段 Hypium 定位,推荐 test-{methodSlug}-btn) */
  testId: string;
  /** 预期结果(展示在用例详情页) */
  expected: string;
  /** 该用例是否需要 GCanvasView 渲染表面 */
  needCanvas: boolean;
  /** 上下文类型:'2d' | 'webgl' | null(needCanvas=true 时生效) */
  contextType: '2d' | 'webgl' | null;
}

export interface TestModule {
  code: string;
  name: string;
  desc: string;
  cases: TestCase[];
}

export const TEST_MODULES: TestModule[] = [
  {
    code: 'F-01',
    name: 'GCanvasView 原生视图渲染',
    desc: '验证 GCanvasView 原生视图在鸿蒙端的渲染表面、生命周期回调与设备像素比适配',
    cases: [
      { id: 'F01-001', title: '能正常渲染画布基础彩色图形', level: 'L0', api: 'GCanvasView', btnLabel: '渲染基础图形', testId: 'test-gcanvas-view-btn', expected: '画布正常渲染彩色基础图形,画面非全黑、非全白', needCanvas: true, contextType: '2d' },
      { id: 'F01-002', title: '画布生成完成时能通知上层', level: 'L0', api: 'onCanvasCreate', btnLabel: '渲染画布', testId: 'test-on-canvas-create-btn', expected: '界面状态更新为“画布已生成”,完成提示出现', needCanvas: true, contextType: '2d' },
      { id: 'F01-003', title: '画布就绪时能通知上层', level: 'L0', api: 'onIsReady', btnLabel: '渲染画布', testId: 'test-on-is-ready-btn', expected: '界面状态更新为“就绪”,就绪指示显示', needCanvas: true, contextType: '2d' },
      { id: 'F01-004', title: '能按设备像素比适配高清屏渲染', level: 'L0', api: 'devicePixelRatio', btnLabel: '高清渲染', testId: 'test-device-pixel-ratio-btn', expected: '在高清屏设备上画布边缘清晰无锯齿,文字与图形锐利', needCanvas: true, contextType: '2d' },
      { id: 'F01-005', title: '画布尺寸变化时能通知上层', level: 'L0', api: 'onCanvasResize', btnLabel: '渲染画布', testId: 'test-on-canvas-resize-btn', expected: '画布尺寸变化时界面状态更新尺寸信息', needCanvas: true, contextType: '2d' },
      { id: 'F01-006', title: '组件卸载后应用不崩溃', level: 'L0', api: 'onCanvasCreate', btnLabel: '离开', testId: 'test-unmount-no-crash-btn', expected: '返回后应用正常运行不崩溃', needCanvas: true, contextType: '2d' },
      { id: 'F01-007', title: '超大尺寸画布能正常渲染', level: 'L0', api: 'GCanvasView', btnLabel: '渲染基础图形', testId: 'test-gcanvas-view-large-btn', expected: '大尺寸画布正常渲染', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-02',
    name: 'Canvas 2D 基础绘图',
    desc: '验证 CanvasRenderingContext2D 基础矩形绘制能力',
    cases: [
      { id: 'F02-001', title: '能启用 2D 绘图能力', level: 'L0', api: 'getContext', btnLabel: '启用 2D 绘图', testId: 'test-get-context-2d-btn', expected: '成功获取 2D 上下文并可绘制', needCanvas: true, contextType: '2d' },
      { id: 'F02-002', title: '能绘制填充矩形', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-fill-rect-btn', expected: '画布显示填充矩形', needCanvas: true, contextType: '2d' },
      { id: 'F02-003', title: '能绘制描边矩形', level: 'L0', api: 'strokeRect', btnLabel: '绘制描边矩形', testId: 'test-stroke-rect-btn', expected: '画布显示描边矩形', needCanvas: true, contextType: '2d' },
      { id: 'F02-004', title: '能清除矩形区域内容', level: 'L0', api: 'clearRect', btnLabel: '清除矩形区域', testId: 'test-clear-rect-btn', expected: '矩形区域被清除', needCanvas: true, contextType: '2d' },
      { id: 'F02-005', title: '能自定义填充颜色', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-fill-style-btn', expected: '矩形显示自定义填充色', needCanvas: true, contextType: '2d' },
      { id: 'F02-006', title: '能调整绘图透明度', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-global-alpha-btn', expected: '矩形显示半透明效果', needCanvas: true, contextType: '2d' },
      { id: 'F02-007', title: '绘制零尺寸矩形时画布不异常', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-zero-rect-btn', expected: '画布正常无异常', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-03',
    name: 'Canvas 2D 路径与变换',
    desc: '验证路径绘制与坐标系变换',
    cases: [
      { id: 'F03-001', title: '能绘制并填充自定义路径', level: 'L0', api: 'fill', btnLabel: '绘制填充路径', testId: 'test-fill-btn', expected: '画布显示填充路径图形', needCanvas: true, contextType: '2d' },
      { id: 'F03-002', title: '能绘制描边路径', level: 'L0', api: 'stroke', btnLabel: '绘制描边路径', testId: 'test-stroke-btn', expected: '画布显示描边路径', needCanvas: true, contextType: '2d' },
      { id: 'F03-003', title: '能对坐标系进行缩放变换', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-scale-btn', expected: '矩形按缩放比例显示', needCanvas: true, contextType: '2d' },
      { id: 'F03-004', title: '能对坐标系进行旋转变换', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-rotate-btn', expected: '矩形按角度旋转显示', needCanvas: true, contextType: '2d' },
      { id: 'F03-005', title: '能对坐标系进行平移变换', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-translate-btn', expected: '矩形按偏移显示', needCanvas: true, contextType: '2d' },
      { id: 'F03-006', title: '绘制异常角度弧线时画布不崩溃', level: 'L0', api: 'arc', btnLabel: '绘制弧线', testId: 'test-arc-btn', expected: '画布正常无异常', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-04',
    name: 'Canvas 2D 文本与字体渲染',
    desc: '验证文本绘制、测量与字体枚举',
    cases: [
      { id: 'F04-001', title: '能绘制填充文本', level: 'L0', api: 'fillText', btnLabel: '绘制文本', testId: 'test-fill-text-btn', expected: '画布显示填充文本', needCanvas: true, contextType: '2d' },
      { id: 'F04-002', title: '能绘制描边文本', level: 'L0', api: 'strokeText', btnLabel: '绘制描边文本', testId: 'test-stroke-text-btn', expected: '画布显示描边文本', needCanvas: true, contextType: '2d' },
      { id: 'F04-003', title: '能测量文本宽度', level: 'L0', api: 'measureText', btnLabel: '测量宽度', testId: 'test-measure-text-btn', expected: '返回文本宽度数值', needCanvas: true, contextType: '2d' },
      { id: 'F04-004', title: '能指定文本对齐方式', level: 'L0', api: 'fillText', btnLabel: '绘制文本', testId: 'test-text-align-btn', expected: '文本按指定对齐方式显示', needCanvas: true, contextType: '2d' },
      { id: 'F04-005', title: '能获取可用字体名称列表', level: 'L0', api: 'getFontNames', btnLabel: '获取字体列表', testId: 'test-get-font-names-btn', expected: '返回系统可用字体名称列表', needCanvas: false, contextType: null },
      { id: 'F04-006', title: '绘制空字符串文本时画布不异常', level: 'L0', api: 'fillText', btnLabel: '绘制文本', testId: 'test-empty-text-btn', expected: '画布正常无异常', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-05',
    name: 'Canvas 2D 渐变与图案',
    desc: '验证渐变与图案填充',
    cases: [
      { id: 'F05-001', title: '能绘制线性渐变', level: 'L0', api: 'createLinearGradient', btnLabel: '绘制线性渐变', testId: 'test-create-linear-gradient-btn', expected: '画布显示线性渐变', needCanvas: true, contextType: '2d' },
      { id: 'F05-002', title: '能绘制径向渐变', level: 'L0', api: 'createRadialGradient', btnLabel: '绘制径向渐变', testId: 'test-create-radial-gradient-btn', expected: '画布显示径向渐变', needCanvas: true, contextType: '2d' },
      { id: 'F05-003', title: '能用图案重复填充区域', level: 'L0', api: 'createPattern', btnLabel: '图案填充', testId: 'test-create-pattern-btn', expected: '画布显示图案重复填充', needCanvas: true, contextType: '2d' },
      { id: 'F05-004', title: '能为图形添加阴影', level: 'L0', api: 'fillRect', btnLabel: '绘制填充矩形', testId: 'test-shadow-btn', expected: '矩形显示阴影效果', needCanvas: true, contextType: '2d' },
      { id: 'F05-005', title: '渐变使用无效颜色时画布不崩溃', level: 'L0', api: 'createLinearGradient', btnLabel: '绘制线性渐变', testId: 'test-invalid-gradient-btn', expected: '画布正常无异常', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-06',
    name: '图片资源与纹理',
    desc: '验证图片预加载、纹理绑定与绘制',
    cases: [
      { id: 'F06-001', title: '能预先准备图片资源', level: 'L0', api: 'preLoadImage', btnLabel: '准备图片', testId: 'test-pre-load-image-btn', expected: '返回图片宽高信息', needCanvas: true, contextType: '2d' },
      { id: 'F06-002', title: '能绑定图片纹理', level: 'L0', api: 'bindImageTexture', btnLabel: '绑定纹理', testId: 'test-bind-image-texture-btn', expected: '图片纹理绑定成功', needCanvas: true, contextType: '2d' },
      { id: 'F06-003', title: '能将图片绘制到画布', level: 'L0', api: 'drawImage', btnLabel: '绘制图片', testId: 'test-draw-image-btn', expected: '画布显示图片', needCanvas: true, contextType: '2d' },
      { id: 'F06-004', title: '能为 WebGL 上传图片纹理', level: 'L0', api: 'texImage2D', btnLabel: '上传纹理', testId: 'test-tex-image-2d-btn', expected: 'WebGL 纹理上传成功', needCanvas: true, contextType: 'webgl' },
      { id: 'F06-005', title: '无效图片地址时能正确处理', level: 'L0', api: 'preLoadImage', btnLabel: '准备图片', testId: 'test-invalid-image-btn', expected: '错误被捕获,画布不崩溃', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-07',
    name: '像素操作与画布导出',
    desc: '验证像素读写与 Base64 导出',
    cases: [
      { id: 'F07-001', title: '能读取画布像素数据', level: 'L0', api: 'getImageData', btnLabel: '读取像素', testId: 'test-get-image-data-btn', expected: '返回像素数据数组', needCanvas: true, contextType: '2d' },
      { id: 'F07-002', title: '能写入像素数据到画布', level: 'L0', api: 'putImageData', btnLabel: '写入像素', testId: 'test-put-image-data-btn', expected: '像素数据写入画布', needCanvas: true, contextType: '2d' },
      { id: 'F07-003', title: '能导出画布为 Base64 图片', level: 'L0', api: 'toDataURL', btnLabel: '导出图片', testId: 'test-to-data-url-btn', expected: '返回 data:image/png;base64,... 字符串', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-08',
    name: 'WebGL 上下文渲染',
    desc: '验证 WebGL 着色器编译与几何体绘制',
    cases: [
      { id: 'F08-001', title: '能启用 WebGL 绘图能力', level: 'L0', api: 'getContext', btnLabel: '启用 WebGL', testId: 'test-get-context-webgl-btn', expected: '成功获取 WebGL 上下文', needCanvas: true, contextType: 'webgl' },
      { id: 'F08-002', title: '能编译链接着色器程序', level: 'L0', api: 'compileShader', btnLabel: '编译着色器', testId: 'test-compile-shader-btn', expected: '着色器编译链接成功', needCanvas: true, contextType: 'webgl' },
      { id: 'F08-003', title: '能绘制三维几何体', level: 'L0', api: 'drawArrays', btnLabel: '绘制几何体', testId: 'test-draw-arrays-btn', expected: '画布显示几何体渲染', needCanvas: true, contextType: 'webgl' },
      { id: 'F08-004', title: '能为几何体贴图渲染', level: 'L0', api: 'texImage2D', btnLabel: '贴图渲染', testId: 'test-tex-image-2d-webgl-btn', expected: '几何体显示贴图', needCanvas: true, contextType: 'webgl' },
      { id: 'F08-005', title: '着色器编译失败时能正确处理', level: 'L0', api: 'compileShader', btnLabel: '编译着色器', testId: 'test-compile-shader-fail-btn', expected: '错误被捕获,画布不崩溃', needCanvas: true, contextType: 'webgl' },
    ],
  },
  {
    code: 'F-09',
    name: '事件与手势交互',
    desc: '验证触摸手势事件分发',
    cases: [
      { id: 'F09-001', title: '触摸手势事件能正确分发', level: 'L0', api: 'onMouseDown', btnLabel: '渲染画布', testId: 'test-on-mouse-down-btn', expected: '触摸画布时触发事件', needCanvas: true, contextType: '2d' },
      { id: 'F09-002', title: '开启手势响应后画布能响应交互', level: 'L0', api: 'onMouseMove', btnLabel: '渲染画布', testId: 'test-on-mouse-move-btn', expected: '移动时触发 mousemove', needCanvas: true, contextType: '2d' },
      { id: 'F09-003', title: '关闭手势响应后画布能忽略交互', level: 'L0', api: 'onMouseMove', btnLabel: '渲染画布', testId: 'test-gesture-disabled-btn', expected: '关闭手势响应后无事件', needCanvas: true, contextType: '2d' },
    ],
  },
  {
    code: 'F-10',
    name: '离屏 Canvas 与生命周期',
    desc: '验证离屏画布与渲染生命周期',
    cases: [
      { id: 'F10-001', title: '能生成离屏画布', level: 'L0', api: 'createCanvas', btnLabel: '生成离屏画布', testId: 'test-create-canvas-btn', expected: '生成离屏画布对象', needCanvas: false, contextType: null },
      { id: 'F10-002', title: '能启用画布渲染', level: 'L0', api: 'enable', btnLabel: '启用渲染', testId: 'test-enable-btn', expected: '画布启用渲染', needCanvas: true, contextType: '2d' },
      { id: 'F10-003', title: '能禁用画布渲染', level: 'L0', api: 'disable', btnLabel: '禁用渲染', testId: 'test-disable-btn', expected: '画布禁用渲染', needCanvas: true, contextType: '2d' },
      { id: 'F10-004', title: '能重置画布组件状态', level: 'L0', api: 'resetComponent', btnLabel: '重置组件', testId: 'test-reset-component-btn', expected: '画布组件状态重置', needCanvas: true, contextType: '2d' },
    ],
  },
];

export const ALL_CASES: TestCase[] = TEST_MODULES.flatMap(m => m.cases);